Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lexers/cue: support CUE attributes #961

Merged
merged 1 commit into from Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
20 changes: 20 additions & 0 deletions lexers/testdata/cue.actual
Expand Up @@ -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 changes: 96 additions & 0 deletions lexers/testdata/cue.expected
Expand Up @@ -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"}
]