Skip to content

Commit

Permalink
Fix Wollok lexer: entity list is shared between lexer instances
Browse files Browse the repository at this point in the history
  • Loading branch information
nsfisis committed May 31, 2023
1 parent b9cb3dd commit 0b572a5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/rouge/lexers/wollok.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ class Wollok < RegexLexer
entity_name = /[a-zA-Z][a-zA-Z0-9]*/
variable_naming = /_?#{entity_name}/

entities = []

state :whitespaces_and_comments do
rule %r/\s+/m, Text::Whitespace
rule %r(//.*$), Comment::Single
Expand Down Expand Up @@ -98,6 +96,12 @@ def any(expressions)
rule %r/\(|\)|=/, Text
rule %r/,/, Punctuation
end

private

def entities
@entities ||= []
end
end
end
end
17 changes: 17 additions & 0 deletions spec/lexers/wollok_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,21 @@
assert_guess :filename => 'foo.wpgm'
end
end

describe 'lexing' do
it 'does not share entity list between instances' do
a = Rouge::Lexers::Wollok.new
b = Rouge::Lexers::Wollok.new

# If "foo" is defined as object, it is recognized as Name.Class.
result_a1 = a.lex('object foo {}').to_a
assert_equal result_a1[2].first, Token['Name.Class']
result_a2 = a.lex('foo.bar()').to_a
assert_equal result_a2[0].first, Token['Name.Class']

# If "foo" is undefined, it is recognized as Keyword.Variable.
result_b1 = b.lex('foo.bar()').to_a
assert_equal result_b1[0].first, Token['Keyword.Variable']
end
end
end

0 comments on commit 0b572a5

Please sign in to comment.