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

Coerce state names into symbols instead of strings #1138

Merged
merged 1 commit into from
May 31, 2019
Merged
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
14 changes: 7 additions & 7 deletions lib/rouge/regex_lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,18 +183,18 @@ def self.start(&b)
# Define a new state for this lexer with the given name.
# The block will be evaluated in the context of a {StateDSL}.
def self.state(name, &b)
name = name.to_s
name = name.to_sym
state_definitions[name] = StateDSL.new(name, &b)
end

def self.prepend(name, &b)
name = name.to_s
name = name.to_sym
dsl = state_definitions[name] or raise "no such state #{name.inspect}"
replace_state(name, dsl.prepended(&b))
end

def self.append(name, &b)
name = name.to_s
name = name.to_sym
dsl = state_definitions[name] or raise "no such state #{name.inspect}"
replace_state(name, dsl.appended(&b))
end
Expand All @@ -204,7 +204,7 @@ def self.get_state(name)
return name if name.is_a? State

states[name.to_sym] ||= begin
defn = state_definitions[name.to_s] or raise "unknown state: #{name.inspect}"
defn = state_definitions[name.to_sym] or raise "unknown state: #{name.inspect}"
defn.to_state(self)
end
end
Expand Down Expand Up @@ -421,15 +421,15 @@ def reset_stack

# Check if `state_name` is in the state stack.
def in_state?(state_name)
state_name = state_name.to_s
state_name = state_name.to_sym
stack.any? do |state|
state.name == state_name.to_s
state.name == state_name.to_sym
end
end

# Check if `state_name` is the state on top of the state stack.
def state?(state_name)
state_name.to_s == state.name
state_name.to_sym == state.name
end

private
Expand Down