generated from cotes2020/chirpy-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FromNand2Tetris: Try using a custom HDL lexer.
- Loading branch information
1 parent
bea6033
commit b1c4b74
Showing
3 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -225,3 +225,6 @@ jekyll-archives: | |
permalinks: | ||
tag: /tags/:name/ | ||
category: /categories/:name/ | ||
|
||
plugins: | ||
- rouge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
module Rouge | ||
module Lexers | ||
class HDLCustom < RegexLexer | ||
tag 'hdlcustom' | ||
filenames '*.hdl' | ||
mimetypes 'text/x-hdl' | ||
|
||
# Keywords | ||
keywords = %w( | ||
CHIP IN OUT BUILTIN PARTS | ||
) | ||
|
||
# Built-in gates | ||
builtins = %w( | ||
Nand And Or Not Xor Mux DMux | ||
Add16 Inc16 ALU Register RAM8 RAM64 | ||
) | ||
|
||
# Pin directions and types | ||
pins = %w(in out) | ||
|
||
state :root do | ||
rule %r(//.*), Comment::Single | ||
rule %r(/\*), Comment::Multiline, :comment | ||
rule %r/\b(#{keywords.join('|')})\b/, Keyword | ||
rule %r/\b(#{builtins.join('|')})\b/, Name::Builtin | ||
rule %r/\b(#{pins.join('|')})\b/, Keyword::Pseudo | ||
rule %r/[a-zA-Z_]\w*/, Name::Variable | ||
rule %r/\d+/, Num | ||
rule %r/[\[\]\(\)\{\},;=]/, Punctuation | ||
rule %r/\s+/, Text::Whitespace | ||
end | ||
|
||
state :comment do | ||
rule %r/\*\//, Comment::Multiline, :pop! | ||
rule %r/[^\*]+/, Comment::Multiline | ||
rule %r/\*/, Comment::Multiline | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters