From 86c259df7bfde0f25f48498e4e8c9048e8fc43cf Mon Sep 17 00:00:00 2001 From: Paul Jolly Date: Wed, 17 Apr 2024 16:39:25 +0100 Subject: [PATCH] lexers/cue: support CUE attributes 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. --- lexers/embedded/cue.xml | 2 +- lexers/testdata/cue.actual | 20 ++++++++ lexers/testdata/cue.expected | 96 ++++++++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+), 1 deletion(-) diff --git a/lexers/embedded/cue.xml b/lexers/embedded/cue.xml index d6c3ea71b..2a12f3953 100644 --- a/lexers/embedded/cue.xml +++ b/lexers/embedded/cue.xml @@ -49,7 +49,7 @@ - + diff --git a/lexers/testdata/cue.actual b/lexers/testdata/cue.actual index 830682b2b..1ac848839 100644 --- a/lexers/testdata/cue.actual +++ b/lexers/testdata/cue.actual @@ -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) diff --git a/lexers/testdata/cue.expected b/lexers/testdata/cue.expected index c7c0dce4c..4dd52dd25 100644 --- a/lexers/testdata/cue.expected +++ b/lexers/testdata/cue.expected @@ -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"} ]