hotcell 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +102 -84
- data/Rakefile +2 -2
- data/ext/lexerc/lexerc.c +350 -308
- data/ext/lexerc/lexerc.h +2 -7
- data/ext/lexerc/lexerc.rl +9 -90
- data/lib/hotcell/commands/for.rb +7 -2
- data/lib/hotcell/config.rb +2 -1
- data/lib/hotcell/extensions.rb +13 -1
- data/lib/hotcell/lexer.rb +5 -10
- data/lib/hotcell/lexer.rl +95 -0
- data/lib/hotcell/lexerr.rb +256 -215
- data/lib/hotcell/lexerr.rl +7 -91
- data/lib/hotcell/manipulator.rb +20 -2
- data/lib/hotcell/node/{calculator.rb → expression.rb} +4 -2
- data/lib/hotcell/node/tag.rb +5 -3
- data/lib/hotcell/node.rb +1 -1
- data/lib/hotcell/parser.rb +565 -514
- data/lib/hotcell/parser.y +46 -24
- data/lib/hotcell/template.rb +3 -2
- data/lib/hotcell/version.rb +1 -1
- data/lib/hotcell.rb +1 -1
- data/spec/lib/hotcell/commands/for_spec.rb +3 -0
- data/spec/lib/hotcell/config_spec.rb +6 -0
- data/spec/lib/hotcell/lexer_spec.rb +28 -17
- data/spec/lib/hotcell/manipulator_spec.rb +16 -11
- data/spec/lib/hotcell/node/block_spec.rb +2 -2
- data/spec/lib/hotcell/parser_spec.rb +113 -30
- data/spec/lib/hotcell/template_spec.rb +51 -1
- data/spec/lib/hotcell_spec.rb +1 -0
- metadata +4 -3
data/lib/hotcell/lexerr.rl
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
%%{
|
2
|
-
#%
|
3
2
|
machine puffer_lexer;
|
4
3
|
|
5
4
|
variable data @data;
|
@@ -7,98 +6,15 @@
|
|
7
6
|
variable ts @ts;
|
8
7
|
variable p @p;
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
arithmetic = plus | minus | multiply | power | divide | modulo;
|
9
|
+
action RegexpCheck {
|
10
|
+
if (!regexp_possible)
|
11
|
+
emit_operator;
|
12
|
+
fgoto expression;
|
13
|
+
end
|
14
|
+
}
|
17
15
|
|
18
|
-
|
19
|
-
or = '||';
|
20
|
-
not = '!';
|
21
|
-
equal = '==';
|
22
|
-
inequal = '!=';
|
23
|
-
gt = '>';
|
24
|
-
gte = '>=';
|
25
|
-
lt = '<';
|
26
|
-
lte = '<=';
|
27
|
-
logic = and | or | not | equal | inequal | gt | gte | lt | lte;
|
28
|
-
|
29
|
-
assign = '=';
|
30
|
-
comma = ',';
|
31
|
-
period = '.';
|
32
|
-
colon = ':';
|
33
|
-
question = '?';
|
34
|
-
semicolon = ';';
|
35
|
-
newline = '\n';
|
36
|
-
flow = assign | comma | period | colon | question | semicolon | newline;
|
37
|
-
|
38
|
-
array_open = '[';
|
39
|
-
array_close = ']';
|
40
|
-
hash_open = '{';
|
41
|
-
hash_close = '}';
|
42
|
-
bracket_open = '(';
|
43
|
-
bracket_close = ')';
|
44
|
-
structure = array_open | array_close | hash_open | hash_close | bracket_open | bracket_close;
|
45
|
-
|
46
|
-
|
47
|
-
escaped_symbol = '\\' any;
|
48
|
-
|
49
|
-
squote = "'";
|
50
|
-
snon_quote = [^\\'];
|
51
|
-
sstring = squote (snon_quote | escaped_symbol)* squote @lerr{ raise_unterminated_string(); };
|
52
|
-
|
53
|
-
dquote = '"';
|
54
|
-
dnon_quote = [^\\"];
|
55
|
-
dstring = dquote (dnon_quote | escaped_symbol)* dquote @lerr{ raise_unterminated_string(); };
|
56
|
-
|
57
|
-
rquote = '/';
|
58
|
-
rnon_quote = [^\\/];
|
59
|
-
regexp = rquote @{ regexp_ambiguity { fgoto expression; } }
|
60
|
-
(rnon_quote | escaped_symbol)* rquote alpha* @lerr{ raise_unterminated_regexp(); };
|
61
|
-
|
62
|
-
|
63
|
-
numeric = '-'? digit* ('.' digit+)?;
|
64
|
-
identifer = (alpha | '_') (alnum | '_')* [?!]?;
|
65
|
-
operator = arithmetic | logic | flow | structure;
|
66
|
-
comment = '#' ([^\n}]+ | '}' [^}])*;
|
67
|
-
blank = [\t\v\f\r ];
|
68
|
-
|
69
|
-
tag_open = '{{' '!'?;
|
70
|
-
tag_close = '}}';
|
71
|
-
template = [^{]+ | '{';
|
72
|
-
|
73
|
-
template_comment_open = '{{#';
|
74
|
-
template_comment_close = '#}}';
|
75
|
-
template_comment_body = [^\#]+ | '#';
|
76
|
-
|
77
|
-
|
78
|
-
expression := |*
|
79
|
-
tag_close => { emit_tag(); fret; };
|
80
|
-
operator => { emit_operator(); };
|
81
|
-
numeric => { emit_numeric(); };
|
82
|
-
identifer => { emit_identifer(); };
|
83
|
-
sstring => { emit_sstring(); };
|
84
|
-
dstring => { emit_dstring(); };
|
85
|
-
regexp => { emit_regexp(); };
|
86
|
-
comment => { emit_comment(); };
|
87
|
-
blank;
|
88
|
-
*|;
|
89
|
-
|
90
|
-
template_comment := |*
|
91
|
-
template_comment_close => { emit_comment(); fret; };
|
92
|
-
template_comment_body => { emit_comment(); };
|
93
|
-
*|;
|
94
|
-
|
95
|
-
main := |*
|
96
|
-
tag_open => { emit_tag(); fcall expression; };
|
97
|
-
template_comment_open => { emit_comment(); fcall template_comment; };
|
98
|
-
template => { emit_template(); };
|
99
|
-
*|;
|
16
|
+
include "lexer.rl";
|
100
17
|
}%%
|
101
|
-
#%
|
102
18
|
|
103
19
|
Hotcell::Lexer.class_eval do
|
104
20
|
def current_position
|
data/lib/hotcell/manipulator.rb
CHANGED
@@ -7,7 +7,7 @@ module Hotcell
|
|
7
7
|
class_attribute :manipulator_methods, instance_writter: false
|
8
8
|
self.manipulator_methods = Set.new
|
9
9
|
|
10
|
-
def self.
|
10
|
+
def self.manipulate *methods
|
11
11
|
self.manipulator_methods = Set.new(manipulator_methods.to_a + methods.flatten.map(&:to_s))
|
12
12
|
end
|
13
13
|
end
|
@@ -17,7 +17,25 @@ module Hotcell
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def manipulator_invoke method, *arguments
|
20
|
-
|
20
|
+
if method == '[]'
|
21
|
+
manipulator_invoke_brackets *arguments
|
22
|
+
elsif manipulator_invokable? method
|
23
|
+
send(method, *arguments)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def manipulator_invokable? method
|
30
|
+
manipulator_methods.include? method
|
31
|
+
end
|
32
|
+
|
33
|
+
def manipulator_invoke_brackets *arguments
|
34
|
+
if respond_to? :[]
|
35
|
+
self[*arguments]
|
36
|
+
else
|
37
|
+
manipulator_invoke *arguments
|
38
|
+
end
|
21
39
|
end
|
22
40
|
end
|
23
41
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Hotcell
|
2
|
-
class
|
2
|
+
class Expression < Hotcell::Node
|
3
3
|
HANDLERS = {
|
4
4
|
:PLUS => ->(value1, value2) { value1 + value2 },
|
5
5
|
:MINUS => ->(value1, value2) { value1 - value2 },
|
@@ -17,7 +17,9 @@ module Hotcell
|
|
17
17
|
:GT => ->(value1, value2) { value1 > value2 },
|
18
18
|
:GTE => ->(value1, value2) { value1 >= value2 },
|
19
19
|
:LT => ->(value1, value2) { value1 < value2 },
|
20
|
-
:LTE => ->(value1, value2) { value1 <= value2 }
|
20
|
+
:LTE => ->(value1, value2) { value1 <= value2 },
|
21
|
+
:RANGE => ->(value1, value2) { Range.new value1, value2 },
|
22
|
+
:ERANGE => ->(value1, value2) { Range.new value1, value2, true }
|
21
23
|
}
|
22
24
|
|
23
25
|
def optimize
|
data/lib/hotcell/node/tag.rb
CHANGED