liquidscript 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -1
- data/Guardfile +0 -4
- data/Rakefile +2 -2
- data/lib/liquidscript/compiler/icr/expressions.rb +2 -1
- data/lib/liquidscript/compiler/icr/literals.rb +17 -3
- data/lib/liquidscript/generator/javascript/literals.rb +18 -2
- data/lib/liquidscript/scanner.rb +3 -31
- data/lib/liquidscript/scanner/base.rb +84 -0
- data/lib/liquidscript/scanner/base/builder.rb +38 -0
- data/lib/liquidscript/scanner/base/context.rb +83 -0
- data/lib/liquidscript/scanner/base/dsl.rb +27 -0
- data/lib/liquidscript/scanner/base/lexer.rb +80 -0
- data/lib/liquidscript/scanner/liquidscript.rb +128 -0
- data/lib/liquidscript/scanner/token.rb +2 -6
- data/lib/liquidscript/template.rb +0 -1
- data/lib/liquidscript/version.rb +1 -1
- data/spec/fixtures/complex.generate.yml +1 -0
- data/spec/fixtures/main.compile.yml +1 -1
- data/spec/fixtures/string.compile.yml +15 -0
- data/spec/fixtures/string.generate.yml +3 -1
- data/spec/{lib/liquidscript → liquidscript}/buffer_spec.rb +0 -0
- data/spec/{lib/liquidscript → liquidscript}/compiler/icr_spec.rb +0 -0
- data/spec/{lib/liquidscript → liquidscript}/generator/javascript_spec.rb +7 -2
- data/spec/{lib/liquidscript → liquidscript}/icr/code_spec.rb +0 -0
- data/spec/{lib/liquidscript → liquidscript}/icr/context_spec.rb +0 -0
- data/spec/{lib/liquidscript → liquidscript}/icr/set_spec.rb +0 -0
- data/spec/{lib/liquidscript → liquidscript}/scanner/lexer_spec.rb +13 -15
- data/spec/{lib/liquidscript → liquidscript}/scanner/token_spec.rb +0 -0
- data/spec/{lib/liquidscript → liquidscript}/scanner_spec.rb +2 -2
- data/spec/spec_helper.rb +1 -0
- data/spec/support/helpers/lexer_helper.rb +1 -1
- data/spec/support/matchers/compile.rb +1 -1
- data/spec/support/matchers/generate.rb +2 -2
- metadata +28 -22
- data/lib/liquidscript/scanner/lexer.rb +0 -805
- data/lib/liquidscript/scanner/lexer.rl +0 -118
@@ -1,118 +0,0 @@
|
|
1
|
-
%%{
|
2
|
-
|
3
|
-
machine lexer;
|
4
|
-
|
5
|
-
variable data @data;
|
6
|
-
variable p @p;
|
7
|
-
variable pe @pe;
|
8
|
-
variable eof @eof;
|
9
|
-
access @;
|
10
|
-
|
11
|
-
number_integer = '-'? [0-9][1-9]*;
|
12
|
-
number_frac = '.' [0-9]+;
|
13
|
-
number_e = ('e' | 'E') ('+' | '-' | '');
|
14
|
-
number_exp = number_e [0-9]+;
|
15
|
-
number = number_integer number_frac? number_exp?;
|
16
|
-
|
17
|
-
string_double = '"' ( any -- '"' | '\\"' )* '"';
|
18
|
-
identifier = [A-Za-z_$][A-Za-z0-9_$]*;
|
19
|
-
string_single = "'" [A-Za-z0-9_$\-]+;
|
20
|
-
keywords = 'undefined' | 'null' | 'true' | 'false';
|
21
|
-
unops = '!' | '++' | '--' | '~' | 'new' | 'return' |
|
22
|
-
'typeof';
|
23
|
-
binops = '+' | '-' | '*' | '/' | '&' | '|' | '^' | '<<' | '>>' |
|
24
|
-
'>>>' | '==' | '!=' | '===' | '!==' | '>' | '>=' | '<' | '<=' |
|
25
|
-
'&&' | '||' | 'instanceof' | 'or' | 'and';
|
26
|
-
|
27
|
-
main := |*
|
28
|
-
number => { emit :number };
|
29
|
-
string_double => { emit :dstring };
|
30
|
-
string_single => { emit :sstring };
|
31
|
-
'class' => { emit :class };
|
32
|
-
'module' => { emit :module };
|
33
|
-
'if' => { emit :if };
|
34
|
-
'unless' => { emit :unless };
|
35
|
-
'elsif' => { emit :elsif };
|
36
|
-
'else' => { emit :else };
|
37
|
-
unops => { emit :unop };
|
38
|
-
binops => { emit :binop };
|
39
|
-
keywords => { emit :keyword };
|
40
|
-
identifier => { emit :identifier };
|
41
|
-
'->' => { emit :arrow };
|
42
|
-
'=' => { emit :equal };
|
43
|
-
'{' => { emit :lbrack };
|
44
|
-
'(' => { emit :lparen };
|
45
|
-
'[' => { emit :lbrace };
|
46
|
-
'}' => { emit :rbrack };
|
47
|
-
')' => { emit :rparen };
|
48
|
-
']' => { emit :rbrace };
|
49
|
-
':' => { emit :colon };
|
50
|
-
'.' => { emit :prop };
|
51
|
-
',' => { emit :comma };
|
52
|
-
'\n' => { line.call };
|
53
|
-
space => { };
|
54
|
-
any => { error };
|
55
|
-
*|;
|
56
|
-
}%%
|
57
|
-
|
58
|
-
module Liquidscript
|
59
|
-
class Scanner
|
60
|
-
|
61
|
-
# A lexer, built from ragel.
|
62
|
-
#
|
63
|
-
# @private
|
64
|
-
class Lexer
|
65
|
-
|
66
|
-
attr_reader :tokens
|
67
|
-
|
68
|
-
def initialize
|
69
|
-
%% write data;
|
70
|
-
# %% # fix
|
71
|
-
@tokens = []
|
72
|
-
clean!
|
73
|
-
end
|
74
|
-
|
75
|
-
def clean!
|
76
|
-
@p = nil
|
77
|
-
@pe = nil
|
78
|
-
@te = nil
|
79
|
-
@ts = nil
|
80
|
-
@act = nil
|
81
|
-
@eof = nil
|
82
|
-
@top = nil
|
83
|
-
@line = { :start => 0, :num => 0 }
|
84
|
-
@data = nil
|
85
|
-
@stack = nil
|
86
|
-
end
|
87
|
-
|
88
|
-
def emit(type)
|
89
|
-
@tokens << Token.new(type, @data[@ts..(@te - 1)],
|
90
|
-
@line[:num], @ts - @line[:start])
|
91
|
-
end
|
92
|
-
|
93
|
-
def error
|
94
|
-
raise SyntaxError, "Unexpected #{@data[@ts..(@te-1)].pack('c*')}"
|
95
|
-
end
|
96
|
-
|
97
|
-
def perform(data)
|
98
|
-
@data = data.unpack("c*") if data.is_a? String
|
99
|
-
@eof = data.length
|
100
|
-
|
101
|
-
@tokens = []
|
102
|
-
|
103
|
-
line = proc do
|
104
|
-
@line[:start] = @ts
|
105
|
-
@line[:num] += 1
|
106
|
-
emit :newline
|
107
|
-
end
|
108
|
-
|
109
|
-
%% write init;
|
110
|
-
%% write exec;
|
111
|
-
|
112
|
-
clean!
|
113
|
-
|
114
|
-
@tokens
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|