1
0
mirror of https://github.com/alecthomas/chroma.git synced 2025-03-17 20:58:08 +02:00
* Add ISC dhcp config lexer

This adds a lexer to parse ISC's dhcpd.conf, https://www.isc.org/dhcp/,
this is EOL, but distributions still carry it.

It has the keywords that I could find and takes some liberty with
LiteralNumber* tokens to return IP, network and MAC addresses.

It may be possible to make this somewhat smaller, but haven't pushed for
that yet.

Signed-off-by: Miek Gieben <miek@miek.nl>

* revert some non-related changes

Signed-off-by: Miek Gieben <miek@miek.nl>

* revert

Signed-off-by: Miek Gieben <miek@miek.nl>

---------

Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
Miek Gieben 2023-03-24 10:58:31 +01:00 committed by GitHub
parent 2672d3c4c3
commit 357f0cbe40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 534 additions and 0 deletions

View File

@ -0,0 +1,112 @@
<lexer>
<config>
<name>ISCdhcpd</name>
<alias>iscdhcpd</alias>
<filename>*.conf</filename>
</config>
<rules>
<state name="interpol">
<rule pattern="\$[{(]">
<token type="LiteralStringInterpol"/>
<push/>
</rule>
<rule pattern="[})]">
<token type="LiteralStringInterpol"/>
<pop depth="1"/>
</rule>
<rule pattern="[^${()}]+">
<token type="LiteralStringInterpol"/>
</rule>
</state>
<state name="arglist">
<rule pattern="\)">
<token type="Punctuation"/>
<pop depth="1"/>
</rule>
<rule pattern=",">
<token type="Punctuation"/>
</rule>
<rule pattern="[\w\-.]+">
<token type="NameVariable"/>
</rule>
<rule pattern="\s+">
<token type="Text"/>
</rule>
</state>
<state name="root">
<rule pattern="#.*?\n">
<token type="Comment"/>
</rule>
<rule pattern="(group|host|subnet|netmask|class|pool)\b">
<token type="KeywordType"/>
</rule>
<rule pattern="(authoritative|domain-name-servers|ethernet|fixed-address|hardware|option|use-host-decl-name|include)\b">
<token type="Keyword"/>
</rule>
<rule pattern="(on|off|true|false)\b">
<token type="KeywordConstant"/>
</rule>
<rule pattern="(if|elsif|else)\b">
<token type="Keyword"/>
</rule>
<rule pattern="(and|or|not)\b">
<token type="OperatorWord"/>
</rule>
<rule pattern="(==|!=|~=|~~|=)">
<token type="Operator"/>
</rule>
<rule pattern="(exists|known|static)\b">
<token type="Keyword"/>
</rule>
<rule pattern="[{},;]">
<token type="Punctuation"/>
</rule>
<rule pattern="\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\/\d{1,2}">
<token type="LiteralNumberFloat"/>
</rule>
<rule pattern="\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}">
<token type="LiteralNumberFloat"/>
</rule>
<rule pattern="[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}">
<token type="LiteralNumberHex"/>
</rule>
<rule pattern="(\w+)(\s+)(\()">
<bygroups>
<token type="NameFunction"/>
<token type="Text"/>
<token type="Punctuation"/>
</bygroups>
<push state="arglist"/>
</rule>
<rule pattern="[\w\-.]+">
<token type="NameVariable"/>
</rule>
<rule pattern="&#34;">
<token type="LiteralString"/>
<push state="doublequotestring"/>
</rule>
<rule pattern="\s+">
<token type="Text"/>
</rule>
</state>
<state name="doublequotestring">
<rule pattern="\$[{(]">
<token type="LiteralStringInterpol"/>
<push state="interpol"/>
</rule>
<rule pattern="\\.">
<token type="LiteralStringEscape"/>
</rule>
<rule pattern="&#34;">
<token type="LiteralString"/>
<pop depth="1"/>
</rule>
<rule pattern="\n">
<token type="LiteralString"/>
</rule>
<rule pattern=".">
<token type="LiteralString"/>
</rule>
</state>
</rules>
</lexer>

77
lexers/testdata/iscdhcpd.actual vendored Normal file
View File

@ -0,0 +1,77 @@
# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#
# Attention: If /etc/ltsp/dhcpd.conf exists, that will be used as
# configuration file instead of this file.
#
# option definitions common to all supported networks...
option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;
default-lease-time 600;
max-lease-time 7200;
ddns-update-style none;
authoritative;
log-facility local7;
# This is a very basic subnet declaration.
subnet 10.254.239.0 netmask 255.255.255.224 {
range 10.254.239.10 10.254.239.20;
option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org;
}
subnet 10.254.239.32 netmask 255.255.255.224 {
range dynamic-bootp 10.254.239.40 10.254.239.60;
option broadcast-address 10.254.239.31;
option routers rtr-239-32-1.example.org;
}
# A slightly different configuration for an internal subnet.
subnet 10.5.5.0 netmask 255.255.255.224 {
range 10.5.5.26 10.5.5.30;
option domain-name-servers ns1.internal.example.org;
option domain-name "internal.example.org";
option subnet-mask 255.255.255.224;
option routers 10.5.5.1;
option broadcast-address 10.5.5.31;
default-lease-time 600;
max-lease-time 7200;
}
host passacaglia {
hardware ethernet 0:0:c0:5d:bd:95;
filename "vmunix.passacaglia";
server-name "toccata.example.com";
}
host fantasia {
hardware ethernet 08:00:07:26:c0:a5;
fixed-address fantasia.example.com;
}
class "foo" {
match if substring (option vendor-class-identifier, 0, 4) = "S\"UNW";
}
shared-network 224-29 {
subnet 10.17.224.0 netmask 255.255.255.0 {
option routers rtr-224.example.org;
}
subnet 10.0.29.0 netmask 255.255.255.0 {
option routers rtr-29.example.org;
}
pool {
allow members of "foo";
range 10.17.224.10 10.17.224.250;
}
pool {
deny members of "foo";
range 10.0.29.10 10.0.29.230;
}
}

345
lexers/testdata/iscdhcpd.expected vendored Normal file
View File

@ -0,0 +1,345 @@
[
{"type":"Comment","value":"# dhcpd.conf\n#\n# Sample configuration file for ISC dhcpd\n#\n# Attention: If /etc/ltsp/dhcpd.conf exists, that will be used as\n# configuration file instead of this file.\n#\n"},
{"type":"Text","value":"\n"},
{"type":"Comment","value":"# option definitions common to all supported networks...\n"},
{"type":"Keyword","value":"option"},
{"type":"Text","value":" "},
{"type":"NameVariable","value":"domain-name"},
{"type":"Text","value":" "},
{"type":"LiteralString","value":"\"example.org\""},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n"},
{"type":"Keyword","value":"option"},
{"type":"Text","value":" "},
{"type":"Keyword","value":"domain-name-servers"},
{"type":"Text","value":" "},
{"type":"NameVariable","value":"ns1.example.org"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"NameVariable","value":"ns2.example.org"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n\n"},
{"type":"NameVariable","value":"default-lease-time"},
{"type":"Text","value":" "},
{"type":"NameVariable","value":"600"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n"},
{"type":"NameVariable","value":"max-lease-time"},
{"type":"Text","value":" "},
{"type":"NameVariable","value":"7200"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n\n"},
{"type":"NameVariable","value":"ddns-update-style"},
{"type":"Text","value":" "},
{"type":"NameVariable","value":"none"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n\n"},
{"type":"Keyword","value":"authoritative"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n\n"},
{"type":"NameVariable","value":"log-facility"},
{"type":"Text","value":" "},
{"type":"NameVariable","value":"local7"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n\n"},
{"type":"Comment","value":"# This is a very basic subnet declaration.\n"},
{"type":"Text","value":"\n"},
{"type":"KeywordType","value":"subnet"},
{"type":"Text","value":" "},
{"type":"LiteralNumberFloat","value":"10.254.239.0"},
{"type":"Text","value":" "},
{"type":"KeywordType","value":"netmask"},
{"type":"Text","value":" "},
{"type":"LiteralNumberFloat","value":"255.255.255.224"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"{"},
{"type":"Text","value":"\n "},
{"type":"NameVariable","value":"range"},
{"type":"Text","value":" "},
{"type":"LiteralNumberFloat","value":"10.254.239.10"},
{"type":"Text","value":" "},
{"type":"LiteralNumberFloat","value":"10.254.239.20"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n "},
{"type":"Keyword","value":"option"},
{"type":"Text","value":" "},
{"type":"NameVariable","value":"routers"},
{"type":"Text","value":" "},
{"type":"NameVariable","value":"rtr-239-0-1.example.org"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"NameVariable","value":"rtr-239-0-2.example.org"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n"},
{"type":"Punctuation","value":"}"},
{"type":"Text","value":"\n\n"},
{"type":"KeywordType","value":"subnet"},
{"type":"Text","value":" "},
{"type":"LiteralNumberFloat","value":"10.254.239.32"},
{"type":"Text","value":" "},
{"type":"KeywordType","value":"netmask"},
{"type":"Text","value":" "},
{"type":"LiteralNumberFloat","value":"255.255.255.224"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"{"},
{"type":"Text","value":"\n "},
{"type":"NameVariable","value":"range"},
{"type":"Text","value":" "},
{"type":"NameVariable","value":"dynamic-bootp"},
{"type":"Text","value":" "},
{"type":"LiteralNumberFloat","value":"10.254.239.40"},
{"type":"Text","value":" "},
{"type":"LiteralNumberFloat","value":"10.254.239.60"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n "},
{"type":"Keyword","value":"option"},
{"type":"Text","value":" "},
{"type":"NameVariable","value":"broadcast-address"},
{"type":"Text","value":" "},
{"type":"LiteralNumberFloat","value":"10.254.239.31"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n "},
{"type":"Keyword","value":"option"},
{"type":"Text","value":" "},
{"type":"NameVariable","value":"routers"},
{"type":"Text","value":" "},
{"type":"NameVariable","value":"rtr-239-32-1.example.org"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n"},
{"type":"Punctuation","value":"}"},
{"type":"Text","value":"\n\n"},
{"type":"Comment","value":"# A slightly different configuration for an internal subnet.\n"},
{"type":"KeywordType","value":"subnet"},
{"type":"Text","value":" "},
{"type":"LiteralNumberFloat","value":"10.5.5.0"},
{"type":"Text","value":" "},
{"type":"KeywordType","value":"netmask"},
{"type":"Text","value":" "},
{"type":"LiteralNumberFloat","value":"255.255.255.224"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"{"},
{"type":"Text","value":"\n "},
{"type":"NameVariable","value":"range"},
{"type":"Text","value":" "},
{"type":"LiteralNumberFloat","value":"10.5.5.26"},
{"type":"Text","value":" "},
{"type":"LiteralNumberFloat","value":"10.5.5.30"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n "},
{"type":"Keyword","value":"option"},
{"type":"Text","value":" "},
{"type":"Keyword","value":"domain-name-servers"},
{"type":"Text","value":" "},
{"type":"NameVariable","value":"ns1.internal.example.org"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n "},
{"type":"Keyword","value":"option"},
{"type":"Text","value":" "},
{"type":"NameVariable","value":"domain-name"},
{"type":"Text","value":" "},
{"type":"LiteralString","value":"\"internal.example.org\""},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n "},
{"type":"Keyword","value":"option"},
{"type":"Text","value":" "},
{"type":"KeywordType","value":"subnet"},
{"type":"NameVariable","value":"-mask"},
{"type":"Text","value":" "},
{"type":"LiteralNumberFloat","value":"255.255.255.224"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n "},
{"type":"Keyword","value":"option"},
{"type":"Text","value":" "},
{"type":"NameVariable","value":"routers"},
{"type":"Text","value":" "},
{"type":"LiteralNumberFloat","value":"10.5.5.1"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n "},
{"type":"Keyword","value":"option"},
{"type":"Text","value":" "},
{"type":"NameVariable","value":"broadcast-address"},
{"type":"Text","value":" "},
{"type":"LiteralNumberFloat","value":"10.5.5.31"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n "},
{"type":"NameVariable","value":"default-lease-time"},
{"type":"Text","value":" "},
{"type":"NameVariable","value":"600"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n "},
{"type":"NameVariable","value":"max-lease-time"},
{"type":"Text","value":" "},
{"type":"NameVariable","value":"7200"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n"},
{"type":"Punctuation","value":"}"},
{"type":"Text","value":"\n\n"},
{"type":"KeywordType","value":"host"},
{"type":"Text","value":" "},
{"type":"NameVariable","value":"passacaglia"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"{"},
{"type":"Text","value":"\n "},
{"type":"Keyword","value":"hardware"},
{"type":"Text","value":" "},
{"type":"Keyword","value":"ethernet"},
{"type":"Text","value":" "},
{"type":"LiteralNumberHex","value":"0:0:c0:5d:bd:95"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n "},
{"type":"NameVariable","value":"filename"},
{"type":"Text","value":" "},
{"type":"LiteralString","value":"\"vmunix.passacaglia\""},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n "},
{"type":"NameVariable","value":"server-name"},
{"type":"Text","value":" "},
{"type":"LiteralString","value":"\"toccata.example.com\""},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n"},
{"type":"Punctuation","value":"}"},
{"type":"Text","value":"\n\n"},
{"type":"KeywordType","value":"host"},
{"type":"Text","value":" "},
{"type":"NameVariable","value":"fantasia"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"{"},
{"type":"Text","value":"\n "},
{"type":"Keyword","value":"hardware"},
{"type":"Text","value":" "},
{"type":"Keyword","value":"ethernet"},
{"type":"Text","value":" "},
{"type":"LiteralNumberHex","value":"08:00:07:26:c0:a5"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n "},
{"type":"Keyword","value":"fixed-address"},
{"type":"Text","value":" "},
{"type":"NameVariable","value":"fantasia.example.com"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n"},
{"type":"Punctuation","value":"}"},
{"type":"Text","value":"\n\n"},
{"type":"KeywordType","value":"class"},
{"type":"Text","value":" "},
{"type":"LiteralString","value":"\"foo\""},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"{"},
{"type":"Text","value":"\n "},
{"type":"NameVariable","value":"match"},
{"type":"Text","value":" "},
{"type":"Keyword","value":"if"},
{"type":"Text","value":" "},
{"type":"NameFunction","value":"substring"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"("},
{"type":"NameVariable","value":"option"},
{"type":"Text","value":" "},
{"type":"NameVariable","value":"vendor-class-identifier"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"NameVariable","value":"0"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"NameVariable","value":"4"},
{"type":"Punctuation","value":")"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"LiteralString","value":"\"S"},
{"type":"LiteralStringEscape","value":"\\\""},
{"type":"LiteralString","value":"UNW\""},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n"},
{"type":"Punctuation","value":"}"},
{"type":"Text","value":"\n\n"},
{"type":"NameVariable","value":"shared-network"},
{"type":"Text","value":" "},
{"type":"NameVariable","value":"224-29"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"{"},
{"type":"Text","value":"\n "},
{"type":"KeywordType","value":"subnet"},
{"type":"Text","value":" "},
{"type":"LiteralNumberFloat","value":"10.17.224.0"},
{"type":"Text","value":" "},
{"type":"KeywordType","value":"netmask"},
{"type":"Text","value":" "},
{"type":"LiteralNumberFloat","value":"255.255.255.0"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"{"},
{"type":"Text","value":"\n "},
{"type":"Keyword","value":"option"},
{"type":"Text","value":" "},
{"type":"NameVariable","value":"routers"},
{"type":"Text","value":" "},
{"type":"NameVariable","value":"rtr-224.example.org"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n "},
{"type":"Punctuation","value":"}"},
{"type":"Text","value":"\n "},
{"type":"KeywordType","value":"subnet"},
{"type":"Text","value":" "},
{"type":"LiteralNumberFloat","value":"10.0.29.0"},
{"type":"Text","value":" "},
{"type":"KeywordType","value":"netmask"},
{"type":"Text","value":" "},
{"type":"LiteralNumberFloat","value":"255.255.255.0"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"{"},
{"type":"Text","value":"\n "},
{"type":"Keyword","value":"option"},
{"type":"Text","value":" "},
{"type":"NameVariable","value":"routers"},
{"type":"Text","value":" "},
{"type":"NameVariable","value":"rtr-29.example.org"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n "},
{"type":"Punctuation","value":"}"},
{"type":"Text","value":"\n "},
{"type":"KeywordType","value":"pool"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"{"},
{"type":"Text","value":"\n "},
{"type":"NameVariable","value":"allow"},
{"type":"Text","value":" "},
{"type":"NameVariable","value":"members"},
{"type":"Text","value":" "},
{"type":"NameVariable","value":"of"},
{"type":"Text","value":" "},
{"type":"LiteralString","value":"\"foo\""},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n "},
{"type":"NameVariable","value":"range"},
{"type":"Text","value":" "},
{"type":"LiteralNumberFloat","value":"10.17.224.10"},
{"type":"Text","value":" "},
{"type":"LiteralNumberFloat","value":"10.17.224.250"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n "},
{"type":"Punctuation","value":"}"},
{"type":"Text","value":"\n "},
{"type":"KeywordType","value":"pool"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"{"},
{"type":"Text","value":"\n "},
{"type":"NameVariable","value":"deny"},
{"type":"Text","value":" "},
{"type":"NameVariable","value":"members"},
{"type":"Text","value":" "},
{"type":"NameVariable","value":"of"},
{"type":"Text","value":" "},
{"type":"LiteralString","value":"\"foo\""},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n "},
{"type":"NameVariable","value":"range"},
{"type":"Text","value":" "},
{"type":"LiteralNumberFloat","value":"10.0.29.10"},
{"type":"Text","value":" "},
{"type":"LiteralNumberFloat","value":"10.0.29.230"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n "},
{"type":"Punctuation","value":"}"},
{"type":"Text","value":"\n"},
{"type":"Punctuation","value":"}"},
{"type":"Text","value":"\n"}
]