Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lexer for VHS #690

Merged
merged 2 commits into from Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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
Expand Down
48 changes: 48 additions & 0 deletions lexers/embedded/vhs.xml
@@ -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 changes: 19 additions & 0 deletions lexers/testdata/vhs.actual
@@ -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 changes: 54 additions & 0 deletions lexers/testdata/vhs.expected
@@ -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"}
]