hotcell 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
- plus = '+';
11
- minus = '-';
12
- multiply = '*';
13
- power = '**';
14
- divide = '/';
15
- modulo = '%';
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
- and = '&&';
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
@@ -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.manipulator *methods
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
- send(method, *arguments) if manipulator_methods.include? method
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 Calculator < Hotcell::Node
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
@@ -19,10 +19,12 @@ module Hotcell
19
19
 
20
20
  def concat context, result
21
21
  case mode
22
- when :normal
23
- result
24
- else
22
+ when :silence
25
23
  ''
24
+ when :escape
25
+ ERB::Util.html_escape_once(result)
26
+ else
27
+ result.to_s
26
28
  end
27
29
  end
28
30
  end
data/lib/hotcell/node.rb CHANGED
@@ -54,7 +54,7 @@ module Hotcell
54
54
  end
55
55
  end
56
56
 
57
- require 'hotcell/node/calculator'
57
+ require 'hotcell/node/expression'
58
58
  require 'hotcell/node/assigner'
59
59
  require 'hotcell/node/summoner'
60
60
  require 'hotcell/node/arrayer'