Skip to content

Commit

Permalink
Highlight shortened lists for syzlang DSL (rouge-ruby#1808)
Browse files Browse the repository at this point in the history
Update the lexer for syzlang DSL to allow processing inputs with lists and
syscall arguments replaced with "...". This is useful for highlighting snippets
that are shortened for readability.

Also add tests for the new behavior.

Signed-off-by: Andrey Konovalov <[email protected]>
  • Loading branch information
xairy authored and razetime committed Jun 30, 2022
1 parent 34d1142 commit c539158
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/rouge/lexers/syzlang.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def self.keywords_type

state :flags_list do
rule inline_spaces, Text
rule %r/\./, Punctuation
mixin :mixin_name
mixin :mixin_number
mixin :mixin_string
Expand All @@ -158,6 +159,7 @@ def self.keywords_type
state :syscall_args do
rule spaces, Text
rule comment, Comment
rule %r/\./, Punctuation
rule id do
token Name
push :arg_type
Expand Down
25 changes: 25 additions & 0 deletions spec/lexers/syzlang_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,31 @@
['Keyword.Type', 'int16']
end

# The tests below check that the lexer can process inputs with lists and
# syscall arguments replaced with "...". This is useful for highlighting
# syzlang snippets that are shortened for readability.

it 'recognizes shortened flags lists' do
assert_tokens_equal "flags = FLAG1, FLAG2, ...",
['Name', 'flags'],
['Text', ' '],
['Punctuation', '='],
['Text', ' '],
['Name', 'FLAG1'],
['Punctuation', ','],
['Text', ' '],
['Name', 'FLAG2'],
['Punctuation', ','],
['Text', ' '],
['Punctuation', '...']
end

it 'recognizes shortened syscalls' do
assert_tokens_equal 'foo(...)',
['Name.Function', 'foo'],
['Punctuation', '(...)']
end

# The tests below check that the lexer can process inputs with relaxed
# whitespace usage and after-line comments. This is useful for highlighting
# syzlang snippets that are split into multiple lines for readability and
Expand Down

0 comments on commit c539158

Please sign in to comment.