summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKornelius Kalnbach <murphy@rubychan.de>2016-02-14 15:08:30 +0100
committerKornelius Kalnbach <murphy@rubychan.de>2016-02-14 15:08:30 +0100
commit13ac3fdc6fa5330c9eacc6ac9be92a869ab8d3be (patch)
tree0cf34739e36f452fa9086455d052589d3ce075e6 /lib
parentf8cadd9fce43c48ed4b32685f62e99f8770b8963 (diff)
downloadcoderay-13ac3fdc6fa5330c9eacc6ac9be92a869ab8d3be.tar.gz
optional push state (return nil)
Diffstat (limited to 'lib')
-rw-r--r--lib/coderay/rule_based_scanner.rb8
-rw-r--r--lib/coderay/scanners/lua2.rb10
2 files changed, 10 insertions, 8 deletions
diff --git a/lib/coderay/rule_based_scanner.rb b/lib/coderay/rule_based_scanner.rb
index 35adad1..334c08c 100644
--- a/lib/coderay/rule_based_scanner.rb
+++ b/lib/coderay/rule_based_scanner.rb
@@ -120,15 +120,19 @@ module CodeRay
raise
@code << " p 'push %p' % [#{action.state}]\n" if $DEBUG
@code << " state = #{action.state}\n"
+ @code << " states << state\n"
when Symbol
@code << " p 'push %p' % [#{action.state.inspect}]\n" if $DEBUG
@code << " state = #{action.state.inspect}\n"
+ @code << " states << state\n"
when Proc
- @code << " state = #{make_callback(action.state)}\n"
+ @code << " if new_state = #{make_callback(action.state)}\n"
+ @code << " state = new_state\n"
+ @code << " states << new_state\n"
+ @code << " end\n"
else
raise "I don't know how to evaluate this push state: %p" % [action.state]
end
- @code << " states << state\n"
if action.is_a? Push
if action.state == action.group
@code << " encoder.begin_group state\n"
diff --git a/lib/coderay/scanners/lua2.rb b/lib/coderay/scanners/lua2.rb
index 4b99a44..8426834 100644
--- a/lib/coderay/scanners/lua2.rb
+++ b/lib/coderay/scanners/lua2.rb
@@ -66,17 +66,15 @@ module Scanners
on %r/::\s*[a-zA-Z_][a-zA-Z0-9_]+\s*::/, :label # ::goto_label::
on %r/_[A-Z]+/, :predefined # _UPPERCASE are names reserved for Lua
on check_if { |brace_depth| brace_depth > 0 }, %r/([a-zA-Z_][a-zA-Z0-9_]*) (\s+)?(=)/x, groups(:key, :space, :operator)
- on %r/[a-zA-Z_][a-zA-Z0-9_]*/, kind { |match| IDENT_KIND[match] }, push_state { |match, kind, state| # Normal letters (or letters followed by digits)
+ on %r/[a-zA-Z_][a-zA-Z0-9_]*/, kind { |match| IDENT_KIND[match] }, push_state { |match, kind| # Normal letters (or letters followed by digits)
# Extra highlighting for entities following certain keywords
if kind == :keyword && match == 'function'
- state = :function_expected
+ :function_expected
elsif kind == :keyword && match == 'goto'
- state = :goto_label_expected
+ :goto_label_expected
elsif kind == :keyword && match == 'local'
- state = :local_var_expected
+ :local_var_expected
end
-
- state
}
on %r/\{/, push(:map), kind { |brace_depth| brace_depth > 0 ? :inline_delimiter : :delimiter }, increment(:brace_depth) # Opening table brace {