From c2e2eab35ac78aebb3d8ec62851720aba8e0abee Mon Sep 17 00:00:00 2001 From: Andrey Konovalov Date: Sat, 19 Feb 2022 20:34:31 +0100 Subject: [PATCH] Highlight shortened lists for syzlang DSL 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 --- lib/rouge/lexers/syzlang.rb | 2 ++ spec/lexers/syzlang_spec.rb | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/lib/rouge/lexers/syzlang.rb b/lib/rouge/lexers/syzlang.rb index 9ddebd7ca2..f203e828c9 100644 --- a/lib/rouge/lexers/syzlang.rb +++ b/lib/rouge/lexers/syzlang.rb @@ -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 @@ -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 diff --git a/spec/lexers/syzlang_spec.rb b/spec/lexers/syzlang_spec.rb index 99b22e23a9..c267fb1c8a 100644 --- a/spec/lexers/syzlang_spec.rb +++ b/spec/lexers/syzlang_spec.rb @@ -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