mirror of
https://github.com/alecthomas/chroma.git
synced 2025-02-03 13:01:47 +02:00
lexers/cue: support CUE attributes (#961)
Currently the following CUE results in the chroma lexer producing an error token for the '@': value: string @go(Value) This code is, however, valid CUE. '@go' is an attributes. This change adds lexer support for attributes in CUE.
This commit is contained in:
parent
9347b550ab
commit
1e983e734d
@ -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>
|
||||
|
20
lexers/testdata/cue.actual
vendored
20
lexers/testdata/cue.actual
vendored
@ -34,3 +34,23 @@ _hidden: int
|
||||
regular: int
|
||||
$id: int
|
||||
#definition: int
|
||||
|
||||
@protobuf(proto3)
|
||||
|
||||
myStruct1: {
|
||||
// Struct attribute:
|
||||
@jsonschema(id="https://example.org/mystruct1.json")
|
||||
|
||||
// Field attributes
|
||||
field: string @go(Field)
|
||||
attr: int @xml(,attr) @go(Attr)
|
||||
}
|
||||
|
||||
myStruct2: {
|
||||
field: string @go(Field)
|
||||
attr: int @xml(a1,attr) @go(Attr)
|
||||
}
|
||||
|
||||
Combined: myStruct1 & myStruct2
|
||||
// field: string @go(Field)
|
||||
// attr: int @xml(,attr) @xml(a1,attr) @go(Attr)
|
||||
|
96
lexers/testdata/cue.expected
vendored
96
lexers/testdata/cue.expected
vendored
@ -126,5 +126,101 @@
|
||||
{"type":"Operator","value":":"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"KeywordType","value":"int"},
|
||||
{"type":"Text","value":"\n\n"},
|
||||
{"type":"Name","value":"@protobuf"},
|
||||
{"type":"Punctuation","value":"("},
|
||||
{"type":"Name","value":"proto3"},
|
||||
{"type":"Punctuation","value":")"},
|
||||
{"type":"Text","value":"\n\n"},
|
||||
{"type":"Name","value":"myStruct1"},
|
||||
{"type":"Operator","value":":"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Punctuation","value":"{"},
|
||||
{"type":"Text","value":"\n "},
|
||||
{"type":"CommentSingle","value":"// Struct attribute:"},
|
||||
{"type":"Text","value":"\n "},
|
||||
{"type":"Name","value":"@jsonschema"},
|
||||
{"type":"Punctuation","value":"("},
|
||||
{"type":"Name","value":"id"},
|
||||
{"type":"Operator","value":"="},
|
||||
{"type":"LiteralString","value":"\"https://example.org/mystruct1.json\""},
|
||||
{"type":"Punctuation","value":")"},
|
||||
{"type":"Text","value":"\n\n "},
|
||||
{"type":"CommentSingle","value":"// Field attributes"},
|
||||
{"type":"Text","value":"\n "},
|
||||
{"type":"Name","value":"field"},
|
||||
{"type":"Operator","value":":"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"KeywordType","value":"string"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Name","value":"@go"},
|
||||
{"type":"Punctuation","value":"("},
|
||||
{"type":"Name","value":"Field"},
|
||||
{"type":"Punctuation","value":")"},
|
||||
{"type":"Text","value":"\n "},
|
||||
{"type":"Name","value":"attr"},
|
||||
{"type":"Operator","value":":"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"KeywordType","value":"int"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Name","value":"@xml"},
|
||||
{"type":"Punctuation","value":"("},
|
||||
{"type":"Operator","value":","},
|
||||
{"type":"Name","value":"attr"},
|
||||
{"type":"Punctuation","value":")"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Name","value":"@go"},
|
||||
{"type":"Punctuation","value":"("},
|
||||
{"type":"Name","value":"Attr"},
|
||||
{"type":"Punctuation","value":")"},
|
||||
{"type":"Text","value":"\n"},
|
||||
{"type":"Punctuation","value":"}"},
|
||||
{"type":"Text","value":"\n\n"},
|
||||
{"type":"Name","value":"myStruct2"},
|
||||
{"type":"Operator","value":":"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Punctuation","value":"{"},
|
||||
{"type":"Text","value":"\n "},
|
||||
{"type":"Name","value":"field"},
|
||||
{"type":"Operator","value":":"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"KeywordType","value":"string"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Name","value":"@go"},
|
||||
{"type":"Punctuation","value":"("},
|
||||
{"type":"Name","value":"Field"},
|
||||
{"type":"Punctuation","value":")"},
|
||||
{"type":"Text","value":"\n "},
|
||||
{"type":"Name","value":"attr"},
|
||||
{"type":"Operator","value":":"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"KeywordType","value":"int"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Name","value":"@xml"},
|
||||
{"type":"Punctuation","value":"("},
|
||||
{"type":"Name","value":"a1"},
|
||||
{"type":"Operator","value":","},
|
||||
{"type":"Name","value":"attr"},
|
||||
{"type":"Punctuation","value":")"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Name","value":"@go"},
|
||||
{"type":"Punctuation","value":"("},
|
||||
{"type":"Name","value":"Attr"},
|
||||
{"type":"Punctuation","value":")"},
|
||||
{"type":"Text","value":"\n"},
|
||||
{"type":"Punctuation","value":"}"},
|
||||
{"type":"Text","value":"\n\n"},
|
||||
{"type":"Name","value":"Combined"},
|
||||
{"type":"Operator","value":":"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Name","value":"myStruct1"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Operator","value":"\u0026"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Name","value":"myStruct2"},
|
||||
{"type":"Text","value":"\n"},
|
||||
{"type":"CommentSingle","value":"// field: string @go(Field)"},
|
||||
{"type":"Text","value":"\n"},
|
||||
{"type":"CommentSingle","value":"// attr: int @xml(,attr) @xml(a1,attr) @go(Attr)"},
|
||||
{"type":"Text","value":"\n"}
|
||||
]
|
||||
|
Loading…
x
Reference in New Issue
Block a user