@@ -26,13 +26,18 @@ class Liquid < Scanner
26
26
iflist|
27
27
endiflist|
28
28
else|
29
+ )/
30
+
31
+ DIRECTIVE_OPERATORS = /(
29
32
=|
30
33
==|
31
34
!=|
32
35
>|
33
36
<|
34
37
<=|
35
- >=
38
+ >=|
39
+ contains|
40
+ with
36
41
)/
37
42
38
43
FILTER_KEYWORDS = /(
@@ -67,6 +72,8 @@ class Liquid < Scanner
67
72
modulo
68
73
)/
69
74
75
+ SELECTORS =
76
+
70
77
LIQUID_DIRECTIVE_BLOCK = /
71
78
{%
72
79
(.*?)
@@ -94,32 +101,60 @@ def scan_directive(encoder, options, match)
94
101
#This should use the DIRECTIVE_KEYWORDS regex, not sure why it doesn't work
95
102
if match = scan ( /(wrap|endwrap)/ )
96
103
encoder . text_token match , :directive
97
- if match = scan ( /(\w +)(:)('\D +')/ )
98
- selector = match [ 0 ]
99
- delimiter = match [ 1 ]
100
- variable = match [ 2 ]
101
-
102
- encoder . text_token selector , :operator
103
- encoder . text_token delimiter , :delimiter
104
- encoder . text_token variable , :variable
104
+ scan_spaces ( encoder )
105
+ #Replace with DIRECTIVE_OPERATORS
106
+ if match = scan ( /with/ )
107
+ encoder . text_token match , :operator
108
+ if delimiter = scan ( /:/ )
109
+ encoder . text_token delimiter , :delimiter
110
+ scan_spaces ( encoder )
111
+ end
112
+ if variable = scan ( /(\w +)|('\S +')|("\w +")/ )
113
+ encoder . text_token variable , :variable
114
+ end
105
115
end
106
116
end
107
117
scan_spaces ( encoder )
108
- if match = scan ( /(%}|}}) / )
118
+ if match = scan ( /%} / )
109
119
encoder . text_token match , :key
110
120
state = :initial
111
121
end
112
122
end
113
123
124
+ def scan_output_filters ( encoder , options , match )
125
+ encoder . text_token match , :delimiter
126
+ scan_spaces ( encoder )
127
+ #Replace with OUTPUT_KEYWORDS regex
128
+ if directive = scan ( /prepend|replace_first/ )
129
+ encoder . text_token directive , :directive
130
+ end
131
+ if delimiter = scan ( /:/ )
132
+ encoder . text_token delimiter , :delimiter
133
+ end
134
+ scan_spaces ( encoder )
135
+ if variable = scan ( /(\w +)|('\S +')|(".+")/ )
136
+ encoder . text_token variable , :variable
137
+ end
138
+ if next_filter = scan ( /\s \| \s / )
139
+ scan_output_filters ( encoder , options , next_filter )
140
+ end
141
+ end
142
+
114
143
def scan_output ( encoder , options , match )
115
144
encoder . text_token match , :key
116
145
state = :liquid
117
146
scan_spaces ( encoder )
118
- if match = scan ( /\D + / )
147
+ if match = scan ( /( \w +)|(' \S +')|(" \w +") / )
119
148
encoder . text_token match , :variable
120
149
end
121
- if scan ( /\| / )
150
+ if match = scan ( /(\s \| \s )/ )
151
+ scan_output_filters ( encoder , options , match )
122
152
end
153
+ scan_spaces ( encoder )
154
+ if match = scan ( /}}/ )
155
+ encoder . text_token match , :key
156
+ end
157
+ state = :initial
123
158
end
124
159
125
160
def scan_tokens ( encoder , options )
@@ -129,12 +164,11 @@ def scan_tokens(encoder, options)
129
164
until eos?
130
165
if ( match = scan_until ( /(?=({{|{%))/ ) || scan_rest ) and not match . empty? and state != :liquid
131
166
@html_scanner . tokenize ( match , tokens : encoder )
132
- debug match , debug_cycle , state if debug_cycle == 1
133
167
state = :initial
134
168
scan_spaces ( encoder )
135
- elsif match = scan ( /({%|{{) / )
169
+ elsif match = scan ( /{% / )
136
170
scan_directive ( encoder ,
562D
options , match )
137
- elsif match = scan ( /({{|{{) / )
171
+ elsif match = scan ( /{{ / )
138
172
scan_output ( encoder , options , match )
139
173
else
140
174
raise "Else-case reached. #{ debug_cycle . to_s } cycles run. State: #{ state . to_s } ."
0 commit comments