10000 Lua scanner, tweaked (finally!) by korny · Pull Request #141 · rubychan/coderay · GitHub
[go: up one dir, main page]

Skip to content

Lua scanner, tweaked (finally!) #141

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

Merged
merged 21 commits into from
Jun 22, 2013
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
:map token kind
Use :map instead of :table. It's more generic, and won't be confused with the :table rendering style.
  • Loading branch information
nathany committed Oct 28, 2012
commit 279348d3c2159df4ce6ac5949ada0177aa7c7159
14 changes: 7 additions & 7 deletions lib/coderay/scanners/lua.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ def scan_tokens(encoder, options)
@encoder.text_token(match, kind)

elsif match = scan(/\{/) # Opening table brace {
@encoder.begin_group(:table)
@encoder.begin_group(:map)
@encoder.text_token(match, @brace_depth >= 1 ? :inline_delimiter : :delimiter)
@brace_depth += 1
@state = :table
@state = :map

elsif match = scan(/\}/) # Closing table brace }
if @brace_depth == 1
Expand All @@ -112,9 +112,9 @@ def scan_tokens(encoder, options)
else
@brace_depth -= 1
@encoder.text_token(match, :inline_delimiter)
@state = :table
@state = :map
end
@encoder.end_group(:table)
@encoder.end_group(:map)

elsif match = scan(/["']/) # String delimiters " and '
@encoder.begin_group(:string)
Expand Down Expand Up @@ -142,8 +142,8 @@ def scan_tokens(encoder, options)

# It may be that we’re scanning a full-blown subexpression of a table
# (tables can contain full expressions in parts).
# If this is the case, return to :table scanning state.
@state = :table if @state == :initial && @brace_depth >= 1
# If this is the case, return to :map scanning state.
@state = :map if @state == :initial && @brace_depth >= 1

when :function_expected
if match = scan(/\(.*?\)/m) # x = function() # "Anonymous" function without explicit name
Expand Down Expand Up @@ -237,7 +237,7 @@ def scan_tokens(encoder, options)
@encoder.text_token(getch, :error)
end

when :table
when :map
if match = scan(/[,;]/)
@encoder.text_token(match, :operator)
elsif match = scan(/[a-zA-Z_][a-zA-Z0-9_]* (?=\s*=)/x)
Expand Down
8 changes: 4 additions & 4 deletions lib/coderay/styles/alpha.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module CodeRay
module Styles

# A colorful theme using CSS 3 colors (with alpha channel).
class Alpha < Style

Expand Down Expand Up @@ -116,9 +116,9 @@ class Alpha < Style
.symbol .content { color:#A60 }
.symbol .delimiter { color:#630 }
.symbol { color:#A60 }
.table .content { color:#808 }
.table .delimiter { color:#40A}
.table { background-color:hsla(200,100%,50%,0.06); }
.map .content { color:#808 }
.map .delimiter { color:#40A}
.map { background-color:hsla(200,100%,50%,0.06); }
.tag { color:#070 }
.type { color:#339; font-weight:bold }
.value { color: #088; }
Expand Down
20 changes: 10 additions & 10 deletions lib/coderay/token_kinds.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module CodeRay

# A Hash of all known token kinds and their associated CSS classes.
TokenKinds = Hash.new do |h, k|
warn 'Undefined Token kind: %p' % [k] if $CODERAY_DEBUG
false
end

# speedup
TokenKinds.compare_by_identity if TokenKinds.respond_to? :compare_by_identity

TokenKinds.update( # :nodoc:
:annotation => 'annotation',
:attribute_name => 'attribute-name',
Expand Down Expand Up @@ -50,6 +50,7 @@ module CodeRay
:keyword => 'keyword',
:label => 'label',
:local_variable => 'local-variable',
:map => 'map',
:modifier => 'modifier',
:namespace => 'namespace',
:octal => 'octal',
Expand All @@ -63,29 +64,28 @@ module CodeRay
:shell => 'shell',
:string => 'string',
:symbol => 'symbol',
:table => 'table',
:tag => 'tag',
:type => 'type',
:value => 'value',
:variable => 'variable',

:change => 'change',
:delete => 'delete',
:head => 'head',
:insert => 'insert',

:eyecatcher => 'eyecatcher',

:ident => false,
:operator => false,

:space => false,
:plain => false
)

TokenKinds[:method] = TokenKinds[:function]
TokenKinds[:escape] = TokenKinds[:delimiter]
TokenKinds[:docstring] = TokenKinds[:comment]

TokenKinds.freeze
end
0