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,6 +1,4 @@
1
- require 'jievro/parser/tools/converter/converter'
2
-
3
- module Kauri
1
+ module Jievro
4
2
  grammar LiteralHexadecimalFloatingPoint
5
3
 
6
4
  rule literal_hexadecimal_floating_point
@@ -11,16 +9,12 @@ module Kauri
11
9
  ) {
12
10
  def tokens
13
11
  [
14
- {
15
- type: 'T_LITERAL_FLOATING_POINT_HEXADECIMAL',
16
- value: text_value
17
- }
12
+ T_LITERAL_FLOATING_POINT_HEXADECIMAL(text_value)
18
13
  ]
19
14
  end
20
15
 
21
16
  def ast
22
-
23
- converter = Kauri::Tools::Converter::HexadecimalFloatStringToFloatConverter.new
17
+ converter = Jievro::Tools::Converter::HexadecimalFloatStringToFloatConverter.new
24
18
 
25
19
  [
26
20
  {
@@ -1,22 +1,16 @@
1
- require 'jievro/parser/tools/converter/converter'
2
-
3
- module Kauri
1
+ module Jievro
4
2
  grammar LiteralIntegerBinary
5
3
 
6
4
  rule literal_integer_binary
7
5
  '0b' binary_digit binary_literal_characters? {
8
6
  def tokens
9
7
  [
10
- {
11
- type: 'T_LITERAL_INTEGER_BINARY',
12
- value: text_value
13
- }
8
+ T_LITERAL_INTEGER_BINARY(text_value)
14
9
  ]
15
10
  end
16
11
 
17
12
  def ast
18
-
19
- converter = Kauri::Tools::Converter::BinaryStringToIntConverter.new
13
+ converter = Jievro::Tools::Converter::BinaryStringToIntConverter.new
20
14
 
21
15
  [
22
16
  {
@@ -1,22 +1,16 @@
1
- require 'jievro/parser/tools/converter/converter'
2
-
3
- module Kauri
1
+ module Jievro
4
2
  grammar LiteralIntegerDecimal
5
3
 
6
4
  rule literal_integer_decimal
7
5
  decimal_digit decimal_literal_characters? {
8
6
  def tokens
9
7
  [
10
- {
11
- type: 'T_LITERAL_INTEGER_DECIMAL',
12
- value: text_value
13
- }
8
+ T_LITERAL_INTEGER_DECIMAL(text_value)
14
9
  ]
15
10
  end
16
11
 
17
12
  def ast
18
-
19
- converter = Kauri::Tools::Converter::DecimalStringToIntConverter.new
13
+ converter = Jievro::Tools::Converter::DecimalStringToIntConverter.new
20
14
 
21
15
  [
22
16
  {
@@ -1,22 +1,16 @@
1
- require 'jievro/parser/tools/converter/converter'
2
-
3
- module Kauri
1
+ module Jievro
4
2
  grammar LiteralIntegerHexadecimal
5
3
 
6
4
  rule literal_integer_hexadecimal
7
5
  '0x' hexadecimal_digit hexadecimal_literal_characters? {
8
6
  def tokens
9
7
  [
10
- {
11
- type: 'T_LITERAL_INTEGER_HEXADECIMAL',
12
- value: text_value
13
- }
8
+ T_LITERAL_INTEGER_HEXADECIMAL(text_value)
14
9
  ]
15
10
  end
16
11
 
17
12
  def ast
18
-
19
- converter = Kauri::Tools::Converter::HexadecimalStringToIntConverter.new
13
+ converter = Jievro::Tools::Converter::HexadecimalStringToIntConverter.new
20
14
 
21
15
  [
22
16
  {
@@ -1,22 +1,16 @@
1
- require 'jievro/parser/tools/converter/converter'
2
-
3
- module Kauri
1
+ module Jievro
4
2
  grammar LiteralIntegerOctal
5
3
 
6
4
  rule literal_integer_octal
7
5
  '0o' octal_digit octal_literal_characters? {
8
6
  def tokens
9
7
  [
10
- {
11
- type: 'T_LITERAL_INTEGER_OCTAL',
12
- value: text_value
13
- }
8
+ T_LITERAL_INTEGER_OCTAL(text_value)
14
9
  ]
15
10
  end
16
11
 
17
12
  def ast
18
-
19
- converter = Kauri::Tools::Converter::OctalStringToIntConverter.new
13
+ converter = Jievro::Tools::Converter::OctalStringToIntConverter.new
20
14
 
21
15
  [
22
16
  {
@@ -1,15 +1,10 @@
1
- module Kauri
1
+ module Jievro
2
2
  grammar LiteralNil
3
3
 
4
4
  rule literal_nil
5
5
  'nil' {
6
6
  def tokens
7
- [
8
- {
9
- type: 'T_NIL',
10
- value: text_value
11
- }
12
- ]
7
+ [T_NIL]
13
8
  end
14
9
 
15
10
  def ast
@@ -4,26 +4,24 @@ require 'jievro/parser/grammar/literal/literal_integer_decimal'
4
4
  require 'jievro/parser/grammar/literal/literal_integer_hexadecimal'
5
5
  require 'jievro/parser/grammar/literal/literal_decimal_floating_point'
6
6
  require 'jievro/parser/grammar/literal/literal_hexadecimal_floating_point'
7
+ require 'jievro/parser/tools/converter/converter'
7
8
 
8
- module Kauri
9
+ module Jievro
9
10
  grammar LiteralNumeric
10
11
 
11
- include Kauri::LiteralIntegerBinary
12
- include Kauri::LiteralIntegerOctal
13
- include Kauri::LiteralIntegerDecimal
14
- include Kauri::LiteralIntegerHexadecimal
15
- include Kauri::LiteralDecimalFloatingPoint
16
- include Kauri::LiteralHexadecimalFloatingPoint
12
+ include Jievro::LiteralIntegerBinary
13
+ include Jievro::LiteralIntegerOctal
14
+ include Jievro::LiteralIntegerDecimal
15
+ include Jievro::LiteralIntegerHexadecimal
16
+ include Jievro::LiteralDecimalFloatingPoint
17
+ include Jievro::LiteralHexadecimalFloatingPoint
17
18
 
18
19
  rule literal_numeric
19
20
  minus:minus? numeric:(literal_floating_point / literal_integer) {
20
21
  def tokens
21
22
  tokens = []
22
23
 
23
- unless minus.text_value.empty?
24
- tokens.push(minus.tokens)
25
- end
26
-
24
+ tokens.concat(minus.tokens) unless minus.text_value.empty?
27
25
  tokens.concat(numeric.tokens)
28
26
 
29
27
  tokens
@@ -32,9 +30,7 @@ module Kauri
32
30
  def ast
33
31
  ast = numeric.ast.first
34
32
 
35
- unless minus.text_value.empty?
36
- ast[:value] = -ast[:value]
37
- end
33
+ ast[:value] = -ast[:value] unless minus.text_value.empty?
38
34
 
39
35
  [ast]
40
36
  end
@@ -58,10 +54,7 @@ module Kauri
58
54
  rule minus
59
55
  '-' {
60
56
  def tokens
61
- {
62
- type: 'T_MINUS',
63
- value: '-'
64
- }
57
+ [T_OPERATOR('-')]
65
58
  end
66
59
  }
67
60
  end
@@ -1,31 +1,19 @@
1
- module Kauri
1
+ module Jievro
2
2
  grammar LiteralString
3
3
 
4
4
  rule literal_string
5
5
  '"' quoted_text:quoted_text? '"' {
6
6
  def tokens
7
+ tokens = []
7
8
 
8
- tokens = [
9
- {
10
- type: 'T_DOUBLE_QUOTE',
11
- value: '"'
12
- }
13
- ]
14
-
15
- unless quoted_text.text_value.empty?
16
- tokens.concat(quoted_text.tokens)
17
- end
18
-
19
- tokens.push({
20
- type: 'T_DOUBLE_QUOTE',
21
- value: '"'
22
- })
9
+ tokens.push(T_DOUBLE_QUOTE)
10
+ tokens.concat(quoted_text.tokens) unless quoted_text.text_value.empty?
11
+ tokens.push(T_DOUBLE_QUOTE)
23
12
 
24
13
  tokens
25
14
  end
26
15
 
27
16
  def ast
28
-
29
17
  if quoted_text.text_value.empty?
30
18
  ast = [
31
19
  {
@@ -56,7 +44,7 @@ module Kauri
56
44
  ast = []
57
45
  is_interpolated_string = false
58
46
  last_node_is_literal_string = false
59
- stripper = Kauri::Tools::QuoteStripper.new
47
+ stripper = Jievro::Tools::QuoteStripper.new
60
48
 
61
49
  elements.each { |e|
62
50
  if e.is_expression
@@ -64,7 +52,6 @@ module Kauri
64
52
  last_node_is_literal_string = false
65
53
  ast.push(e.ast)
66
54
  else
67
-
68
55
  if e.is_quoted_unicode_char
69
56
  value = e.raw_value
70
57
  else
@@ -104,12 +91,10 @@ module Kauri
104
91
  rule sequence_of_chars
105
92
  (escaped_character / standard_character)+ {
106
93
  def tokens
107
- stripper = Kauri::Tools::QuoteStripper.new
94
+ stripper = Jievro::Tools::QuoteStripper.new
95
+
108
96
  [
109
- {
110
- type: 'T_LITERAL_STRING',
111
- value: stripper.strip(text_value)
112
- }
97
+ T_LITERAL_STRING(stripper.strip(text_value))
113
98
  ]
114
99
  end
115
100
 
@@ -128,17 +113,9 @@ module Kauri
128
113
  def tokens
129
114
  tokens = []
130
115
 
131
- tokens.push({
132
- type: 'T_QUOTED_EXPRESSION_OPEN',
133
- value: '\('
134
- })
135
-
116
+ tokens.push(T_QUOTED_EXPRESSION_OPEN)
136
117
  tokens.concat(expression.tokens)
137
-
138
- tokens.push({
139
- type: 'T_QUOTED_EXPRESSION_CLOSE',
140
- value: ')'
141
- })
118
+ tokens.push(T_QUOTED_EXPRESSION_CLOSE)
142
119
 
143
120
  tokens
144
121
  end
@@ -161,18 +138,9 @@ module Kauri
161
138
  '\u{' unicode_scalar_digits:unicode_scalar_digits 1..8 '}' {
162
139
  def tokens
163
140
  [
164
- {
165
- type: 'T_QUOTED_UNICODE_CHAR_OPEN',
166
- value: '\\u' + 123.chr
167
- },
168
- {
169
- type: 'T_UNICODE_CHAR',
170
- value: unicode_scalar_digits.text_value
171
- },
172
- {
173
- type: 'T_QUOTED_UNICODE_CHAR_CLOSE',
174
- value: 125.chr
175
- }
141
+ T_QUOTED_UNICODE_CHAR_OPEN,
142
+ T_UNICODE_CHAR(unicode_scalar_digits.text_value),
143
+ T_QUOTED_UNICODE_CHAR_CLOSE
176
144
  ]
177
145
  end
178
146
 
@@ -1,4 +1,4 @@
1
- module Kauri
1
+ module Jievro
2
2
  grammar Operator
3
3
 
4
4
  rule operator
@@ -2,12 +2,12 @@ require 'jievro/parser/grammar/pattern/pattern_wildcard'
2
2
  require 'jievro/parser/grammar/pattern/pattern_identifier'
3
3
  require 'jievro/parser/grammar/pattern/pattern_initializer'
4
4
 
5
- module Kauri
5
+ module Jievro
6
6
  grammar Pattern
7
7
 
8
- include Kauri::PatternWildcard
9
- include Kauri::PatternIdentifier
10
- include Kauri::PatternInitializer
8
+ include Jievro::PatternWildcard
9
+ include Jievro::PatternIdentifier
10
+ include Jievro::PatternInitializer
11
11
 
12
12
  rule pattern
13
13
  pattern_wildcard / pattern_identifier
@@ -1,4 +1,4 @@
1
- module Kauri
1
+ module Jievro
2
2
  grammar PatternIdentifier
3
3
 
4
4
  rule pattern_identifier
@@ -1,4 +1,4 @@
1
- module Kauri
1
+ module Jievro
2
2
  grammar PatternInitializer
3
3
 
4
4
  rule untyped_pattern_initializer
@@ -7,29 +7,20 @@ module Kauri
7
7
  tokens = []
8
8
 
9
9
  tokens.concat(pattern.tokens)
10
-
11
- unless ws.text_value.empty?
12
- tokens.concat(ws.tokens)
13
- end
14
-
15
- unless initializer.text_value.empty?
16
- tokens.concat(initializer.tokens)
17
- end
10
+ tokens.concat(ws.tokens) unless ws.text_value.empty?
11
+ tokens.concat(initializer.tokens) unless initializer.text_value.empty?
18
12
 
19
13
  tokens
20
14
  end
21
15
 
22
16
  def ast
23
-
24
17
  ast = {
25
18
  pattern: pattern.ast.first
26
19
  }
27
20
 
28
21
  ast[:pattern] = pattern.ast.first
29
-
30
- unless initializer.text_value.empty?
31
- ast[:initializer] = initializer.ast.first
32
- end
22
+ ast[:initializer] = initializer.ast.first \
23
+ unless initializer.text_value.empty?
33
24
 
34
25
  ast
35
26
  end
@@ -42,20 +33,10 @@ module Kauri
42
33
  tokens = []
43
34
 
44
35
  tokens.concat(pattern.tokens)
45
-
46
- unless ws1.text_value.empty?
47
- tokens.concat(ws1.tokens)
48
- end
49
-
36
+ tokens.concat(ws1.tokens) unless ws1.text_value.empty?
50
37
  tokens.concat(type_annotation.tokens)
51
-
52
- unless ws2.text_value.empty?
53
- tokens.concat(ws2.tokens)
54
- end
55
-
56
- unless initializer.text_value.empty?
57
- tokens.concat(initializer.tokens)
58
- end
38
+ tokens.concat(ws2.tokens) unless ws2.text_value.empty?
39
+ tokens.concat(initializer.tokens) unless initializer.text_value.empty?
59
40
 
60
41
  tokens
61
42
  end
@@ -65,10 +46,8 @@ module Kauri
65
46
 
66
47
  ast[:pattern] = pattern.ast.first
67
48
  ast[:pattern][:type] = type_annotation.ast.first
68
-
69
- unless initializer.text_value.empty?
70
- ast[:initializer] = initializer.ast.first
71
- end
49
+ ast[:initializer] = initializer.ast.first \
50
+ unless initializer.text_value.empty?
72
51
 
73
52
  ast
74
53
  end
@@ -90,30 +69,19 @@ module Kauri
90
69
  rule pattern_initializer_list
91
70
  head:pattern_initializer_list_head? ws:_ tail:pattern_initializer {
92
71
  def tokens
93
-
94
72
  tokens = []
95
73
 
96
- unless head.text_value.empty?
97
- tokens.concat(head.tokens)
98
- end
99
-
100
- unless ws.text_value.empty?
101
- tokens.concat(ws.tokens)
102
- end
103
-
74
+ tokens.concat(head.tokens) unless head.text_value.empty?
75
+ tokens.concat(ws.tokens) unless ws.text_value.empty?
104
76
  tokens.concat(tail.tokens)
105
77
 
106
78
  tokens
107
79
  end
108
80
 
109
81
  def ast
110
-
111
82
  ast = []
112
83
 
113
- unless head.text_value.empty?
114
- ast.concat(head.ast)
115
- end
116
-
84
+ ast.concat(head.ast) unless head.text_value.empty?
117
85
  ast.push(tail.ast)
118
86
 
119
87
  ast
@@ -124,32 +92,19 @@ module Kauri
124
92
  rule pattern_initializer_list_head
125
93
  (pattern_initializer:pattern_initializer ws1:_ ',' ws2:_)+ {
126
94
  def tokens
127
-
128
95
  tokens = []
129
96
 
130
97
  elements.each { |e|
131
-
132
98
  tokens.concat(e.pattern_initializer.tokens)
133
-
134
- unless e.ws1.text_value.empty?
135
- tokens.concat(e.ws1.tokens)
136
- end
137
-
138
- tokens.push({
139
- type: 'T_COMMA',
140
- value: ','
141
- })
142
-
143
- unless e.ws2.text_value.empty?
144
- tokens.concat(e.ws2.tokens)
145
- end
99
+ tokens.concat(e.ws1.tokens) unless e.ws1.text_value.empty?
100
+ tokens.push(T_COMMA)
101
+ tokens.concat(e.ws2.tokens) unless e.ws2.text_value.empty?
146
102
  }
147
103
 
148
104
  tokens
149
105
  end
150
106
 
151
107
  def ast
152
-
153
108
  ast = []
154
109
 
155
110
  elements.each { |e|
@@ -166,15 +121,8 @@ module Kauri
166
121
  def tokens
167
122
  tokens = []
168
123
 
169
- tokens.push({
170
- type: 'T_OPERATOR',
171
- value: '='
172
- })
173
-
174
- unless ws.text_value.empty?
175
- tokens.concat(ws.tokens)
176
- end
177
-
124
+ tokens.push(T_OPERATOR('='))
125
+ tokens.concat(ws.tokens) unless ws.text_value.empty?
178
126
  tokens.concat(expression.tokens)
179
127
 
180
128
  tokens