Skip to content

Commit 898d467

Browse files
authored
lexers/cue: support definitions and dollars in field names (#935)
'$' 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.
1 parent 0f92de4 commit 898d467

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

lexers/embedded/cue.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
<rule pattern="(true|false|null|_)\b">
5050
<token type="KeywordConstant"/>
5151
</rule>
52-
<rule pattern="[_a-zA-Z]\w*">
52+
<rule pattern="#?[_a-zA-Z$]\w*">
5353
<token type="Name"/>
5454
</rule>
5555
</state>

lexers/testdata/cue.actual

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,8 @@ A: close({
2929
field2: string
3030
})
3131

32+
// Verify that various field types work
33+
_hidden: int
34+
regular: int
35+
$id: int
36+
#definition: int

lexers/testdata/cue.expected

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,27 @@
104104
{"type":"KeywordType","value":"string"},
105105
{"type":"Text","value":"\n"},
106106
{"type":"Punctuation","value":"})"},
107-
{"type":"Text","value":"\n\n"}
107+
{"type":"Text","value":"\n\n"},
108+
{"type":"CommentSingle","value":"// Verify that various field types work"},
109+
{"type":"Text","value":"\n"},
110+
{"type":"Name","value":"_hidden"},
111+
{"type":"Operator","value":":"},
112+
{"type":"Text","value":" "},
113+
{"type":"KeywordType","value":"int"},
114+
{"type":"Text","value":"\n"},
115+
{"type":"Name","value":"regular"},
116+
{"type":"Operator","value":":"},
117+
{"type":"Text","value":" "},
118+
{"type":"KeywordType","value":"int"},
119+
{"type":"Text","value":"\n"},
120+
{"type":"Name","value":"$id"},
121+
{"type":"Operator","value":":"},
122+
{"type":"Text","value":" "},
123+
{"type":"KeywordType","value":"int"},
124+
{"type":"Text","value":"\n"},
125+
{"type":"Name","value":"#definition"},
126+
{"type":"Operator","value":":"},
127+
{"type":"Text","value":" "},
128+
{"type":"KeywordType","value":"int"},
129+
{"type":"Text","value":"\n"}
108130
]

0 commit comments

Comments
 (0)