From e8b60d0339e03a615b85e2db08294c9d6fe5657f Mon Sep 17 00:00:00 2001 From: Aaron Bentley Date: Sat, 17 Sep 2022 20:58:04 -0400 Subject: [PATCH 1/9] Add Jsonnet support --- pygments/lexers/_mapping.py | 1 + pygments/lexers/jsonnet.py | 160 ++++ tests/examplefiles/jsonnet/example.jsonnet | 74 ++ .../jsonnet/example.jsonnet.output | 697 ++++++++++++++++++ 4 files changed, 932 insertions(+) create mode 100644 pygments/lexers/jsonnet.py create mode 100644 tests/examplefiles/jsonnet/example.jsonnet create mode 100644 tests/examplefiles/jsonnet/example.jsonnet.output diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py index 3c5f043a53..7ea8566eb4 100644 --- a/pygments/lexers/_mapping.py +++ b/pygments/lexers/_mapping.py @@ -237,6 +237,7 @@ 'JsonBareObjectLexer': ('pygments.lexers.data', 'JSONBareObject', (), (), ()), 'JsonLdLexer': ('pygments.lexers.data', 'JSON-LD', ('jsonld', 'json-ld'), ('*.jsonld',), ('application/ld+json',)), 'JsonLexer': ('pygments.lexers.data', 'JSON', ('json', 'json-object'), ('*.json', 'Pipfile.lock'), ('application/json', 'application/json-object')), + 'JsonnetLexer': ('pygments.lexers.jsonnet', 'Jsonnet', ('jsonnet',), ('*.jsonnet', '*.libsonnet'), ()), 'JspLexer': ('pygments.lexers.templates', 'Java Server Page', ('jsp',), ('*.jsp',), ('application/x-jsp',)), 'JuliaConsoleLexer': ('pygments.lexers.julia', 'Julia console', ('jlcon', 'julia-repl'), (), ()), 'JuliaLexer': ('pygments.lexers.julia', 'Julia', ('julia', 'jl'), ('*.jl',), ('text/x-julia', 'application/x-julia')), diff --git a/pygments/lexers/jsonnet.py b/pygments/lexers/jsonnet.py new file mode 100644 index 0000000000..6b25d157f3 --- /dev/null +++ b/pygments/lexers/jsonnet.py @@ -0,0 +1,160 @@ +from pygments.lexer import RegexLexer +from pygments.token import ( + Comment, + Keyword, + Name, + Number, + Operator, + Punctuation, + String, + Whitespace, +) + +__all__ = ['JsonnetLexer'] + +jsonnet_token_chars = r'[_A-Za-z0-9]' +jsonnet_token = r'[_A-Za-z]' + jsonnet_token_chars + '*' +jsonnet_function_token = jsonnet_token + r'(?=\()' + + +comments = [ + (r'//.*\n', Comment.Single), + (r'#.*\n', Comment.Single), + (r'/\*\*([^/]|/(?!\*))*\*/', String.Doc), + (r'/\*([^/]|/(?!\*))*\*/', Comment), +] + + +whitespace = (r'[\n ]+', Whitespace) + + +keywords = '|'.join([ + 'assert', 'else', 'error', 'false', 'for', 'if', 'import', 'importstr', + 'in', 'null', 'tailstrict', 'then', 'self', 'super', 'true', +]) + + +rvalues = comments + [ + (r"@'.*'", String), + (r'@".*"', String), + (r"'", String, 'singlestring'), + (r'"', String, 'doublestring'), + (r'(?s:\|\|\|.*\|\|\|)', String), + (r'[+-]?[0-9]+(.[0-9])?', Number.Float), + # Omit : despite spec because it appears to be used as a field separator + (r'[!$~+\-&|^=<>*/%]', Operator), + (r'[{]', Punctuation, 'object'), + (r'\[', Punctuation, 'array'), + (r'local', Keyword, ('local_name')), + (r'assert', Keyword, 'assert'), + (fr'({keywords})(?!{jsonnet_token_chars})', Keyword), + whitespace, + (r'function(?=\()', Keyword, 'function_params'), + (r'std\.' + jsonnet_function_token, Name.Builtin, 'function_args'), + (jsonnet_function_token, Name.Function, 'function_args'), + (jsonnet_token, Name.Variable), + (r'[\.()]', Punctuation), +] + + +def string_rules(quote_mark): + return [ + (r"[^{}\\]".format(quote_mark), String), + (r"\\.", String.Escape), + (quote_mark, String, '#pop'), + ] + + +def quoted_field_name(quote_mark): + return [ + (r'([^{quote}\\]|\\.)*{quote}'.format(quote=quote_mark), + Name.Variable, 'field_separator') + ] + + +class JsonnetLexer(RegexLexer): + name = 'Jsonnet' + aliases = ['jsonnet'] + filenames = ['*.jsonnet', '*.libsonnet'] + tokens = { + 'root': rvalues, + 'singlestring': string_rules("'"), + 'doublestring': string_rules('"'), + 'array': [ + (r',', Punctuation), + (r'\]', Punctuation, '#pop'), + ] + rvalues, + 'local_name': [ + (jsonnet_function_token, Name.Function, 'function_params'), + (jsonnet_token, Name.Variable), + whitespace, + ('(?==)', Whitespace, ('#pop', 'local_value')), + ], + 'local_value': [ + (r'=', Operator), + (r';', Punctuation, '#pop'), + ] + rvalues, + 'assert': [ + (r':', Punctuation), + (r';', Punctuation, '#pop'), + ] + rvalues, + 'function_params': [ + (jsonnet_token, Name.Variable), + (r'\(', Punctuation), + (r'\)', Punctuation, '#pop'), + (r',', Punctuation), + whitespace, + (r'=', Operator, 'function_param_default'), + ], + 'function_args': [ + (r'\(', Punctuation), + (r'\)', Punctuation, '#pop'), + (r',', Punctuation), + whitespace, + ] + rvalues, + 'object': [ + whitespace, + (r'local', Keyword, 'object_local_name'), + ('assert', Keyword, 'object_assert'), + (r'\[', Operator, 'field_name_expr'), + (fr'(?={jsonnet_token})', Name.Variable, 'field_name'), + (r'}', Punctuation, '#pop'), + (r'"', Name.Variable, 'double_field_name'), + (r"'", Name.Variable, 'single_field_name'), + ] + comments, + 'field_name': [ + (jsonnet_function_token, Name.Function, + ('field_separator', 'function_params') + ), + (jsonnet_token, Name.Variable, 'field_separator'), + ], + 'double_field_name': quoted_field_name('"'), + 'single_field_name': quoted_field_name("'"), + 'field_name_expr': [ + (r'\]', Operator, 'field_separator'), + ] + rvalues, + 'function_param_default': [ + (r'(?=[,\)])', Whitespace, '#pop') + ] + rvalues, + 'field_separator': [ + whitespace, + (r'\+?::?:?', Punctuation, ('#pop', '#pop', 'field_value')), + ] + comments, + 'field_value': [ + (r',', Punctuation, '#pop'), + (r'}', Punctuation, '#pop:2'), + ] + rvalues, + 'object_assert': [ + (r':', Punctuation), + (r',', Punctuation, '#pop'), + ] + rvalues, + 'object_local_name': [ + (jsonnet_token, Name.Variable, ('#pop', 'object_local_value')), + whitespace, + ], + 'object_local_value': [ + (r'=', Operator), + (r',', Punctuation, '#pop'), + (r'}', Punctuation, '#pop:2'), + ] + rvalues, + } diff --git a/tests/examplefiles/jsonnet/example.jsonnet b/tests/examplefiles/jsonnet/example.jsonnet new file mode 100644 index 0000000000..74e2e45993 --- /dev/null +++ b/tests/examplefiles/jsonnet/example.jsonnet @@ -0,0 +1,74 @@ +/* Multiline / +comment */ +local x = 100; +/* Multiline +comment */ + +/** + * Docs + **/ + + +local i = import 'foo'; +local foo = 'bar'; +local lambda = function(foo, bar) ['baz', 'qux']; +local named(foo, bar=10, baz=20) = ['baz', 'qux']; +local in1troduction = 'introduction'; +assert 5 > 3: "interesting"; +//comment +{ + local foo = "bar", + spam: 'eggs', +} + +{local foo = "bar"} + + +{ + // this is a comment + # python-style comment + assert 1 == 1: 'huh?', + spam: 'eggs // /* #', + spam2(foo, bar):: 2, + spa: 'eggs', + foo: 'bar', + block: ||| + Hello + Block + |||, + baz: 'qux' + 'fuzz', + 'm:oo': 'cow', + "b:oo": ('cow'), + goo: ['bar', 'ba\nz'], + spam3: 2.25, + spam4::: -2.25, + spam5::: +2.25, + spam6//funky + : 'hello' //moo + , //moo + ['spa\'m']: 'eggs', + ["spa\"m2"]: "eggs", + raw1: @'hello\', + raw2: @"hello\", + spam7: foo, + spam8: lambda(1, 2), + spam9: self.spam2(3, 4), + intro: in1troduction, + spam_10: 10, + spam_11(y=10):: 11, + spam12: std.type('null'), + spam13+: 27, + spam14: $.spam13, + spam15: ~5, + spam16: !false, + spam17: 0 - 5, + spam18: 5 & 3, + spam19: 5 | 3, + spam20: 5 ^ 3, + spam21: 5 == 3, + spam22: 5 < 3, + spam23: 5 > 3, + spam24: 5 * 3, + spam25: 5 / 3, + spam26: 5 % 3, +} diff --git a/tests/examplefiles/jsonnet/example.jsonnet.output b/tests/examplefiles/jsonnet/example.jsonnet.output new file mode 100644 index 0000000000..63d8973ec0 --- /dev/null +++ b/tests/examplefiles/jsonnet/example.jsonnet.output @@ -0,0 +1,697 @@ +'/* Multiline /\ncomment */' Comment +'\n' Text.Whitespace + +'local' Keyword +' ' Text.Whitespace +'x' Name.Variable +' ' Text.Whitespace +'' Text.Whitespace +'=' Operator +' ' Text.Whitespace +'100' Literal.Number.Float +';' Punctuation +'\n' Text.Whitespace + +'/* Multiline\ncomment */' Comment +'\n\n' Text.Whitespace + +'/**\n * Docs\n **/' Literal.String.Doc +'\n\n\n' Text.Whitespace + +'local' Keyword +' ' Text.Whitespace +'i' Name.Variable +' ' Text.Whitespace +'' Text.Whitespace +'=' Operator +' ' Text.Whitespace +'import' Keyword +' ' Text.Whitespace +"'" Literal.String +'f' Literal.String +'o' Literal.String +'o' Literal.String +"'" Literal.String +';' Punctuation +'\n' Text.Whitespace + +'local' Keyword +' ' Text.Whitespace +'foo' Name.Variable +' ' Text.Whitespace +'' Text.Whitespace +'=' Operator +' ' Text.Whitespace +"'" Literal.String +'b' Literal.String +'a' Literal.String +'r' Literal.String +"'" Literal.String +';' Punctuation +'\n' Text.Whitespace + +'local' Keyword +' ' Text.Whitespace +'lambda' Name.Variable +' ' Text.Whitespace +'' Text.Whitespace +'=' Operator +' ' Text.Whitespace +'function' Keyword +'(' Punctuation +'foo' Name.Variable +',' Punctuation +' ' Text.Whitespace +'bar' Name.Variable +')' Punctuation +' ' Text.Whitespace +'[' Punctuation +"'" Literal.String +'b' Literal.String +'a' Literal.String +'z' Literal.String +"'" Literal.String +',' Punctuation +' ' Text.Whitespace +"'" Literal.String +'q' Literal.String +'u' Literal.String +'x' Literal.String +"'" Literal.String +']' Punctuation +';' Punctuation +'\n' Text.Whitespace + +'local' Keyword +' ' Text.Whitespace +'named' Name.Function +'(' Punctuation +'foo' Name.Variable +',' Punctuation +' ' Text.Whitespace +'bar' Name.Variable +'=' Operator +'10' Literal.Number.Float +'' Text.Whitespace +',' Punctuation +' ' Text.Whitespace +'baz' Name.Variable +'=' Operator +'20' Literal.Number.Float +'' Text.Whitespace +')' Punctuation +' ' Text.Whitespace +'' Text.Whitespace +'=' Operator +' ' Text.Whitespace +'[' Punctuation +"'" Literal.String +'b' Literal.String +'a' Literal.String +'z' Literal.String +"'" Literal.String +',' Punctuation +' ' Text.Whitespace +"'" Literal.String +'q' Literal.String +'u' Literal.String +'x' Literal.String +"'" Literal.String +']' Punctuation +';' Punctuation +'\n' Text.Whitespace + +'local' Keyword +' ' Text.Whitespace +'in1troduction' Name.Variable +' ' Text.Whitespace +'' Text.Whitespace +'=' Operator +' ' Text.Whitespace +"'" Literal.String +'i' Literal.String +'n' Literal.String +'t' Literal.String +'r' Literal.String +'o' Literal.String +'d' Literal.String +'u' Literal.String +'c' Literal.String +'t' Literal.String +'i' Literal.String +'o' Literal.String +'n' Literal.String +"'" Literal.String +';' Punctuation +'\n' Text.Whitespace + +'assert' Keyword +' ' Text.Whitespace +'5' Literal.Number.Float +' ' Text.Whitespace +'>' Operator +' ' Text.Whitespace +'3' Literal.Number.Float +':' Punctuation +' ' Text.Whitespace +'"' Literal.String +'i' Literal.String +'n' Literal.String +'t' Literal.String +'e' Literal.String +'r' Literal.String +'e' Literal.String +'s' Literal.String +'t' Literal.String +'i' Literal.String +'n' Literal.String +'g' Literal.String +'"' Literal.String +';' Punctuation +'\n' Text.Whitespace + +'//comment\n' Comment.Single + +'{' Punctuation +'\n ' Text.Whitespace +'local' Keyword +' ' Text.Whitespace +'foo' Name.Variable +' ' Text.Whitespace +'=' Operator +' ' Text.Whitespace +'"' Literal.String +'b' Literal.String +'a' Literal.String +'r' Literal.String +'"' Literal.String +',' Punctuation +'\n ' Text.Whitespace +'' Name.Variable +'spam' Name.Variable +':' Punctuation +' ' Text.Whitespace +"'" Literal.String +'e' Literal.String +'g' Literal.String +'g' Literal.String +'s' Literal.String +"'" Literal.String +',' Punctuation +'\n' Text.Whitespace + +'}' Punctuation +'\n\n' Text.Whitespace + +'{' Punctuation +'local' Keyword +' ' Text.Whitespace +'foo' Name.Variable +' ' Text.Whitespace +'=' Operator +' ' Text.Whitespace +'"' Literal.String +'b' Literal.String +'a' Literal.String +'r' Literal.String +'"' Literal.String +'}' Punctuation +'\n\n\n' Text.Whitespace + +'{' Punctuation +'\n ' Text.Whitespace +'// this is a comment\n' Comment.Single + +' ' Text.Whitespace +'# python-style comment\n' Comment.Single + +' ' Text.Whitespace +'assert' Keyword +' ' Text.Whitespace +'1' Literal.Number.Float +' ' Text.Whitespace +'=' Operator +'=' Operator +' ' Text.Whitespace +'1' Literal.Number.Float +':' Punctuation +' ' Text.Whitespace +"'" Literal.String +'h' Literal.String +'u' Literal.String +'h' Literal.String +'?' Literal.String +"'" Literal.String +',' Punctuation +'\n ' Text.Whitespace +'' Name.Variable +'spam' Name.Variable +':' Punctuation +' ' Text.Whitespace +"'" Literal.String +'e' Literal.String +'g' Literal.String +'g' Literal.String +'s' Literal.String +' ' Literal.String +'/' Literal.String +'/' Literal.String +' ' Literal.String +'/' Literal.String +'*' Literal.String +' ' Literal.String +'#' Literal.String +"'" Literal.String +',' Punctuation +'\n ' Text.Whitespace +'' Name.Variable +'spam2' Name.Function +'(' Punctuation +'foo' Name.Variable +',' Punctuation +' ' Text.Whitespace +'bar' Name.Variable +')' Punctuation +'::' Punctuation +' ' Text.Whitespace +'2' Literal.Number.Float +',' Punctuation +'\n ' Text.Whitespace +'' Name.Variable +'spa' Name.Variable +':' Punctuation +' ' Text.Whitespace +"'" Literal.String +'e' Literal.String +'g' Literal.String +'g' Literal.String +'s' Literal.String +"'" Literal.String +',' Punctuation +'\n ' Text.Whitespace +'' Name.Variable +'foo' Name.Variable +':' Punctuation +' ' Text.Whitespace +"'" Literal.String +'b' Literal.String +'a' Literal.String +'r' Literal.String +"'" Literal.String +',' Punctuation +'\n ' Text.Whitespace +'' Name.Variable +'block' Name.Variable +':' Punctuation +' ' Text.Whitespace +'|||\n Hello\n Block\n |||' Literal.String +',' Punctuation +'\n ' Text.Whitespace +'' Name.Variable +'baz' Name.Variable +':' Punctuation +' ' Text.Whitespace +"'" Literal.String +'q' Literal.String +'u' Literal.String +'x' Literal.String +"'" Literal.String +' ' Text.Whitespace +'+' Operator +' ' Text.Whitespace +"'" Literal.String +'f' Literal.String +'u' Literal.String +'z' Literal.String +'z' Literal.String +"'" Literal.String +',' Punctuation +'\n ' Text.Whitespace +"'" Name.Variable +"m:oo'" Name.Variable +':' Punctuation +' ' Text.Whitespace +"'" Literal.String +'c' Literal.String +'o' Literal.String +'w' Literal.String +"'" Literal.String +',' Punctuation +'\n ' Text.Whitespace +'"' Name.Variable +'b:oo"' Name.Variable +':' Punctuation +' ' Text.Whitespace +'(' Punctuation +"'" Literal.String +'c' Literal.String +'o' Literal.String +'w' Literal.String +"'" Literal.String +')' Punctuation +',' Punctuation +'\n ' Text.Whitespace +'' Name.Variable +'goo' Name.Variable +':' Punctuation +' ' Text.Whitespace +'[' Punctuation +"'" Literal.String +'b' Literal.String +'a' Literal.String +'r' Literal.String +"'" Literal.String +',' Punctuation +' ' Text.Whitespace +"'" Literal.String +'b' Literal.String +'a' Literal.String +'\\n' Literal.String.Escape +'z' Literal.String +"'" Literal.String +']' Punctuation +',' Punctuation +'\n ' Text.Whitespace +'' Name.Variable +'spam3' Name.Variable +':' Punctuation +' ' Text.Whitespace +'2.2' Literal.Number.Float +'5' Literal.Number.Float +',' Punctuation +'\n ' Text.Whitespace +'' Name.Variable +'spam4' Name.Variable +':::' Punctuation +' ' Text.Whitespace +'-2.2' Literal.Number.Float +'5' Literal.Number.Float +',' Punctuation +'\n ' Text.Whitespace +'' Name.Variable +'spam5' Name.Variable +':::' Punctuation +' ' Text.Whitespace +'+2.2' Literal.Number.Float +'5' Literal.Number.Float +',' Punctuation +'\n ' Text.Whitespace +'' Name.Variable +'spam6' Name.Variable +'//funky\n' Comment.Single + +' ' Text.Whitespace +':' Punctuation +' ' Text.Whitespace +"'" Literal.String +'h' Literal.String +'e' Literal.String +'l' Literal.String +'l' Literal.String +'o' Literal.String +"'" Literal.String +' ' Text.Whitespace +'//moo\n' Comment.Single + +' ' Text.Whitespace +',' Punctuation +' ' Text.Whitespace +'//moo\n' Comment.Single + +' ' Text.Whitespace +'[' Operator +"'" Literal.String +'s' Literal.String +'p' Literal.String +'a' Literal.String +"\\'" Literal.String.Escape +'m' Literal.String +"'" Literal.String +']' Operator +':' Punctuation +' ' Text.Whitespace +"'" Literal.String +'e' Literal.String +'g' Literal.String +'g' Literal.String +'s' Literal.String +"'" Literal.String +',' Punctuation +'\n ' Text.Whitespace +'[' Operator +'"' Literal.String +'s' Literal.String +'p' Literal.String +'a' Literal.String +'\\"' Literal.String.Escape +'m' Literal.String +'2' Literal.String +'"' Literal.String +']' Operator +':' Punctuation +' ' Text.Whitespace +'"' Literal.String +'e' Literal.String +'g' Literal.String +'g' Literal.String +'s' Literal.String +'"' Literal.String +',' Punctuation +'\n ' Text.Whitespace +'' Name.Variable +'raw1' Name.Variable +':' Punctuation +' ' Text.Whitespace +"@'hello\\'" Literal.String +',' Punctuation +'\n ' Text.Whitespace +'' Name.Variable +'raw2' Name.Variable +':' Punctuation +' ' Text.Whitespace +'@"hello\\"' Literal.String +',' Punctuation +'\n ' Text.Whitespace +'' Name.Variable +'spam7' Name.Variable +':' Punctuation +' ' Text.Whitespace +'foo' Name.Variable +',' Punctuation +'\n ' Text.Whitespace +'' Name.Variable +'spam8' Name.Variable +':' Punctuation +' ' Text.Whitespace +'lambda' Name.Function +'(' Punctuation +'1' Literal.Number.Float +',' Punctuation +' ' Text.Whitespace +'2' Literal.Number.Float +')' Punctuation +',' Punctuation +'\n ' Text.Whitespace +'' Name.Variable +'spam9' Name.Variable +':' Punctuation +' ' Text.Whitespace +'self' Keyword +'.' Punctuation +'spam2' Name.Function +'(' Punctuation +'3' Literal.Number.Float +',' Punctuation +' ' Text.Whitespace +'4' Literal.Number.Float +')' Punctuation +',' Punctuation +'\n ' Text.Whitespace +'' Name.Variable +'intro' Name.Variable +':' Punctuation +' ' Text.Whitespace +'in1troduction' Name.Variable +',' Punctuation +'\n ' Text.Whitespace +'' Name.Variable +'spam_10' Name.Variable +':' Punctuation +' ' Text.Whitespace +'10' Literal.Number.Float +',' Punctuation +'\n ' Text.Whitespace +'' Name.Variable +'spam_11' Name.Function +'(' Punctuation +'y' Name.Variable +'=' Operator +'10' Literal.Number.Float +'' Text.Whitespace +')' Punctuation +'::' Punctuation +' ' Text.Whitespace +'11' Literal.Number.Float +',' Punctuation +'\n ' Text.Whitespace +'' Name.Variable +'spam12' Name.Variable +':' Punctuation +' ' Text.Whitespace +'std.type' Name.Builtin +'(' Punctuation +"'" Literal.String +'n' Literal.String +'u' Literal.String +'l' Literal.String +'l' Literal.String +"'" Literal.String +')' Punctuation +',' Punctuation +'\n ' Text.Whitespace +'' Name.Variable +'spam13' Name.Variable +'+:' Punctuation +' ' Text.Whitespace +'27' Literal.Number.Float +',' Punctuation +'\n ' Text.Whitespace +'' Name.Variable +'spam14' Name.Variable +':' Punctuation +' ' Text.Whitespace +'$' Operator +'.' Punctuation +'spam13' Name.Variable +',' Punctuation +'\n ' Text.Whitespace +'' Name.Variable +'spam15' Name.Variable +':' Punctuation +' ' Text.Whitespace +'~' Operator +'5' Literal.Number.Float +',' Punctuation +'\n ' Text.Whitespace +'' Name.Variable +'spam16' Name.Variable +':' Punctuation +' ' Text.Whitespace +'!' Operator +'false' Keyword +',' Punctuation +'\n ' Text.Whitespace +'' Name.Variable +'spam17' Name.Variable +':' Punctuation +' ' Text.Whitespace +'0' Literal.Number.Float +' ' Text.Whitespace +'-' Operator +' ' Text.Whitespace +'5' Literal.Number.Float +',' Punctuation +'\n ' Text.Whitespace +'' Name.Variable +'spam18' Name.Variable +':' Punctuation +' ' Text.Whitespace +'5' Literal.Number.Float +' ' Text.Whitespace +'&' Operator +' ' Text.Whitespace +'3' Literal.Number.Float +',' Punctuation +'\n ' Text.Whitespace +'' Name.Variable +'spam19' Name.Variable +':' Punctuation +' ' Text.Whitespace +'5' Literal.Number.Float +' ' Text.Whitespace +'|' Operator +' ' Text.Whitespace +'3' Literal.Number.Float +',' Punctuation +'\n ' Text.Whitespace +'' Name.Variable +'spam20' Name.Variable +':' Punctuation +' ' Text.Whitespace +'5' Literal.Number.Float +' ' Text.Whitespace +'^' Operator +' ' Text.Whitespace +'3' Literal.Number.Float +',' Punctuation +'\n ' Text.Whitespace +'' Name.Variable +'spam21' Name.Variable +':' Punctuation +' ' Text.Whitespace +'5' Literal.Number.Float +' ' Text.Whitespace +'=' Operator +'=' Operator +' ' Text.Whitespace +'3' Literal.Number.Float +',' Punctuation +'\n ' Text.Whitespace +'' Name.Variable +'spam22' Name.Variable +':' Punctuation +' ' Text.Whitespace +'5' Literal.Number.Float +' ' Text.Whitespace +'<' Operator +' ' Text.Whitespace +'3' Literal.Number.Float +',' Punctuation +'\n ' Text.Whitespace +'' Name.Variable +'spam23' Name.Variable +':' Punctuation +' ' Text.Whitespace +'5' Literal.Number.Float +' ' Text.Whitespace +'>' Operator +' ' Text.Whitespace +'3' Literal.Number.Float +',' Punctuation +'\n ' Text.Whitespace +'' Name.Variable +'spam24' Name.Variable +':' Punctuation +' ' Text.Whitespace +'5' Literal.Number.Float +' ' Text.Whitespace +'*' Operator +' ' Text.Whitespace +'3' Literal.Number.Float +',' Punctuation +'\n ' Text.Whitespace +'' Name.Variable +'spam25' Name.Variable +':' Punctuation +' ' Text.Whitespace +'5' Literal.Number.Float +' ' Text.Whitespace +'/' Operator +' ' Text.Whitespace +'3' Literal.Number.Float +',' Punctuation +'\n ' Text.Whitespace +'' Name.Variable +'spam26' Name.Variable +':' Punctuation +' ' Text.Whitespace +'5' Literal.Number.Float +' ' Text.Whitespace +'%' Operator +' ' Text.Whitespace +'3' Literal.Number.Float +',' Punctuation +'\n' Text.Whitespace + +'}' Punctuation +'\n' Text.Whitespace From 2110d667fdccb75f9f9a3cbe293ca4235830fd52 Mon Sep 17 00:00:00 2001 From: Aaron Bentley Date: Thu, 22 Sep 2022 17:25:32 -0400 Subject: [PATCH 2/9] Use words() --- pygments/lexers/jsonnet.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pygments/lexers/jsonnet.py b/pygments/lexers/jsonnet.py index 6b25d157f3..2ccd5b1eda 100644 --- a/pygments/lexers/jsonnet.py +++ b/pygments/lexers/jsonnet.py @@ -1,4 +1,7 @@ -from pygments.lexer import RegexLexer +from pygments.lexer import ( + RegexLexer, + words, +) from pygments.token import ( Comment, Keyword, @@ -28,10 +31,10 @@ whitespace = (r'[\n ]+', Whitespace) -keywords = '|'.join([ +keywords = words([ 'assert', 'else', 'error', 'false', 'for', 'if', 'import', 'importstr', 'in', 'null', 'tailstrict', 'then', 'self', 'super', 'true', -]) +]).get() rvalues = comments + [ From 0375c9c957dd55148757cc9a9faed8c4e30ea8ba Mon Sep 17 00:00:00 2001 From: Aaron Bentley Date: Sat, 24 Sep 2022 17:02:18 -0400 Subject: [PATCH 3/9] Combine regexes Co-authored-by: Jean Abou-Samra --- pygments/lexers/jsonnet.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pygments/lexers/jsonnet.py b/pygments/lexers/jsonnet.py index 2ccd5b1eda..5a10db455c 100644 --- a/pygments/lexers/jsonnet.py +++ b/pygments/lexers/jsonnet.py @@ -21,8 +21,7 @@ comments = [ - (r'//.*\n', Comment.Single), - (r'#.*\n', Comment.Single), + (r'(//|#).*\n', Comment.Single), (r'/\*\*([^/]|/(?!\*))*\*/', String.Doc), (r'/\*([^/]|/(?!\*))*\*/', Comment), ] From 327f404583ad37ef79b7c7cc321be583d9091784 Mon Sep 17 00:00:00 2001 From: Aaron Bentley Date: Sat, 24 Sep 2022 17:48:28 -0400 Subject: [PATCH 4/9] Copyright and tweaks. --- pygments/lexers/jsonnet.py | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/pygments/lexers/jsonnet.py b/pygments/lexers/jsonnet.py index 5a10db455c..bcb2056bc1 100644 --- a/pygments/lexers/jsonnet.py +++ b/pygments/lexers/jsonnet.py @@ -1,3 +1,12 @@ +""" + pygments.lexers.jsonnet + ~~~~~~~~~~~~~~~~~~~~~~~ + + Lexer for Jsonnet data templating language. + + :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" from pygments.lexer import ( RegexLexer, words, @@ -27,9 +36,6 @@ ] -whitespace = (r'[\n ]+', Whitespace) - - keywords = words([ 'assert', 'else', 'error', 'false', 'for', 'if', 'import', 'importstr', 'in', 'null', 'tailstrict', 'then', 'self', 'super', 'true', @@ -47,10 +53,10 @@ (r'[!$~+\-&|^=<>*/%]', Operator), (r'[{]', Punctuation, 'object'), (r'\[', Punctuation, 'array'), - (r'local', Keyword, ('local_name')), + (r'local\b', Keyword, ('local_name')), (r'assert', Keyword, 'assert'), (fr'({keywords})(?!{jsonnet_token_chars})', Keyword), - whitespace, + (r'\s+', Whitespace), (r'function(?=\()', Keyword, 'function_params'), (r'std\.' + jsonnet_function_token, Name.Builtin, 'function_args'), (jsonnet_function_token, Name.Function, 'function_args'), @@ -89,7 +95,7 @@ class JsonnetLexer(RegexLexer): 'local_name': [ (jsonnet_function_token, Name.Function, 'function_params'), (jsonnet_token, Name.Variable), - whitespace, + (r'\s+', Whitespace), ('(?==)', Whitespace, ('#pop', 'local_value')), ], 'local_value': [ @@ -105,19 +111,19 @@ class JsonnetLexer(RegexLexer): (r'\(', Punctuation), (r'\)', Punctuation, '#pop'), (r',', Punctuation), - whitespace, + (r'\s+', Whitespace), (r'=', Operator, 'function_param_default'), ], 'function_args': [ (r'\(', Punctuation), (r'\)', Punctuation, '#pop'), (r',', Punctuation), - whitespace, + (r'\s+', Whitespace), ] + rvalues, 'object': [ - whitespace, - (r'local', Keyword, 'object_local_name'), - ('assert', Keyword, 'object_assert'), + (r'\s+', Whitespace), + (r'local\b', Keyword, 'object_local_name'), + (r'assert\b', Keyword, 'object_assert'), (r'\[', Operator, 'field_name_expr'), (fr'(?={jsonnet_token})', Name.Variable, 'field_name'), (r'}', Punctuation, '#pop'), @@ -139,7 +145,7 @@ class JsonnetLexer(RegexLexer): (r'(?=[,\)])', Whitespace, '#pop') ] + rvalues, 'field_separator': [ - whitespace, + (r'\s+', Whitespace), (r'\+?::?:?', Punctuation, ('#pop', '#pop', 'field_value')), ] + comments, 'field_value': [ @@ -152,7 +158,7 @@ class JsonnetLexer(RegexLexer): ] + rvalues, 'object_local_name': [ (jsonnet_token, Name.Variable, ('#pop', 'object_local_value')), - whitespace, + (r'\s+', Whitespace), ], 'object_local_value': [ (r'=', Operator), From 5b57afdb378223c6353474cc33bbb9c013b911fc Mon Sep 17 00:00:00 2001 From: Aaron Bentley Date: Sat, 24 Sep 2022 17:54:08 -0400 Subject: [PATCH 5/9] Use words() with suffix inline. --- pygments/lexers/jsonnet.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/pygments/lexers/jsonnet.py b/pygments/lexers/jsonnet.py index bcb2056bc1..decb28cd1f 100644 --- a/pygments/lexers/jsonnet.py +++ b/pygments/lexers/jsonnet.py @@ -36,12 +36,6 @@ ] -keywords = words([ - 'assert', 'else', 'error', 'false', 'for', 'if', 'import', 'importstr', - 'in', 'null', 'tailstrict', 'then', 'self', 'super', 'true', -]).get() - - rvalues = comments + [ (r"@'.*'", String), (r'@".*"', String), @@ -55,7 +49,10 @@ (r'\[', Punctuation, 'array'), (r'local\b', Keyword, ('local_name')), (r'assert', Keyword, 'assert'), - (fr'({keywords})(?!{jsonnet_token_chars})', Keyword), + (words([ + 'assert', 'else', 'error', 'false', 'for', 'if', 'import', 'importstr', + 'in', 'null', 'tailstrict', 'then', 'self', 'super', 'true', + ], suffix=r'\b'), Keyword), (r'\s+', Whitespace), (r'function(?=\()', Keyword, 'function_params'), (r'std\.' + jsonnet_function_token, Name.Builtin, 'function_args'), From 9ae73d41794974d8a28221dcd9e8c80902a73d59 Mon Sep 17 00:00:00 2001 From: Aaron Bentley Date: Sat, 24 Sep 2022 18:09:53 -0400 Subject: [PATCH 6/9] Use include instead of plus sign. --- pygments/lexers/jsonnet.py | 103 ++++++++++++++++++++----------------- 1 file changed, 57 insertions(+), 46 deletions(-) diff --git a/pygments/lexers/jsonnet.py b/pygments/lexers/jsonnet.py index decb28cd1f..8d130be007 100644 --- a/pygments/lexers/jsonnet.py +++ b/pygments/lexers/jsonnet.py @@ -8,6 +8,7 @@ :license: BSD, see LICENSE for details. """ from pygments.lexer import ( + include, RegexLexer, words, ) @@ -29,39 +30,6 @@ jsonnet_function_token = jsonnet_token + r'(?=\()' -comments = [ - (r'(//|#).*\n', Comment.Single), - (r'/\*\*([^/]|/(?!\*))*\*/', String.Doc), - (r'/\*([^/]|/(?!\*))*\*/', Comment), -] - - -rvalues = comments + [ - (r"@'.*'", String), - (r'@".*"', String), - (r"'", String, 'singlestring'), - (r'"', String, 'doublestring'), - (r'(?s:\|\|\|.*\|\|\|)', String), - (r'[+-]?[0-9]+(.[0-9])?', Number.Float), - # Omit : despite spec because it appears to be used as a field separator - (r'[!$~+\-&|^=<>*/%]', Operator), - (r'[{]', Punctuation, 'object'), - (r'\[', Punctuation, 'array'), - (r'local\b', Keyword, ('local_name')), - (r'assert', Keyword, 'assert'), - (words([ - 'assert', 'else', 'error', 'false', 'for', 'if', 'import', 'importstr', - 'in', 'null', 'tailstrict', 'then', 'self', 'super', 'true', - ], suffix=r'\b'), Keyword), - (r'\s+', Whitespace), - (r'function(?=\()', Keyword, 'function_params'), - (r'std\.' + jsonnet_function_token, Name.Builtin, 'function_args'), - (jsonnet_function_token, Name.Function, 'function_args'), - (jsonnet_token, Name.Variable), - (r'[\.()]', Punctuation), -] - - def string_rules(quote_mark): return [ (r"[^{}\\]".format(quote_mark), String), @@ -82,13 +50,46 @@ class JsonnetLexer(RegexLexer): aliases = ['jsonnet'] filenames = ['*.jsonnet', '*.libsonnet'] tokens = { - 'root': rvalues, + # Not used by itself + '_comments': [ + (r'(//|#).*\n', Comment.Single), + (r'/\*\*([^/]|/(?!\*))*\*/', String.Doc), + (r'/\*([^/]|/(?!\*))*\*/', Comment), + ], + 'root': [ + include('_comments'), + (r"@'.*'", String), + (r'@".*"', String), + (r"'", String, 'singlestring'), + (r'"', String, 'doublestring'), + (r'(?s:\|\|\|.*\|\|\|)', String), + (r'[+-]?[0-9]+(.[0-9])?', Number.Float), + # Omit : despite spec because it appears to be used as a field + # separator + (r'[!$~+\-&|^=<>*/%]', Operator), + (r'[{]', Punctuation, 'object'), + (r'\[', Punctuation, 'array'), + (r'local\b', Keyword, ('local_name')), + (r'assert', Keyword, 'assert'), + (words([ + 'assert', 'else', 'error', 'false', 'for', 'if', 'import', + 'importstr', 'in', 'null', 'tailstrict', 'then', 'self', + 'super', 'true', + ], suffix=r'\b'), Keyword), + (r'\s+', Whitespace), + (r'function(?=\()', Keyword, 'function_params'), + (r'std\.' + jsonnet_function_token, Name.Builtin, 'function_args'), + (jsonnet_function_token, Name.Function, 'function_args'), + (jsonnet_token, Name.Variable), + (r'[\.()]', Punctuation), + ], 'singlestring': string_rules("'"), 'doublestring': string_rules('"'), 'array': [ (r',', Punctuation), (r'\]', Punctuation, '#pop'), - ] + rvalues, + include('root'), + ], 'local_name': [ (jsonnet_function_token, Name.Function, 'function_params'), (jsonnet_token, Name.Variable), @@ -98,11 +99,13 @@ class JsonnetLexer(RegexLexer): 'local_value': [ (r'=', Operator), (r';', Punctuation, '#pop'), - ] + rvalues, + include('root'), + ], 'assert': [ (r':', Punctuation), (r';', Punctuation, '#pop'), - ] + rvalues, + include('root'), + ], 'function_params': [ (jsonnet_token, Name.Variable), (r'\(', Punctuation), @@ -116,7 +119,8 @@ class JsonnetLexer(RegexLexer): (r'\)', Punctuation, '#pop'), (r',', Punctuation), (r'\s+', Whitespace), - ] + rvalues, + include('root'), + ], 'object': [ (r'\s+', Whitespace), (r'local\b', Keyword, 'object_local_name'), @@ -126,7 +130,8 @@ class JsonnetLexer(RegexLexer): (r'}', Punctuation, '#pop'), (r'"', Name.Variable, 'double_field_name'), (r"'", Name.Variable, 'single_field_name'), - ] + comments, + include('_comments'), + ], 'field_name': [ (jsonnet_function_token, Name.Function, ('field_separator', 'function_params') @@ -137,22 +142,27 @@ class JsonnetLexer(RegexLexer): 'single_field_name': quoted_field_name("'"), 'field_name_expr': [ (r'\]', Operator, 'field_separator'), - ] + rvalues, + include('root'), + ], 'function_param_default': [ - (r'(?=[,\)])', Whitespace, '#pop') - ] + rvalues, + (r'(?=[,\)])', Whitespace, '#pop'), + include('root'), + ], 'field_separator': [ (r'\s+', Whitespace), (r'\+?::?:?', Punctuation, ('#pop', '#pop', 'field_value')), - ] + comments, + include('_comments'), + ], 'field_value': [ (r',', Punctuation, '#pop'), (r'}', Punctuation, '#pop:2'), - ] + rvalues, + include('root'), + ], 'object_assert': [ (r':', Punctuation), (r',', Punctuation, '#pop'), - ] + rvalues, + include('root'), + ], 'object_local_name': [ (jsonnet_token, Name.Variable, ('#pop', 'object_local_value')), (r'\s+', Whitespace), @@ -161,5 +171,6 @@ class JsonnetLexer(RegexLexer): (r'=', Operator), (r',', Punctuation, '#pop'), (r'}', Punctuation, '#pop:2'), - ] + rvalues, + include('root'), + ], } From c455497189d2bd42329e4c8f05c86affb192d419 Mon Sep 17 00:00:00 2001 From: Aaron Bentley Date: Sat, 24 Sep 2022 18:18:03 -0400 Subject: [PATCH 7/9] Switch to \w --- pygments/lexers/jsonnet.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pygments/lexers/jsonnet.py b/pygments/lexers/jsonnet.py index 8d130be007..e6f37af751 100644 --- a/pygments/lexers/jsonnet.py +++ b/pygments/lexers/jsonnet.py @@ -25,8 +25,7 @@ __all__ = ['JsonnetLexer'] -jsonnet_token_chars = r'[_A-Za-z0-9]' -jsonnet_token = r'[_A-Za-z]' + jsonnet_token_chars + '*' +jsonnet_token = r'[^\W\d]\w*' jsonnet_function_token = jsonnet_token + r'(?=\()' From 11a7483e68f78304ff43ce339b89d61517bad900 Mon Sep 17 00:00:00 2001 From: Aaron Bentley Date: Sat, 24 Sep 2022 19:48:11 -0400 Subject: [PATCH 8/9] Updates from review. --- pygments/lexers/jsonnet.py | 7 +- .../jsonnet/example.jsonnet.output | 70 +++++++++---------- 2 files changed, 40 insertions(+), 37 deletions(-) diff --git a/pygments/lexers/jsonnet.py b/pygments/lexers/jsonnet.py index e6f37af751..0794c060c7 100644 --- a/pygments/lexers/jsonnet.py +++ b/pygments/lexers/jsonnet.py @@ -20,6 +20,7 @@ Operator, Punctuation, String, + Text, Whitespace, ) @@ -48,6 +49,7 @@ class JsonnetLexer(RegexLexer): name = 'Jsonnet' aliases = ['jsonnet'] filenames = ['*.jsonnet', '*.libsonnet'] + url = "https://jsonnet.org" tokens = { # Not used by itself '_comments': [ @@ -62,6 +64,7 @@ class JsonnetLexer(RegexLexer): (r"'", String, 'singlestring'), (r'"', String, 'doublestring'), (r'(?s:\|\|\|.*\|\|\|)', String), + # Jsonnet has no integers, only an IEEE754 64-bit float (r'[+-]?[0-9]+(.[0-9])?', Number.Float), # Omit : despite spec because it appears to be used as a field # separator @@ -69,7 +72,7 @@ class JsonnetLexer(RegexLexer): (r'[{]', Punctuation, 'object'), (r'\[', Punctuation, 'array'), (r'local\b', Keyword, ('local_name')), - (r'assert', Keyword, 'assert'), + (r'assert\b', Keyword, 'assert'), (words([ 'assert', 'else', 'error', 'false', 'for', 'if', 'import', 'importstr', 'in', 'null', 'tailstrict', 'then', 'self', @@ -125,7 +128,7 @@ class JsonnetLexer(RegexLexer): (r'local\b', Keyword, 'object_local_name'), (r'assert\b', Keyword, 'object_assert'), (r'\[', Operator, 'field_name_expr'), - (fr'(?={jsonnet_token})', Name.Variable, 'field_name'), + (fr'(?={jsonnet_token})', Text, 'field_name'), (r'}', Punctuation, '#pop'), (r'"', Name.Variable, 'double_field_name'), (r"'", Name.Variable, 'single_field_name'), diff --git a/tests/examplefiles/jsonnet/example.jsonnet.output b/tests/examplefiles/jsonnet/example.jsonnet.output index 63d8973ec0..3b98523e59 100644 --- a/tests/examplefiles/jsonnet/example.jsonnet.output +++ b/tests/examplefiles/jsonnet/example.jsonnet.output @@ -187,7 +187,7 @@ '"' Literal.String ',' Punctuation '\n ' Text.Whitespace -'' Name.Variable +'' Text 'spam' Name.Variable ':' Punctuation ' ' Text.Whitespace @@ -244,7 +244,7 @@ "'" Literal.String ',' Punctuation '\n ' Text.Whitespace -'' Name.Variable +'' Text 'spam' Name.Variable ':' Punctuation ' ' Text.Whitespace @@ -264,7 +264,7 @@ "'" Literal.String ',' Punctuation '\n ' Text.Whitespace -'' Name.Variable +'' Text 'spam2' Name.Function '(' Punctuation 'foo' Name.Variable @@ -277,7 +277,7 @@ '2' Literal.Number.Float ',' Punctuation '\n ' Text.Whitespace -'' Name.Variable +'' Text 'spa' Name.Variable ':' Punctuation ' ' Text.Whitespace @@ -289,7 +289,7 @@ "'" Literal.String ',' Punctuation '\n ' Text.Whitespace -'' Name.Variable +'' Text 'foo' Name.Variable ':' Punctuation ' ' Text.Whitespace @@ -300,14 +300,14 @@ "'" Literal.String ',' Punctuation '\n ' Text.Whitespace -'' Name.Variable +'' Text 'block' Name.Variable ':' Punctuation ' ' Text.Whitespace '|||\n Hello\n Block\n |||' Literal.String ',' Punctuation '\n ' Text.Whitespace -'' Name.Variable +'' Text 'baz' Name.Variable ':' Punctuation ' ' Text.Whitespace @@ -351,7 +351,7 @@ ')' Punctuation ',' Punctuation '\n ' Text.Whitespace -'' Name.Variable +'' Text 'goo' Name.Variable ':' Punctuation ' ' Text.Whitespace @@ -372,7 +372,7 @@ ']' Punctuation ',' Punctuation '\n ' Text.Whitespace -'' Name.Variable +'' Text 'spam3' Name.Variable ':' Punctuation ' ' Text.Whitespace @@ -380,7 +380,7 @@ '5' Literal.Number.Float ',' Punctuation '\n ' Text.Whitespace -'' Name.Variable +'' Text 'spam4' Name.Variable ':::' Punctuation ' ' Text.Whitespace @@ -388,7 +388,7 @@ '5' Literal.Number.Float ',' Punctuation '\n ' Text.Whitespace -'' Name.Variable +'' Text 'spam5' Name.Variable ':::' Punctuation ' ' Text.Whitespace @@ -396,7 +396,7 @@ '5' Literal.Number.Float ',' Punctuation '\n ' Text.Whitespace -'' Name.Variable +'' Text 'spam6' Name.Variable '//funky\n' Comment.Single @@ -458,28 +458,28 @@ '"' Literal.String ',' Punctuation '\n ' Text.Whitespace -'' Name.Variable +'' Text 'raw1' Name.Variable ':' Punctuation ' ' Text.Whitespace "@'hello\\'" Literal.String ',' Punctuation '\n ' Text.Whitespace -'' Name.Variable +'' Text 'raw2' Name.Variable ':' Punctuation ' ' Text.Whitespace '@"hello\\"' Literal.String ',' Punctuation '\n ' Text.Whitespace -'' Name.Variable +'' Text 'spam7' Name.Variable ':' Punctuation ' ' Text.Whitespace 'foo' Name.Variable ',' Punctuation '\n ' Text.Whitespace -'' Name.Variable +'' Text 'spam8' Name.Variable ':' Punctuation ' ' Text.Whitespace @@ -492,7 +492,7 @@ ')' Punctuation ',' Punctuation '\n ' Text.Whitespace -'' Name.Variable +'' Text 'spam9' Name.Variable ':' Punctuation ' ' Text.Whitespace @@ -507,21 +507,21 @@ ')' Punctuation ',' Punctuation '\n ' Text.Whitespace -'' Name.Variable +'' Text 'intro' Name.Variable ':' Punctuation ' ' Text.Whitespace 'in1troduction' Name.Variable ',' Punctuation '\n ' Text.Whitespace -'' Name.Variable +'' Text 'spam_10' Name.Variable ':' Punctuation ' ' Text.Whitespace '10' Literal.Number.Float ',' Punctuation '\n ' Text.Whitespace -'' Name.Variable +'' Text 'spam_11' Name.Function '(' Punctuation 'y' Name.Variable @@ -534,7 +534,7 @@ '11' Literal.Number.Float ',' Punctuation '\n ' Text.Whitespace -'' Name.Variable +'' Text 'spam12' Name.Variable ':' Punctuation ' ' Text.Whitespace @@ -549,14 +549,14 @@ ')' Punctuation ',' Punctuation '\n ' Text.Whitespace -'' Name.Variable +'' Text 'spam13' Name.Variable '+:' Punctuation ' ' Text.Whitespace '27' Literal.Number.Float ',' Punctuation '\n ' Text.Whitespace -'' Name.Variable +'' Text 'spam14' Name.Variable ':' Punctuation ' ' Text.Whitespace @@ -565,7 +565,7 @@ 'spam13' Name.Variable ',' Punctuation '\n ' Text.Whitespace -'' Name.Variable +'' Text 'spam15' Name.Variable ':' Punctuation ' ' Text.Whitespace @@ -573,7 +573,7 @@ '5' Literal.Number.Float ',' Punctuation '\n ' Text.Whitespace -'' Name.Variable +'' Text 'spam16' Name.Variable ':' Punctuation ' ' Text.Whitespace @@ -581,7 +581,7 @@ 'false' Keyword ',' Punctuation '\n ' Text.Whitespace -'' Name.Variable +'' Text 'spam17' Name.Variable ':' Punctuation ' ' Text.Whitespace @@ -592,7 +592,7 @@ '5' Literal.Number.Float ',' Punctuation '\n ' Text.Whitespace -'' Name.Variable +'' Text 'spam18' Name.Variable ':' Punctuation ' ' Text.Whitespace @@ -603,7 +603,7 @@ '3' Literal.Number.Float ',' Punctuation '\n ' Text.Whitespace -'' Name.Variable +'' Text 'spam19' Name.Variable ':' Punctuation ' ' Text.Whitespace @@ -614,7 +614,7 @@ '3' Literal.Number.Float ',' Punctuation '\n ' Text.Whitespace -'' Name.Variable +'' Text 'spam20' Name.Variable ':' Punctuation ' ' Text.Whitespace @@ -625,7 +625,7 @@ '3' Literal.Number.Float ',' Punctuation '\n ' Text.Whitespace -'' Name.Variable +'' Text 'spam21' Name.Variable ':' Punctuation ' ' Text.Whitespace @@ -637,7 +637,7 @@ '3' Literal.Number.Float ',' Punctuation '\n ' Text.Whitespace -'' Name.Variable +'' Text 'spam22' Name.Variable ':' Punctuation ' ' Text.Whitespace @@ -648,7 +648,7 @@ '3' Literal.Number.Float ',' Punctuation '\n ' Text.Whitespace -'' Name.Variable +'' Text 'spam23' Name.Variable ':' Punctuation ' ' Text.Whitespace @@ -659,7 +659,7 @@ '3' Literal.Number.Float ',' Punctuation '\n ' Text.Whitespace -'' Name.Variable +'' Text 'spam24' Name.Variable ':' Punctuation ' ' Text.Whitespace @@ -670,7 +670,7 @@ '3' Literal.Number.Float ',' Punctuation '\n ' Text.Whitespace -'' Name.Variable +'' Text 'spam25' Name.Variable ':' Punctuation ' ' Text.Whitespace @@ -681,7 +681,7 @@ '3' Literal.Number.Float ',' Punctuation '\n ' Text.Whitespace -'' Name.Variable +'' Text 'spam26' Name.Variable ':' Punctuation ' ' Text.Whitespace From 6f7ae34b01359b39dc1c16958ef6425840462589 Mon Sep 17 00:00:00 2001 From: Jean Abou Samra Date: Sun, 25 Sep 2022 12:44:15 +0200 Subject: [PATCH 9/9] Fix regexlint warnings caused by limitations of regexlint --- pygments/lexers/jsonnet.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pygments/lexers/jsonnet.py b/pygments/lexers/jsonnet.py index 0794c060c7..356191fe33 100644 --- a/pygments/lexers/jsonnet.py +++ b/pygments/lexers/jsonnet.py @@ -63,13 +63,13 @@ class JsonnetLexer(RegexLexer): (r'@".*"', String), (r"'", String, 'singlestring'), (r'"', String, 'doublestring'), - (r'(?s:\|\|\|.*\|\|\|)', String), + (r'\|\|\|(.|\n)*\|\|\|', String), # Jsonnet has no integers, only an IEEE754 64-bit float (r'[+-]?[0-9]+(.[0-9])?', Number.Float), # Omit : despite spec because it appears to be used as a field # separator (r'[!$~+\-&|^=<>*/%]', Operator), - (r'[{]', Punctuation, 'object'), + (r'\{', Punctuation, 'object'), (r'\[', Punctuation, 'array'), (r'local\b', Keyword, ('local_name')), (r'assert\b', Keyword, 'assert'), @@ -129,7 +129,7 @@ class JsonnetLexer(RegexLexer): (r'assert\b', Keyword, 'object_assert'), (r'\[', Operator, 'field_name_expr'), (fr'(?={jsonnet_token})', Text, 'field_name'), - (r'}', Punctuation, '#pop'), + (r'\}', Punctuation, '#pop'), (r'"', Name.Variable, 'double_field_name'), (r"'", Name.Variable, 'single_field_name'), include('_comments'), @@ -157,7 +157,7 @@ class JsonnetLexer(RegexLexer): ], 'field_value': [ (r',', Punctuation, '#pop'), - (r'}', Punctuation, '#pop:2'), + (r'\}', Punctuation, '#pop:2'), include('root'), ], 'object_assert': [ @@ -172,7 +172,7 @@ class JsonnetLexer(RegexLexer): 'object_local_value': [ (r'=', Operator), (r',', Punctuation, '#pop'), - (r'}', Punctuation, '#pop:2'), + (r'\}', Punctuation, '#pop:2'), include('root'), ], }