Add syntax highlighting for YANG data modeling language
ClosedPublic

Authored by nalvarez on May 9 2017, 4:17 PM.

Details

Summary

Add syntax highlighting for YANG data modeling language, based on yang.vim.

Improvements from yang.vim:

  • Character escapes such as \n in "foo\nbar" are highlighted in a different color
  • 'foo\'bar' is highlighted correctly (string ends at first ' regardless of backslash). yang.vim wrongly interprets \\ and \' as escapes in single-quoted strings.

Regressions from yang.vim (which I may fix later):

  • Numbers don't have special highlighting and look like normal text.
  • "Dates" and "lengths" don't have special highlighting and look like normal strings.

I also don't highlight identifiers starting with xml as an error (which yang.vim does), but it seems like that's a YANG 1.0 restriction that was removed in YANG 1.1.

Also the XML code ended up unreadable with little whitespace. Hit me with that in code review.

Test Plan

Manually tested with random samples copied from the RFC, comparing the result between Vim and KWrite. However those can't be used as test cases for licensing reasons. Perhaps @jkt can provide a usable test file?

Diff Detail

Repository
R216 Syntax Highlighting
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
nalvarez created this revision.May 9 2017, 4:17 PM
Restricted Application added a project: Frameworks. · View Herald TranscriptMay 9 2017, 4:17 PM
Restricted Application added a subscriber: Frameworks. · View Herald Transcript
dhaumann accepted this revision.May 9 2017, 7:34 PM
dhaumann added a subscriber: dhaumann.

The patch looks good to me. Can you please also add a unit test for this? We try to have as many highlighting unit tests as possible... The unit test highlighting file should preferably be LGPL or even MIT license.

This revision is now accepted and ready to land.May 9 2017, 7:34 PM

@nalvarez Ping? Essentially, you're good to go. It would help, if you could add a unit test for this (autotest/input/) along with the reference data (use the script autotest/update-reference-data.sh in your build folder to update this into the src folder).

Sorry, I don't know enough about the language to provide a meaningful test. I made these highlighting rules on request by @jkt, partly translating the .vim file and partly reading the RFC, without even understanding what the language is for. I was hoping he could provide a test file, but he didn't reply to my highlight here or to my email...

Should I commit anyway, without the test?

jkt accepted this revision.Jun 17 2017, 11:28 PM

Oops, sorry, I forgot to comment here. I appreciate your conversion, it works really nicely!

Compared to the vim version, my QtCreator theme is not highlighting the true and false keywords in statements such as mandatory true;. That's because the dsVariable appears to be mapped to "Local" in QtC, and that thing is not being decorated in any manner in my theme. Perhaps mapping it to "something else" ,ight be a good idea? I have to admit that I have no clue about a best fit here; it's probably not a keyword.

Thanks again for implementing this!

jkt added a comment.Jun 17 2017, 11:34 PM

Re "extracting bits from the RFC", RFC 6020 says (among other things) that "Code Components extracted from this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Simplified BSD License." That sounds like a reasonable license, doesn't it?

I knew the text of RFCs was under a somewhat-restrictive license. I didn't know code snippets were explicitly excluded and BSD'd instead. We can work with that then :)

aacid added a subscriber: aacid.Jun 18 2017, 9:32 PM
This comment was removed by aacid.
This revision was automatically updated to reflect the committed changes.