Skip to content

Commit

Permalink
lexers/cue: support definitions and dollars in field names (#935)
Browse files Browse the repository at this point in the history
'$' is valid in a bare field name in CUE. It is not special. It happens
to be used by convention at the start of field names, but that is about
it.

Definitions start with '#'.

Add a "section" of tests that cover the various types of field. There
are no errors in new "tests", whereas before (i.e. without the change to
the CUE lexer) there would have been.
  • Loading branch information
myitcv committed Feb 26, 2024
1 parent 0f92de4 commit 898d467
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lexers/embedded/cue.xml
Expand Up @@ -49,7 +49,7 @@
<rule pattern="(true|false|null|_)\b">
<token type="KeywordConstant"/>
</rule>
<rule pattern="[_a-zA-Z]\w*">
<rule pattern="#?[_a-zA-Z$]\w*">
<token type="Name"/>
</rule>
</state>
Expand Down
5 changes: 5 additions & 0 deletions lexers/testdata/cue.actual
Expand Up @@ -29,3 +29,8 @@ A: close({
field2: string
})

// Verify that various field types work
_hidden: int
regular: int
$id: int
#definition: int
24 changes: 23 additions & 1 deletion lexers/testdata/cue.expected
Expand Up @@ -104,5 +104,27 @@
{"type":"KeywordType","value":"string"},
{"type":"Text","value":"\n"},
{"type":"Punctuation","value":"})"},
{"type":"Text","value":"\n\n"}
{"type":"Text","value":"\n\n"},
{"type":"CommentSingle","value":"// Verify that various field types work"},
{"type":"Text","value":"\n"},
{"type":"Name","value":"_hidden"},
{"type":"Operator","value":":"},
{"type":"Text","value":" "},
{"type":"KeywordType","value":"int"},
{"type":"Text","value":"\n"},
{"type":"Name","value":"regular"},
{"type":"Operator","value":":"},
{"type":"Text","value":" "},
{"type":"KeywordType","value":"int"},
{"type":"Text","value":"\n"},
{"type":"Name","value":"$id"},
{"type":"Operator","value":":"},
{"type":"Text","value":" "},
{"type":"KeywordType","value":"int"},
{"type":"Text","value":"\n"},
{"type":"Name","value":"#definition"},
{"type":"Operator","value":":"},
{"type":"Text","value":" "},
{"type":"KeywordType","value":"int"},
{"type":"Text","value":"\n"}
]

0 comments on commit 898d467

Please sign in to comment.