Exporting an Existing Language Defintion?
-
Hi all,
Is it possible to export an existing language definition so that a new UDL can be based on it? What I’m hoping to do is export the Python language definition so I can modify it to create one for GDScript.Of course, if someone knows of a GDScript UDL that already exists, that would do just fine, too. I didn’t see one in the github repository.
-
I think the problem is going to be that non-UDL languages and UDL languages are vastly different things.
-
@Alan-Kilborn Bummer. Thanks, Alan.
-
I don’t know how similar GDScript is to Python (all I know about GDScript is what I saw from the headlines on this search), but if syntax is basically the same, and it’s mostly just some extra keywords that you’d like to highlight, the Style Configurator has “user-defined keywords” boxes for KEYWORDS and BUILTINS styles, plus the ability to add custom extensions.
For example, if GDScript is basically python, but with the
gd
extension instead ofpy
, and a builtin objectMySuperNode
(and maybe some other KEYWORDS not shown), it might look something like:
You can do more than one word in each blank, so you can add BUILTINS and KEYWORDS to your heart’s content. This was just a quickie example.
-
I am trying to do this same thing except I want to get the auto-complete to work as well. As far as I can tell I would have to edit the perl.xml auto-complete to get this to work.
It would be nice if we could treat all the languages the same to be able to import/export/duplicate them for scripting languages that are built on top of others. -
@Monsterray said in Exporting an Existing Language Defintion?:
I am trying to do this same thing except I want to get the auto-complete to work as well. As far as I can tell I would have to edit the perl.xml auto-complete to get this to work.
To get auto-complete to work, yes, taking an existing one and just tweaking it and giving it the right name is “all” that’s needed.
It would be nice if we could treat all the languages the same to be able to import/export/duplicate them for scripting languages that are built on top of others.
Every built-in langauge has its own separate source code, because most of the built-in go way beyond simple keyword matching. The User Defined Languages (UDL), OTOH, just use simple keyword matching. Without a complete redesign and rewrite – essentially, abandoning the library that Notepad++ currently uses for syntax highlighting (which is guaranteed to never happen, so don’t get your hopes up) – it is not possible to “export” a built-in library to replicate to some other language.
But my answer to you is essentially the same as my answer from almost 5 years ago – if you have a “language” that is similar enough to Perl that you’d want to start from perl as a basis, you could try to just add your own keywords to the already-existing “user-defined keywords” boxes available in the Perl entry in Style Configurator – this allows you to add your own keywords, while keeping all the fancy stuff (like code-folding and brace processing, etc) the same as Perl.
-
@Monsterray ,
In addition to what @PeterJones is saying, while you have a functional ability that he suggests, you could create your own UDL mirroring the stuff that is already accessible to you from the main language you want to copy from, like Keywords, background colors, foreground colors, font Name, font size, font style, and helpfully, the Names that the word style is applied to from the stylers.xml file, so you can duplicate it inside of the UDL with applicable mapping to the UDL components of Operators 1 & 2 and Delimiters, Comment and Number, Folding & Default and Keyword Lists. You can also then work on the Function List aspect and the AutoComplete that would be tailored to your use case and preferences. We don’t have control over the parsing and application and customization that writing the lexer does, but if you work hard enough and learn the intricacies of working with the UDL and customizable features available, you can make a pretty good alternative to the original’s capability…but it will take learning and work. :-)The people here can help you do it, if you want to, or you can do what @PeterJones suggests to do it the easy way. :-)
Below here are the mappings from the Python section of the stylers.xml file you’ll need to map to the UDL categories and properties.
<LexerType desc="Python" ext="" name="python"> <WordsStyle bgColor="FFFFFF" fgColor="000000" fontName="" fontSize="" fontStyle="0" name="DEFAULT" styleID="0" /> <WordsStyle bgColor="FFFFFF" fgColor="008000" fontName="" fontSize="" fontStyle="0" name="COMMENT LINE" styleID="1" /> <WordsStyle bgColor="FFFFFF" fgColor="FF0000" fontName="" fontSize="" fontStyle="0" name="NUMBER" styleID="2" /> <WordsStyle bgColor="FFFFFF" fgColor="808080" fontName="" fontSize="" fontStyle="0" name="STRING" styleID="3" /> <WordsStyle bgColor="FFFFFF" fgColor="808080" fontName="" fontSize="" fontStyle="0" name="CHARACTER" styleID="4" /> <WordsStyle bgColor="FFFFFF" fgColor="0000FF" fontName="" fontSize="" fontStyle="1" keywordClass="instre1" name="KEYWORDS" styleID="5" /> <WordsStyle bgColor="FFFFFF" fgColor="FF8000" fontName="" fontSize="" fontStyle="0" name="TRIPLE" styleID="6" /> <WordsStyle bgColor="FFFFFF" fgColor="FF8000" fontName="" fontSize="" fontStyle="0" name="TRIPLE DOUBLE" styleID="7" /> <WordsStyle bgColor="FFFFFF" fgColor="000000" fontName="" fontSize="" fontStyle="1" name="CLASS NAME" styleID="8" /> <WordsStyle bgColor="FFFFFF" fgColor="FF00FF" fontName="" fontSize="" fontStyle="0" name="DEF NAME" styleID="9" /> <WordsStyle bgColor="FFFFFF" fgColor="000080" fontName="" fontSize="" fontStyle="1" name="OPERATOR" styleID="10" /> <WordsStyle bgColor="FFFFFF" fgColor="000000" fontName="" fontSize="" fontStyle="0" name="IDENTIFIER" styleID="11" /> <WordsStyle bgColor="FFFFFF" fgColor="008000" fontName="" fontSize="" fontStyle="0" name="COMMENT BLOCK" styleID="12" /> <WordsStyle bgColor="FFFFFF" fgColor="880088" fontName="" fontSize="" fontStyle="1" keywordClass="instre2" name="BUILTINS" styleID="14" /> <WordsStyle bgColor="FFFFFF" fgColor="FF8000" fontName="" fontSize="" fontStyle="2" name="DECORATOR" styleID="15" /> <WordsStyle bgColor="FFFFFF" fgColor="808080" fontName="" fontSize="" fontStyle="0" name="F STRING" styleID="16" /> <WordsStyle bgColor="FFFFFF" fgColor="808080" fontName="" fontSize="" fontStyle="0" name="F CHARACTER" styleID="17" /> <WordsStyle bgColor="FFFFFF" fgColor="FF8000" fontName="" fontSize="" fontStyle="0" name="F TRIPLE" styleID="18" /> <WordsStyle bgColor="FFFFFF" fgColor="FF8000" fontName="" fontSize="" fontStyle="0" name="F TRIPLEDOUBLE" styleID="19" /> <WordsStyle bgColor="FFFFFF" fgColor="000000" fontName="" fontSize="" fontStyle="0" name="ATTRIBUTE" styleID="20" /> <WordsStyle bgColor="FFFF80" fgColor="000000" fontName="" fontSize="" fontStyle="0" keywordClass="substyle1" name="USER KEYWORDS 1" styleID="128" /> <WordsStyle bgColor="FFFF80" fgColor="000000" fontName="" fontSize="" fontStyle="0" keywordClass="substyle2" name="USER KEYWORDS 2" styleID="129" /> <WordsStyle bgColor="FFFF80" fgColor="000000" fontName="" fontSize="" fontStyle="0" keywordClass="substyle3" name="USER KEYWORDS 3" styleID="130" /> <WordsStyle bgColor="FFFF80" fgColor="000000" fontName="" fontSize="" fontStyle="0" keywordClass="substyle4" name="USER KEYWORDS 4" styleID="131" /> <WordsStyle bgColor="FFFF80" fgColor="000000" fontName="" fontSize="" fontStyle="0" keywordClass="substyle5" name="USER KEYWORDS 5" styleID="132" /> <WordsStyle bgColor="FFFF80" fgColor="000000" fontName="" fontSize="" fontStyle="0" keywordClass="substyle6" name="USER KEYWORDS 6" styleID="133" /> <WordsStyle bgColor="FFFF80" fgColor="000000" fontName="" fontSize="" fontStyle="0" keywordClass="substyle7" name="USER KEYWORDS 7" styleID="134" /> <WordsStyle bgColor="FFFF80" fgColor="000000" fontName="" fontSize="" fontStyle="0" keywordClass="substyle8" name="USER KEYWORDS 8" styleID="135" /> </LexerType>