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

Fix Wollok lexer: entity list is shared between lexer instances #1954

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