UDL Syntax coloring for JSON-encoded language

  • Hello everyone
    I am trying to define a UDL for a Language called “TTP” - Table Type Patterns, used by ONF (www.opennetworking.org) to describe OpenFlow Switches.

    The trouble I am having is that the language is JSON encoded. EVRYTHING is a string, and
    the general structure is full of nested objects and lists with the final elements being Name:value pairs separated by commas.

    “name”: [
    {“name” : “value”, “name”:“value”}

    I can ALMOST get it done, but

    1. I manage to define the keywords by using “keyword” in the lists and defined styles
    2. I added both : and , as operators
    3. I defined both { and [ and } ] as start-end code-folding markers

    this gets me about 95% of what I want. I need help with the last 5%

    1. The Language uses sometimes hex numbers in strings, like so '0x1000". I can’t
      figure out how to teach UDL this is a number.

    2. The language has a built in keyword that introduces a comment string. Like this:

      "doc": "Descriptive text here.",

    but also can be multi-line

       "doc": ["Descriptinve text line 1:",
              " - Descriptinve text Line 2",
              " - Descriptinve text line 3" ]

    If I define “doc” as a starting delimiter, I can define EITHER ‘]’ or ‘,’ as closing the delimiter, but not
    both. One works correctly for the multi-line, but fails on the 1-line version that does not have a closing brace as the next character, and the other works on the one-liner, but not on the block. AM I missing something?

    1. (bonus) a couple of keywords actually have two distinct usages. in one context I want them styles as per “1st Group” and in the other context I’d want them styles as per '2nd Group". Is there a way to do this?

    Michael Orr

  • Hello Michael-Orr,

    Here’s a quick one before I have to leave

    The Language uses sometimes hex numbers in strings, like so '0x1000".
    I can’t figure out how to teach UDL this is a number.

    Number style->Prefix 2: 0x
    Number style->Extras 1: A B C D E F a b c d e f  (digits are recognized anyway)

    The language has a built in keyword that introduces a comment string. Like this:

    use the special operator (( )) like

    (( , ] ))


  • Claudia - First let me thank you for jumping in so fast.

    However, at the risk of being dense, I am still in the dark

    1. I did define the hex number format, as per the documentation I found, and it works
      for “naked” hex numbers, but not for ones encased in Quotes. so it works for
      0x12AB and for " 0x12AB " (note spaces between quote make and digits) but not for “0x12AB”
    2. I did not understand how to use the ‘((’ operator and what it does from your note, and I do not
      seem to see it in the documentation - can you give me a pointer? or an example how I might
      use it?

    By way of Illustration, and assuming I have not already imposed on your time too much, I am copy-pasting below a snippet of the TTP language, so you get the flavor of it

    The “doc” elements are the ones I was referring to in my 2nd question. They are a sort of comment, but they are not a comment of THIS source, they are a comment of the TARGET when this code is “compiled”.
    I wanted to color them, but if I set ‘doc’ as delimiter 1 open and ‘,’ (a comma) as delimiter 1 close then the 1st 2 instances are correctly marked, but in the last one marking stops at after the 4t6h word. If I set ‘]’ as the delimiter1 close, then the two liens following the 1st “doc” are incorrectly marked as if they were part of the “doc” element

    “name”: “Control-Frame-Filter”,
    “doc”: “Mandatory filtering of control frames with C-VLAN Bridge reserved DA.”,
    “priority”: 1,
    “match_set”: [{“field”:“ETH_DST”,“mask”:“0xfffffffffff0”,“value”:“0x0180C2000000”}],
    “instruction_set”: []

          "name": "Non-Control-Frame",
          "doc": "Mandatory miss flow_mod, sends packets to IngressVLAN table.",
          "priority": 0,
          "match_set": [],
          "instruction_set": [{"instruction": "GOTO_TABLE", "table": "IngressVLAN"}]
      ]  // BI FM = List of two Elements, each itself a FMT {name,doc, pri match:[],IS:[]}
    },  // ControlFrame FlowTable
      "name": "IngressVLAN",
      "doc": ["Ingress VID processing table, including:",
              " - accepting or blocking untagged and priority tagged frames",
              " - accepting or blocking VLAN tagged frames",
              " - ingress VID filtering control",
              " - (optional) ingress VID translation" ],

  • Hello Michael,

    yes, the delimiter section is hidden on the udl webpage,
    don’t know why and just right now I saw that there is another hidden page to.
    You can find it when you hover over the home link and then move slowly down, suddenly delimiter link appears.
    If you move then to the right a numbers new link appears. Seems webmaster had some fun ;-)

    From the doc
    If two or more strings are defined inside of a special operator (( )), they are interchangeable.
    So you can have multiple closing delimiters but you need to encase (?) it by (( and )).

    Regarding the number encased by double quotes, I guess you are right, need to think about it.

    One question, I’m not a native speaker and always eager to improve my english.
    When you say encased by quotes is it the same as saying surrounded by quotes or
    does it have slightly different meanings?

    Thank you and cheers

  • Hello Michael,

    I guess both open requests cannot be solved.
    The closing delimiter for the comment, the comma is used in the text as well
    and double quotes making a string out of the hex value.

    Still looking into it but I don’t think it can be achieved.


  • Hello Michael,

    ok - the encased hexnumber is solved, I guess.
    Just define a delimiter double quote (of course, the char not the word) and allow nesting with numbers.

    Let see if we find a solution to comment issue as well.


  • @Claudia-Frank Yes, “encased” is the same as Surrounded in this context. “encased” is like saying “in a case” so “encased in Quote marks” is like saying “in a case made from quote marks” == Surrounded by quote marks.

  • Hello Michael,

    thank you for the explanation. Fyi I’m still working on the comment line - the closest I have is that
    the line next to doc line is coloured as well.


  • @Michael Orr
    Hello Michael,

    unfortunattely I din’t get it managed.
    I strongly believe that the current version of UDL cannot answer this question.


Log in to reply