mirror of
https://github.com/alecthomas/chroma.git
synced 2025-03-17 20:58:08 +02:00
CFEngine 3: Added syntax highlighting for macros, promise keyword, and different string literals (#604)
The new promise keyword is used in the same places as bundle and body, to declare new promise types in CFEngine 3. See, for example:f126ede5e6/libpromises/cf3parse.y (L44-L57)
f126ede5e6/libpromises/cf3lex.l (L102-L106)
CFEngine 3 supports 3 symbols for string literals: single quotation marks, double quotation marks, and backticks (grave accent). See: https://docs.cfengine.com/docs/3.18/reference-language-concepts-variables.html#quoting
This commit is contained in:
parent
d9c7dea1e6
commit
4bc1957345
@ -38,6 +38,9 @@
|
||||
<rule pattern="#.*?\n">
|
||||
<token type="Comment"/>
|
||||
</rule>
|
||||
<rule pattern="@.*?\n">
|
||||
<token type="CommentPreproc"/>
|
||||
</rule>
|
||||
<rule pattern="(body)(\s+)(\S+)(\s+)(control)">
|
||||
<bygroups>
|
||||
<token type="Keyword"/>
|
||||
@ -47,7 +50,7 @@
|
||||
<token type="Keyword"/>
|
||||
</bygroups>
|
||||
</rule>
|
||||
<rule pattern="(body|bundle)(\s+)(\S+)(\s+)(\w+)(\()">
|
||||
<rule pattern="(body|bundle|promise)(\s+)(\S+)(\s+)(\w+)(\()">
|
||||
<bygroups>
|
||||
<token type="Keyword"/>
|
||||
<token type="Text"/>
|
||||
@ -58,7 +61,7 @@
|
||||
</bygroups>
|
||||
<push state="arglist"/>
|
||||
</rule>
|
||||
<rule pattern="(body|bundle)(\s+)(\S+)(\s+)(\w+)">
|
||||
<rule pattern="(body|bundle|promise)(\s+)(\S+)(\s+)(\w+)">
|
||||
<bygroups>
|
||||
<token type="Keyword"/>
|
||||
<token type="Text"/>
|
||||
@ -89,7 +92,15 @@
|
||||
</rule>
|
||||
<rule pattern=""">
|
||||
<token type="LiteralString"/>
|
||||
<push state="string"/>
|
||||
<push state="doublequotestring"/>
|
||||
</rule>
|
||||
<rule pattern="'">
|
||||
<token type="LiteralString"/>
|
||||
<push state="singlequotestring"/>
|
||||
</rule>
|
||||
<rule pattern="`">
|
||||
<token type="LiteralString"/>
|
||||
<push state="backtickstring"/>
|
||||
</rule>
|
||||
<rule pattern="(\w+)(\()">
|
||||
<bygroups>
|
||||
@ -134,7 +145,7 @@
|
||||
<token type="Text"/>
|
||||
</rule>
|
||||
</state>
|
||||
<state name="string">
|
||||
<state name="doublequotestring">
|
||||
<rule pattern="\$[{(]">
|
||||
<token type="LiteralStringInterpol"/>
|
||||
<push state="interpol"/>
|
||||
@ -153,5 +164,43 @@
|
||||
<token type="LiteralString"/>
|
||||
</rule>
|
||||
</state>
|
||||
<state name="singlequotestring">
|
||||
<rule pattern="\$[{(]">
|
||||
<token type="LiteralStringInterpol"/>
|
||||
<push state="interpol"/>
|
||||
</rule>
|
||||
<rule pattern="\\.">
|
||||
<token type="LiteralStringEscape"/>
|
||||
</rule>
|
||||
<rule pattern="'">
|
||||
<token type="LiteralString"/>
|
||||
<pop depth="1"/>
|
||||
</rule>
|
||||
<rule pattern="\n">
|
||||
<token type="LiteralString"/>
|
||||
</rule>
|
||||
<rule pattern=".">
|
||||
<token type="LiteralString"/>
|
||||
</rule>
|
||||
</state>
|
||||
<state name="backtickstring">
|
||||
<rule pattern="\$[{(]">
|
||||
<token type="LiteralStringInterpol"/>
|
||||
<push state="interpol"/>
|
||||
</rule>
|
||||
<rule pattern="\\.">
|
||||
<token type="LiteralStringEscape"/>
|
||||
</rule>
|
||||
<rule pattern="`">
|
||||
<token type="LiteralString"/>
|
||||
<pop depth="1"/>
|
||||
</rule>
|
||||
<rule pattern="\n">
|
||||
<token type="LiteralString"/>
|
||||
</rule>
|
||||
<rule pattern=".">
|
||||
<token type="LiteralString"/>
|
||||
</rule>
|
||||
</state>
|
||||
</rules>
|
||||
</lexer>
|
||||
</lexer>
|
||||
|
27
lexers/testdata/cfengine3.actual
vendored
Normal file
27
lexers/testdata/cfengine3.actual
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
@if minimum_version(3.20)
|
||||
body members foo
|
||||
{
|
||||
include => { "alice", "bob" };
|
||||
exclude => { "malcom" };
|
||||
}
|
||||
@endif
|
||||
|
||||
@if minimum_version(3.20)
|
||||
promise agent blah
|
||||
{
|
||||
path => "/some/path";
|
||||
}
|
||||
@endif
|
||||
|
||||
bundle agent __main__
|
||||
{
|
||||
groups:
|
||||
"foo"
|
||||
policy => "present",
|
||||
@if minimum_version(3.20)
|
||||
members => foo;
|
||||
@else
|
||||
members => '{ "include": ["alice", "bob"],
|
||||
"exclude": ["malcom"] }';
|
||||
@endif
|
||||
}
|
99
lexers/testdata/cfengine3.expected
vendored
Normal file
99
lexers/testdata/cfengine3.expected
vendored
Normal file
@ -0,0 +1,99 @@
|
||||
[
|
||||
{"type":"CommentPreproc","value":"@if minimum_version(3.20)\n"},
|
||||
{"type":"Keyword","value":"body"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Keyword","value":"members"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"NameFunction","value":"foo"},
|
||||
{"type":"Text","value":"\n"},
|
||||
{"type":"Punctuation","value":"{"},
|
||||
{"type":"Text","value":"\n "},
|
||||
{"type":"KeywordReserved","value":"include"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Operator","value":"=\u003e"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Punctuation","value":"{"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"LiteralString","value":"\"alice\""},
|
||||
{"type":"Punctuation","value":","},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"LiteralString","value":"\"bob\""},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Punctuation","value":"};"},
|
||||
{"type":"Text","value":"\n "},
|
||||
{"type":"KeywordReserved","value":"exclude"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Operator","value":"=\u003e"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Punctuation","value":"{"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"LiteralString","value":"\"malcom\""},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Punctuation","value":"};"},
|
||||
{"type":"Text","value":"\n"},
|
||||
{"type":"Punctuation","value":"}"},
|
||||
{"type":"Text","value":"\n"},
|
||||
{"type":"CommentPreproc","value":"@endif\n"},
|
||||
{"type":"Text","value":"\n"},
|
||||
{"type":"CommentPreproc","value":"@if minimum_version(3.20)\n"},
|
||||
{"type":"Keyword","value":"promise"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Keyword","value":"agent"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"NameFunction","value":"blah"},
|
||||
{"type":"Text","value":"\n"},
|
||||
{"type":"Punctuation","value":"{"},
|
||||
{"type":"Text","value":"\n "},
|
||||
{"type":"KeywordReserved","value":"path"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Operator","value":"=\u003e"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"LiteralString","value":"\"/some/path\""},
|
||||
{"type":"Punctuation","value":";"},
|
||||
{"type":"Text","value":"\n"},
|
||||
{"type":"Punctuation","value":"}"},
|
||||
{"type":"Text","value":"\n"},
|
||||
{"type":"CommentPreproc","value":"@endif\n"},
|
||||
{"type":"Text","value":"\n"},
|
||||
{"type":"Keyword","value":"bundle"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Keyword","value":"agent"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"NameFunction","value":"__main__"},
|
||||
{"type":"Text","value":"\n"},
|
||||
{"type":"Punctuation","value":"{"},
|
||||
{"type":"Text","value":"\n "},
|
||||
{"type":"KeywordDeclaration","value":"groups"},
|
||||
{"type":"Punctuation","value":":"},
|
||||
{"type":"Text","value":"\n "},
|
||||
{"type":"LiteralString","value":"\"foo\""},
|
||||
{"type":"Text","value":"\n "},
|
||||
{"type":"KeywordReserved","value":"policy"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Operator","value":"=\u003e"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"LiteralString","value":"\"present\""},
|
||||
{"type":"Punctuation","value":","},
|
||||
{"type":"Text","value":"\n"},
|
||||
{"type":"CommentPreproc","value":"@if minimum_version(3.20)\n"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"KeywordReserved","value":"members"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Operator","value":"=\u003e"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"NameFunction","value":"foo"},
|
||||
{"type":"Punctuation","value":";"},
|
||||
{"type":"Text","value":"\n"},
|
||||
{"type":"CommentPreproc","value":"@else\n"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"KeywordReserved","value":"members"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Operator","value":"=\u003e"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"LiteralString","value":"'{ \"include\": [\"alice\", \"bob\"],\n \"exclude\": [\"malcom\"] }'"},
|
||||
{"type":"Punctuation","value":";"},
|
||||
{"type":"Text","value":"\n"},
|
||||
{"type":"CommentPreproc","value":"@endif\n"},
|
||||
{"type":"Punctuation","value":"}"},
|
||||
{"type":"Text","value":"\n"}
|
||||
]
|
Loading…
x
Reference in New Issue
Block a user