jievro-parser 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +3 -3
  3. data/Rakefile +1 -1
  4. data/jievro-parser.gemspec +1 -1
  5. data/lib/jievro/parser/binary_operator.rb +27 -38
  6. data/lib/jievro/parser/grammar/code_block.treetop +1 -1
  7. data/lib/jievro/parser/grammar/declaration/constant_declaration.treetop +2 -8
  8. data/lib/jievro/parser/grammar/declaration/declaration.treetop +47 -5
  9. data/lib/jievro/parser/grammar/declaration/function_declaration.treetop +26 -105
  10. data/lib/jievro/parser/grammar/declaration/initializer_declaration.treetop +16 -0
  11. data/lib/jievro/parser/grammar/declaration/protocol_declaration.treetop +164 -0
  12. data/lib/jievro/parser/grammar/declaration/struct_declaration.treetop +49 -0
  13. data/lib/jievro/parser/grammar/declaration/typealias_declaration.treetop +64 -0
  14. data/lib/jievro/parser/grammar/declaration/variable_declaration.treetop +113 -9
  15. data/lib/jievro/parser/grammar/expression/binary_expression.treetop +5 -22
  16. data/lib/jievro/parser/grammar/expression/closure_expression.treetop +28 -86
  17. data/lib/jievro/parser/grammar/expression/expression.treetop +13 -13
  18. data/lib/jievro/parser/grammar/expression/function_call_expression.treetop +2 -6
  19. data/lib/jievro/parser/grammar/expression/literal_expression.treetop +1 -1
  20. data/lib/jievro/parser/grammar/expression/parenthesized_expression.treetop +15 -54
  21. data/lib/jievro/parser/grammar/expression/postfix_expression.treetop +1 -1
  22. data/lib/jievro/parser/grammar/expression/prefix_expression.treetop +1 -1
  23. data/lib/jievro/parser/grammar/expression/primary_expression.treetop +1 -1
  24. data/lib/jievro/parser/grammar/expression/range_expression.treetop +4 -18
  25. data/lib/jievro/parser/grammar/expression/self_expression.treetop +2 -7
  26. data/lib/jievro/parser/grammar/expression/super_expression.treetop +2 -7
  27. data/lib/jievro/parser/grammar/expression/wildcard_expression.treetop +1 -1
  28. data/lib/jievro/parser/grammar/generics/generic_argument_clause.treetop +8 -34
  29. data/lib/jievro/parser/grammar/generics/generics.treetop +2 -2
  30. data/lib/jievro/parser/grammar/grammar.treetop +35 -28
  31. data/lib/jievro/parser/grammar/identifier.treetop +2 -2
  32. data/lib/jievro/parser/grammar/implicit_parameter_name.treetop +1 -1
  33. data/lib/jievro/parser/grammar/literal/literal.treetop +25 -24
  34. data/lib/jievro/parser/grammar/literal/literal_array.treetop +12 -40
  35. data/lib/jievro/parser/grammar/literal/literal_boolean.treetop +5 -13
  36. data/lib/jievro/parser/grammar/literal/literal_decimal_floating_point.treetop +3 -9
  37. data/lib/jievro/parser/grammar/literal/literal_dictionary.treetop +18 -57
  38. data/lib/jievro/parser/grammar/literal/literal_hexadecimal_floating_point.treetop +3 -9
  39. data/lib/jievro/parser/grammar/literal/literal_integer_binary.treetop +3 -9
  40. data/lib/jievro/parser/grammar/literal/literal_integer_decimal.treetop +3 -9
  41. data/lib/jievro/parser/grammar/literal/literal_integer_hexadecimal.treetop +3 -9
  42. data/lib/jievro/parser/grammar/literal/literal_integer_octal.treetop +3 -9
  43. data/lib/jievro/parser/grammar/literal/literal_nil.treetop +2 -7
  44. data/lib/jievro/parser/grammar/literal/literal_numeric.treetop +11 -18
  45. data/lib/jievro/parser/grammar/literal/literal_string.treetop +14 -46
  46. data/lib/jievro/parser/grammar/operator.treetop +1 -1
  47. data/lib/jievro/parser/grammar/pattern/pattern.treetop +4 -4
  48. data/lib/jievro/parser/grammar/pattern/pattern_identifier.treetop +1 -1
  49. data/lib/jievro/parser/grammar/pattern/pattern_initializer.treetop +18 -70
  50. data/lib/jievro/parser/grammar/pattern/pattern_wildcard.treetop +1 -1
  51. data/lib/jievro/parser/grammar/statement/branch/branch.treetop +2 -2
  52. data/lib/jievro/parser/grammar/statement/branch/if.treetop +1 -1
  53. data/lib/jievro/parser/grammar/statement/loop/do_while.treetop +1 -1
  54. data/lib/jievro/parser/grammar/statement/loop/for.treetop +1 -1
  55. data/lib/jievro/parser/grammar/statement/loop/for_in.treetop +1 -1
  56. data/lib/jievro/parser/grammar/statement/loop/loop.treetop +5 -5
  57. data/lib/jievro/parser/grammar/statement/loop/while.treetop +1 -1
  58. data/lib/jievro/parser/grammar/statement/statement.treetop +3 -3
  59. data/lib/jievro/parser/grammar/type/type.treetop +7 -5
  60. data/lib/jievro/parser/grammar/type/type_annotation.treetop +1 -1
  61. data/lib/jievro/parser/grammar/type/type_array.treetop +1 -1
  62. data/lib/jievro/parser/grammar/type/type_dictionary.treetop +1 -1
  63. data/lib/jievro/parser/grammar/type/type_identifier.treetop +7 -14
  64. data/lib/jievro/parser/grammar/type/type_inheritance_clause.treetop +57 -0
  65. data/lib/jievro/parser/grammar/whitespace.treetop +1 -1
  66. data/lib/jievro/parser/grammar/wildcard.treetop +1 -1
  67. data/lib/jievro/parser/string_parser.rb +2 -7
  68. data/lib/jievro/parser/tools/converter/binary_string_to_int_converter.rb +6 -7
  69. data/lib/jievro/parser/tools/converter/converter.rb +1 -1
  70. data/lib/jievro/parser/tools/converter/decimal_float_string_to_float_converter.rb +5 -6
  71. data/lib/jievro/parser/tools/converter/decimal_string_to_int_converter.rb +5 -6
  72. data/lib/jievro/parser/tools/converter/hexadecimal_float_string_to_float_converter.rb +9 -14
  73. data/lib/jievro/parser/tools/converter/hexadecimal_string_to_int_converter.rb +5 -6
  74. data/lib/jievro/parser/tools/converter/octal_string_to_int_converter.rb +5 -6
  75. data/lib/jievro/parser/tools/quote_stripper.rb +1 -2
  76. data/lib/jievro/parser/tools/shunting_yard.rb +18 -32
  77. data/lib/jievro/parser/tools/tokens.rb +159 -0
  78. data/lib/jievro/parser/version.rb +1 -1
  79. metadata +24 -19
@@ -1,8 +1,7 @@
1
- module Kauri
1
+ module Jievro
2
2
  module Tools
3
3
  class QuoteStripper
4
4
  def strip(string)
5
-
6
5
  string.gsub!(/\\n/, "\n")
7
6
  string.gsub!(/\\r/, "\r")
8
7
  string.gsub!(/\\t/, "\t")
@@ -4,76 +4,62 @@ module Jievro
4
4
  module Parser
5
5
  module Tools
6
6
  class ShuntingYard
7
-
8
7
  def generate_ast(infix_tokens)
9
-
10
8
  node_stack = []
11
9
  rpn_tokens = generate_rpn(infix_tokens)
12
10
 
13
- rpn_tokens.each { |token|
14
-
15
- if BinaryOperator.is_operator(token)
11
+ rpn_tokens.each do |token|
12
+ if BinaryOperator.operator?(token)
16
13
  right = node_stack.pop
17
14
  left = node_stack.pop
18
15
 
19
- node_stack.push({
16
+ node_stack << {
20
17
  __type: 'binary-expression',
21
18
  operator: token,
22
19
  left: left,
23
20
  right: right
24
- })
25
-
21
+ }
26
22
  else
27
- node_stack.push(token)
23
+ node_stack << token
28
24
  end
29
- }
25
+ end
30
26
 
31
27
  node_stack
32
28
  end
33
29
 
34
30
  def generate_rpn(infix_tokens)
35
-
36
31
  output_queue = []
37
32
  operator_stack = []
38
33
 
39
- infix_tokens.each { |token|
40
-
41
- if BinaryOperator.is_operator(token)
42
-
34
+ infix_tokens.each do |token|
35
+ if BinaryOperator.operator?(token)
43
36
  current_operator = BinaryOperator.get(token)
44
37
 
45
- until operator_stack.empty? do
46
-
38
+ until operator_stack.empty?
47
39
  stack_operator = operator_stack.last
48
-
49
40
  move_operator_to_queue = false
50
41
 
51
- if :left == current_operator.associativity and current_operator.precedence <= stack_operator.precedence
42
+ if :left == current_operator.associativity && current_operator.precedence <= stack_operator.precedence
52
43
  move_operator_to_queue = true
53
- elsif :right == current_operator.associativity and current_operator.precedence < stack_operator.precedence
44
+ elsif :right == current_operator.associativity && current_operator.precedence < stack_operator.precedence
54
45
  move_operator_to_queue = true
55
46
  end
56
47
 
57
- unless move_operator_to_queue
58
- break
59
- end
48
+ break unless move_operator_to_queue
60
49
 
61
50
  operator_stack.pop
62
- output_queue.push stack_operator.sign
51
+
52
+ output_queue << stack_operator.sign
63
53
  end
64
54
 
65
- operator_stack.push(current_operator)
55
+ operator_stack << current_operator
66
56
  else
67
-
68
- output_queue.push(token)
69
-
57
+ output_queue << token
70
58
  end
71
- }
72
-
73
- until operator_stack.empty?
74
- output_queue.push(operator_stack.pop.sign)
75
59
  end
76
60
 
61
+ output_queue << operator_stack.pop.sign until operator_stack.empty?
62
+
77
63
  output_queue
78
64
  end
79
65
  end
@@ -30,6 +30,16 @@ T_CLOSE_ROUND_BRACKET = {
30
30
  value: ')'
31
31
  }
32
32
 
33
+ T_OPEN_SQUARE_BRACKET = {
34
+ type: 'T_OPEN_SQUARE_BRACKET',
35
+ value: '['
36
+ }
37
+
38
+ T_CLOSE_SQUARE_BRACKET = {
39
+ type: 'T_CLOSE_SQUARE_BRACKET',
40
+ value: ']'
41
+ }
42
+
33
43
  T_OPEN_CURLY_BRACKET = {
34
44
  type: 'T_OPEN_CURLY_BRACKET',
35
45
  value: '{'
@@ -40,6 +50,43 @@ T_CLOSE_CURLY_BRACKET = {
40
50
  value: '}'
41
51
  }
42
52
 
53
+ T_OPEN_ANGLE_BRACKET = {
54
+ type: 'T_OPEN_ANGLE_BRACKET',
55
+ value: '<'
56
+ }
57
+
58
+ T_CLOSE_ANGLE_BRACKET = {
59
+ type: 'T_CLOSE_ANGLE_BRACKET',
60
+ value: '>'
61
+ }
62
+
63
+ T_QUOTED_EXPRESSION_OPEN = {
64
+ type: 'T_QUOTED_EXPRESSION_OPEN',
65
+ value: '\('
66
+ }
67
+
68
+ T_QUOTED_EXPRESSION_CLOSE = {
69
+ type: 'T_QUOTED_EXPRESSION_CLOSE',
70
+ value: ')'
71
+ }
72
+
73
+ def T_UNICODE_CHAR(value)
74
+ {
75
+ type: 'T_UNICODE_CHAR',
76
+ value: value
77
+ }
78
+ end
79
+
80
+ T_QUOTED_UNICODE_CHAR_OPEN = {
81
+ type: 'T_QUOTED_UNICODE_CHAR_OPEN',
82
+ value: '\\u' + 123.chr
83
+ }
84
+
85
+ T_QUOTED_UNICODE_CHAR_CLOSE = {
86
+ type: 'T_QUOTED_UNICODE_CHAR_CLOSE',
87
+ value: 125.chr
88
+ }
89
+
43
90
  T_FALSE = {
44
91
  type: 'T_FALSE',
45
92
  value: 'false'
@@ -62,6 +109,48 @@ def T_LITERAL_INTEGER_DECIMAL(value)
62
109
  }
63
110
  end
64
111
 
112
+ def T_LITERAL_FLOATING_POINT_DECIMAL(value)
113
+ {
114
+ type: 'T_LITERAL_FLOATING_POINT_DECIMAL',
115
+ value: value
116
+ }
117
+ end
118
+
119
+ def T_LITERAL_FLOATING_POINT_HEXADECIMAL(value)
120
+ {
121
+ type: 'T_LITERAL_FLOATING_POINT_HEXADECIMAL',
122
+ value: value
123
+ }
124
+ end
125
+
126
+ def T_LITERAL_INTEGER_BINARY(value)
127
+ {
128
+ type: 'T_LITERAL_INTEGER_BINARY',
129
+ value: value
130
+ }
131
+ end
132
+
133
+ def T_LITERAL_INTEGER_HEXADECIMAL(value)
134
+ {
135
+ type: 'T_LITERAL_INTEGER_HEXADECIMAL',
136
+ value: value
137
+ }
138
+ end
139
+
140
+ def T_LITERAL_INTEGER_OCTAL(value)
141
+ {
142
+ type: 'T_LITERAL_INTEGER_OCTAL',
143
+ value: value
144
+ }
145
+ end
146
+
147
+ def T_LITERAL_STRING(value)
148
+ {
149
+ type: 'T_LITERAL_STRING',
150
+ value: value
151
+ }
152
+ end
153
+
65
154
  def T_IDENTIFIER(value)
66
155
  {
67
156
  type: 'T_IDENTIFIER',
@@ -81,6 +170,11 @@ T_VAR = {
81
170
  value: 'var'
82
171
  }
83
172
 
173
+ T_LET = {
174
+ type: 'T_LET',
175
+ value: 'let'
176
+ }
177
+
84
178
  T_FOR = {
85
179
  type: 'T_FOR',
86
180
  value: 'for'
@@ -110,3 +204,68 @@ T_ELSE = {
110
204
  type: 'T_ELSE',
111
205
  value: 'else'
112
206
  }
207
+
208
+ T_STRUCT = {
209
+ type: 'T_STRUCT',
210
+ value: 'struct'
211
+ }
212
+
213
+ T_NIL = {
214
+ type: 'T_NIL',
215
+ value: 'nil'
216
+ }
217
+
218
+ T_SELF = {
219
+ type: 'T_SELF',
220
+ value: 'self'
221
+ }
222
+
223
+ T_SUPER = {
224
+ type: 'T_SUPER',
225
+ value: 'super'
226
+ }
227
+
228
+ T_DOUBLE_QUOTE = {
229
+ type: 'T_DOUBLE_QUOTE',
230
+ value: '"'
231
+ }
232
+
233
+ T_FUNCTION = {
234
+ type: 'T_FUNCTION',
235
+ value: 'func'
236
+ }
237
+
238
+ T_RETURN_TYPE_ARROW = {
239
+ type: 'T_RETURN_TYPE_ARROW',
240
+ value: '->'
241
+ }
242
+
243
+ T_PROTOCOL = {
244
+ type: 'T_PROTOCOL',
245
+ value: 'protocol'
246
+ }
247
+
248
+ T_GET = {
249
+ type: 'T_GET',
250
+ value: 'get'
251
+ }
252
+
253
+ T_SET = {
254
+ type: 'T_SET',
255
+ value: 'set'
256
+ }
257
+
258
+ T_INIT = {
259
+ type: 'T_INIT',
260
+ value: 'init'
261
+ }
262
+
263
+ T_TYPEALIAS = {
264
+ type: 'T_TYPEALIAS',
265
+ value: 'typealias'
266
+ }
267
+
268
+ T_UNOWNED = {
269
+ type: 'T_UNOWNED',
270
+ value: 'unowned'
271
+ }
@@ -1,5 +1,5 @@
1
1
  module Jievro
2
2
  module Parser
3
- VERSION = '0.8.0'
3
+ VERSION = '0.9.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,83 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jievro-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefano Azzalini
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-08 00:00:00.000000000 Z
11
+ date: 2015-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jievro-ast
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.5'
19
+ version: '0.7'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.5'
26
+ version: '0.7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: treetop
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.6'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.6'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '1.9'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.9'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '10.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '10.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '3.2'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '3.2'
83
83
  description:
@@ -86,8 +86,8 @@ executables: []
86
86
  extensions: []
87
87
  extra_rdoc_files: []
88
88
  files:
89
- - .gitignore
90
- - .travis.yml
89
+ - ".gitignore"
90
+ - ".travis.yml"
91
91
  - Gemfile
92
92
  - Gemfile.lock
93
93
  - LICENSE.txt
@@ -100,6 +100,10 @@ files:
100
100
  - lib/jievro/parser/grammar/declaration/constant_declaration.treetop
101
101
  - lib/jievro/parser/grammar/declaration/declaration.treetop
102
102
  - lib/jievro/parser/grammar/declaration/function_declaration.treetop
103
+ - lib/jievro/parser/grammar/declaration/initializer_declaration.treetop
104
+ - lib/jievro/parser/grammar/declaration/protocol_declaration.treetop
105
+ - lib/jievro/parser/grammar/declaration/struct_declaration.treetop
106
+ - lib/jievro/parser/grammar/declaration/typealias_declaration.treetop
103
107
  - lib/jievro/parser/grammar/declaration/variable_declaration.treetop
104
108
  - lib/jievro/parser/grammar/expression/binary_expression.treetop
105
109
  - lib/jievro/parser/grammar/expression/closure_expression.treetop
@@ -150,6 +154,7 @@ files:
150
154
  - lib/jievro/parser/grammar/type/type_array.treetop
151
155
  - lib/jievro/parser/grammar/type/type_dictionary.treetop
152
156
  - lib/jievro/parser/grammar/type/type_identifier.treetop
157
+ - lib/jievro/parser/grammar/type/type_inheritance_clause.treetop
153
158
  - lib/jievro/parser/grammar/whitespace.treetop
154
159
  - lib/jievro/parser/grammar/wildcard.treetop
155
160
  - lib/jievro/parser/parse_result.rb
@@ -175,17 +180,17 @@ require_paths:
175
180
  - lib
176
181
  required_ruby_version: !ruby/object:Gem::Requirement
177
182
  requirements:
178
- - - ~>
183
+ - - "~>"
179
184
  - !ruby/object:Gem::Version
180
185
  version: '2.0'
181
186
  required_rubygems_version: !ruby/object:Gem::Requirement
182
187
  requirements:
183
- - - '>='
188
+ - - ">="
184
189
  - !ruby/object:Gem::Version
185
190
  version: '0'
186
191
  requirements: []
187
192
  rubyforge_project:
188
- rubygems_version: 2.0.14
193
+ rubygems_version: 2.4.6
189
194
  signing_key:
190
195
  specification_version: 4
191
196
  summary: Source code parser used internally by jievro