From 56e49328fbadab7ead27c8b5b905afc2f47a860e Mon Sep 17 00:00:00 2001 From: Roberto Alsina Date: Tue, 13 Aug 2024 21:00:00 -0300 Subject: [PATCH 1/4] Tiny bug --- src/rules.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rules.cr b/src/rules.cr index 1f4a7eb..a7dc872 100644 --- a/src/rules.cr +++ b/src/rules.cr @@ -19,7 +19,7 @@ module Tartrazine match = pattern.match(text, pos) # We don't match if the match doesn't move the cursor # because that causes infinite loops - return false, pos, [] of Token if match.nil? || match.end == 0 + return false, pos, [] of Token if match.nil? || match.size == 0 # Log.trace { "#{match}, #{pattern.inspect}, #{text}, #{pos}" } tokens = [] of Token # Emit the tokens From c898f395a101c3270f9c12baf5350bdcc12df942 Mon Sep 17 00:00:00 2001 From: Roberto Alsina Date: Tue, 13 Aug 2024 22:06:07 -0300 Subject: [PATCH 2/4] reset stack on EOL instead of error, makes no difference, but it's in pygments version --- src/lexer.cr | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/lexer.cr b/src/lexer.cr index 63e5b7d..a22cecb 100644 --- a/src/lexer.cr +++ b/src/lexer.cr @@ -94,8 +94,13 @@ module Tartrazine end # If no rule matches, emit an error token unless matched - # Log.trace { "Error at #{pos}" } - tokens << {type: "Error", value: "#{text[pos]}"} + if text[pos] == "\n" + # at EOL, reset state to "root" + tokens << {type: "TextWhitespace", value: "\n"} + @state_stack = ["root"] + else + tokens << {type: "Error", value: text[pos..pos]} + end pos += 1 end end From 5218af68553822e49465f88c4214b6cd97437b0e Mon Sep 17 00:00:00 2001 From: Roberto Alsina Date: Tue, 13 Aug 2024 22:06:19 -0300 Subject: [PATCH 3/4] lint --- src/formatters/html.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/formatters/html.cr b/src/formatters/html.cr index 7b4be85..1c8a245 100644 --- a/src/formatters/html.cr +++ b/src/formatters/html.cr @@ -30,7 +30,7 @@ module Tartrazine @standalone : Bool = false, @surrounding_pre : Bool = true, @wrap_long_lines : Bool = false, - @weight_of_bold : Int32 = 600,) + @weight_of_bold : Int32 = 600) end def format(text : String, lexer : Lexer) : String From 6f64b76c44eaf33601e39b879603e4474361c8d1 Mon Sep 17 00:00:00 2001 From: Roberto Alsina Date: Tue, 13 Aug 2024 22:07:23 -0300 Subject: [PATCH 4/4] lint --- spec/tartrazine_spec.cr | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/tartrazine_spec.cr b/spec/tartrazine_spec.cr index 4615a25..4a06dc2 100644 --- a/spec/tartrazine_spec.cr +++ b/spec/tartrazine_spec.cr @@ -42,7 +42,6 @@ known_bad = { "#{__DIR__}/tests/mcfunction/selectors.txt", "#{__DIR__}/tests/php/anonymous_class.txt", "#{__DIR__}/tests/html/javascript_unclosed.txt", - } # Tests that fail because of a limitation in PCRE2