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

Lexer for VHS (#690)

This commit is contained in:
Maas Lalani 2022-10-28 17:52:43 -04:00 committed by GitHub
parent 06f7007f02
commit f0bac8cfd0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 122 additions and 1 deletions

View File

@ -56,7 +56,7 @@ Q | QBasic
R | R, Racket, Ragel, Raku, react, ReasonML, reg, reStructuredText, Rexx, Ruby, Rust
S | SAS, Sass, Scala, Scheme, Scilab, SCSS, Sed, Smalltalk, Smarty, Snobol, Solidity, SPARQL, SQL, SquidConf, Standard ML, Stylus, Svelte, Swift, SYSTEMD, systemverilog
T | TableGen, TASM, Tcl, Tcsh, Termcap, Terminfo, Terraform, TeX, Thrift, TOML, TradingView, Transact-SQL, Turing, Turtle, Twig, TypeScript, TypoScript, TypoScriptCssData, TypoScriptHtmlData
V | VB.net, verilog, VHDL, VimL, vue
V | VB.net, verilog, VHDL, VHS, VimL, vue
W | WDTE
X | XML, Xorg
Y | YAML, YANG

48
lexers/embedded/vhs.xml Normal file
View File

@ -0,0 +1,48 @@
<lexer>
<config>
<name>VHS</name>
<alias>vhs</alias>
<alias>tape</alias>
<alias>cassette</alias>
<filename>*.tape</filename>
</config>
<rules>
<state name="root">
<rule pattern="(Output)(\s+)(.*)(\s+)">
<bygroups>
<token type="Keyword"/>
<token type="TextWhitespace"/>
<token type="LiteralString"/>
<token type="TextWhitespace"/>
</bygroups>
</rule>
<rule pattern="\b(Set|Type|Left|Right|Up|Down|Backspace|Enter|Tab|Space|Ctrl|Sleep|Hide|Show|Escape)\b">
<token type="Keyword"/>
</rule>
<rule pattern="\b(FontFamily|FontSize|Framerate|Height|Width|Theme|Padding|TypingSpeed|PlaybackSpeed|LineHeight|Framerate|LetterSpacing)\b">
<token type="NameBuiltin"/>
</rule>
<rule pattern="#.*(\S|$)">
<token type="Comment"/>
</rule>
<rule pattern="(?s)&#34;.*&#34;">
<token type="LiteralStringDouble"/>
</rule>
<rule pattern="(?s)&#39;.*&#39;">
<token type="LiteralStringSingle"/>
</rule>
<rule pattern="(@|\+)">
<token type="Punctuation"/>
</rule>
<rule pattern="\d+">
<token type="LiteralNumber"/>
</rule>
<rule pattern="\s+">
<token type="TextWhitespace"/>
</rule>
<rule pattern="(ms|s)">
<token type="Text"/>
</rule>
</state>
</rules>
</lexer>

19
lexers/testdata/vhs.actual vendored Normal file
View File

@ -0,0 +1,19 @@
# Where should we write the GIF?
Output demo.gif
# Set up a 1200x600 terminal with 46px font.
Set FontSize 46
Set Width 1200
Set Height 600
# Type a command in the terminal.
Type@100ms "echo 'Welcome to VHS!'"
# Pause for dramatic effect...
Sleep 500ms
# Run the command by pressing enter.
Enter
# Admire the output for a bit.
Sleep 5s

54
lexers/testdata/vhs.expected vendored Normal file
View File

@ -0,0 +1,54 @@
[
{"type":"Comment","value":"# Where should we write the GIF?"},
{"type":"TextWhitespace","value":"\n"},
{"type":"Keyword","value":"Output"},
{"type":"TextWhitespace","value":" "},
{"type":"LiteralString","value":"demo.gif"},
{"type":"TextWhitespace","value":"\n\n"},
{"type":"Comment","value":"# Set up a 1200x600 terminal with 46px font."},
{"type":"TextWhitespace","value":"\n"},
{"type":"Keyword","value":"Set"},
{"type":"TextWhitespace","value":" "},
{"type":"NameBuiltin","value":"FontSize"},
{"type":"TextWhitespace","value":" "},
{"type":"LiteralNumber","value":"46"},
{"type":"TextWhitespace","value":"\n"},
{"type":"Keyword","value":"Set"},
{"type":"TextWhitespace","value":" "},
{"type":"NameBuiltin","value":"Width"},
{"type":"TextWhitespace","value":" "},
{"type":"LiteralNumber","value":"1200"},
{"type":"TextWhitespace","value":"\n"},
{"type":"Keyword","value":"Set"},
{"type":"TextWhitespace","value":" "},
{"type":"NameBuiltin","value":"Height"},
{"type":"TextWhitespace","value":" "},
{"type":"LiteralNumber","value":"600"},
{"type":"TextWhitespace","value":"\n\n"},
{"type":"Comment","value":"# Type a command in the terminal."},
{"type":"TextWhitespace","value":"\n"},
{"type":"Keyword","value":"Type"},
{"type":"Punctuation", "value": "@"},
{"type":"LiteralNumber", "value": "100"},
{"type":"Text", "value": "ms"},
{"type":"TextWhitespace","value":" "},
{"type":"LiteralStringDouble","value":"\"echo 'Welcome to VHS!'\""},
{"type":"TextWhitespace","value":"\n\n"},
{"type":"Comment","value":"# Pause for dramatic effect..."},
{"type":"TextWhitespace","value":"\n"},
{"type":"Keyword","value":"Sleep"},
{"type":"TextWhitespace","value":" "},
{"type":"LiteralNumber","value":"500"},
{"type":"Text","value":"ms"},
{"type":"TextWhitespace","value":"\n\n"},
{"type":"Comment","value":"# Run the command by pressing enter."},
{"type":"TextWhitespace","value":"\n"},
{"type":"Keyword","value":"Enter"},
{"type":"TextWhitespace","value":"\n\n"},
{"type":"Comment","value":"# Admire the output for a bit."},
{"type":"TextWhitespace","value":"\n"},
{"type":"Keyword","value":"Sleep"},
{"type":"TextWhitespace","value":" "},
{"type":"LiteralNumber","value":"5"},
{"type":"Text","value":"s"}
]