Skip to content

Commit f1b86cf

Browse files
committed
fix math operators and reorder regex
1 parent cf25d44 commit f1b86cf

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

lib/coderay/scanners/liquid.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ class Liquid < Scanner
55

66
register_for :liquid
77

8-
DIRECTIVE_KEYWORDS = "list|endlist|for|endfor|wrap|endwrap|if|endif|unless|endunless|elsif|assignlist|assign|cycle|capture|end|capture|fill|iflist|endiflist|else"
8+
DIRECTIVE_KEYWORDS = "endlist|list|endfor|for|endwrap|wrap|endif|if|endunless|unless|elsif|assignlist|assign|cycle|capture|end|capture|fill|endiflist|iflist|else"
99

10-
DIRECTIVE_OPERATORS = "=|==|!=|>|<|<=|>=|contains"
10+
DIRECTIVE_OPERATORS = "=|==|!=|>|<|<=|>=|contains|\+"
1111

12-
MATH = "==|=|!=|>|<=|<|>"
12+
MATH = /==|=|!=|>|<=|<|>|\+/
1313

1414
FILTER_KEYWORDS = "date|capitalize|downcase|upcase|first|last|join|sort|map|size|escape_once|escape|strip_html|strip_newlines|newline_to_br|replace_first|replace|remove_first|remove|truncate|truncatewords|prepend|append|minus|plus|times|divided_by|split|modulo"
1515

@@ -63,7 +63,7 @@ def scan_directive(encoder, options, match)
6363
end
6464
scan_spaces(encoder)
6565
if match = scan(/#{MATH}/)
66-
encoder.text_token match, :char
66+
encoder.text_token match, :operator
6767
scan_spaces(encoder)
6868
scan_selector(encoder, options, match)
6969
end
@@ -82,7 +82,7 @@ def scan_directive(encoder, options, match)
8282
end
8383

8484
def scan_output_filters(encoder, options, match)
85-
encoder.text_token match, :delimiter
85+
encoder.text_token match, :operator
8686
scan_spaces(encoder)
8787
if directive = scan(/#{FILTER_KEYWORDS}/)
8888
encoder.text_token directive, :directive
@@ -125,7 +125,6 @@ def scan_tokens(encoder, options)
125125
if (match = scan_until(/(?=({{2,3}|{{1,2}%))/) || scan_rest) and not match.empty? and state != :liquid
126126
Rails.logger.debug "DEBUG: HTML scanning: #{match}"
127127
if match =~ /^"|^'/
128-
#match = match.sub /^"|^'/, ''
129128
@html_scanner.tokenize(match, { tokens: encoder, state: :attribute_value_string })
130129
else
131130
@html_scanner.tokenize(match, tokens: encoder)

lib/coderay/token_kinds.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ module CodeRay
6767
:type => 'type',
6868
:value => 'value',
6969
:variable => 'variable',
70-
70+
7171
:change => 'change',
7272
:delete => 'delete',
7373
:head => 'head',
@@ -76,7 +76,7 @@ module CodeRay
7676
:eyecatcher => 'eyecatcher',
7777

7878
:ident => false,
79-
:operator => false,
79+
:operator => 'operator',
8080

8181
:space => false,
8282
:plain => false

0 commit comments

Comments
 (0)