Open Modelica user language

  • Hello,
    I am quite new here, I am trying to create a UDL for OpenModelica language. I can do the basics with the user language creation tool, but I want to add something to finish the UDL. I need to highlight every function name like : acos(x) or myfunction(test). acos and myfunction should be highlighted.
    I also found that the erlang language do that well. So I looked at the UDL usermanual and I tried to change the udl.xml file outside the UDL editor. In the stylers.xml, in the erlang section this line seems to do the trick :

    <WordsStyle name="FUNCTION NAME" styleID="8" fgColor="00007f" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />

    Unfortunately, I did not manage to make this line work in my UDL.

    I also tried to add a new language directly inside the langs.xml and the stylers.xml, but my new language only appear in the Settings > Style Configurator and not in the Language menu.

    Did I miss something ? It’s quite frustrating, everything is working but the function name…

  • @DarthMoule ,

    User Defined Languages (UDL) do not use the Style Configurator, stylers.xml, or langs.xml; only builtin languages use those. Erlang is a language that uses a builtin lexer, not the UDL, which is why its configuration is stored in langs and stylers. You cannot use it as an example for your UDL.

    For syntax highlighting of UDL, you can affect every highlighting setting and option available through the Language > User Defined Language > Define Your Language menu entry (or Language > Define Your Language on older Notepad++ versions), or in the userDefineLang.xml (old-style, but still works) or in the separate xml files in the userDefineLangs subdirectory. Since you are a beginner at UDL, it’s going to be easiest for you to just use the GUI, rather than trying to find and edit config files manually.

    For your UDL, assuming you’ve already named the UDL (which I assume, because you claim you already used the language creation tool). Now, to define lists of keywords (like function names), you would:

    1. run the … Define Your Language menu entry to bring up the User Defined Language dialog box (or docked pane)
    2. select your UDL from the dropdown
    3. click on the Keywords List
    4. Go into one of the numbered groups (your choice), and you type the keywords as a space-separated list
    5. Since you want it to highlight, even when you have parentheses (acos(x)), you need Prefix Mode enabled
    6. Click on the Styler button for the specific group of keywords
    7. Pick the color and other formatting rules
    8. Right now, your file doesn’t apply the UDL highlighting. Go to Language > OpenModelica to apply the UDL highlighting to the active document
    9. If you set an extension list in the Ext box – a space-separated list of the extensions, without the dots – then Notepad++ will automatically apply this UDL to files with those extensions when you open them.
      • For example, if you have two files, first.omod and (*) which you want to automatically get OpenModelica highlighting the next time you open them, you would set Ext to omod om. (*: I don’t know the OpenModelica file extension(s), so made an example guess)



  • I said,

    have parentheses (acos(x)), you need Prefix Mode enabled

    Sorry; something felt odd about that, so I did more experimenting. If you followed that advice, and had a third function defined multiarg, which would be used like multiarg(a, b, c) in your code, only the multiarg(a, would be highlighted, which would be just weird. The right way to handle parentheses: turn off the Prefix Mode (don’t need it anymore); go to the Operators & Delimiters; here, you have two choices:

    • if you want the parens highlighted, but the stuff between not highlighted, then put ( and ) inside the Operators 1 box (space-separated list). It would then render like the following (where I chose green as the style):
      See that the function names are red, the parens are green, and the args are default (black)
    • if you want the parens and the stuff between highlighted instead, then choose an unused Delimiter # style (I chose #1 and set it to Blue), with Open = ( and Close = ). This will show up as:
      See that the function name is still red, the parens and arguments and commas are blue.

    The Prefix Mode setting would allow you to write something like open in the list, and every function that started with open, like openFile, openDoor, and openSesame would all be highlighted with that one entry of open.

Log in to reply