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

Highlight shortened lists for syzlang DSL #1808

Merged
merged 1 commit into from
Feb 24, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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