code-ruby-parser 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/docs/precedence.code +1 -0
  4. data/docs/precedence.template +35 -0
  5. data/lib/code/parser/and_operator.rb +1 -1
  6. data/lib/code/parser/call.rb +33 -24
  7. data/lib/code/parser/chained_call.rb +3 -3
  8. data/lib/code/parser/class.rb +2 -3
  9. data/lib/code/parser/dictionnary.rb +13 -9
  10. data/lib/code/parser/equal.rb +1 -2
  11. data/lib/code/parser/equality.rb +1 -1
  12. data/lib/code/parser/function.rb +20 -11
  13. data/lib/code/parser/name.rb +14 -0
  14. data/lib/code/parser/negation.rb +1 -1
  15. data/lib/code/parser/operation.rb +15 -6
  16. data/lib/code/parser/or_operator.rb +1 -1
  17. data/lib/code/parser/power.rb +3 -3
  18. data/lib/code/parser/splat.rb +35 -0
  19. data/lib/template/parser.rb +1 -1
  20. data/spec/code/parser/addition_spec.rb +1 -1
  21. data/spec/code/parser/and_operator_spec.rb +1 -1
  22. data/spec/code/parser/bitwise_and_spec.rb +1 -1
  23. data/spec/code/parser/bitwise_or_spec.rb +1 -1
  24. data/spec/code/parser/boolean_spec.rb +1 -1
  25. data/spec/code/parser/call_spec.rb +1 -1
  26. data/spec/code/parser/chained_call_spec.rb +1 -1
  27. data/spec/code/parser/class_spec.rb +1 -1
  28. data/spec/code/parser/code_spec.rb +1 -1
  29. data/spec/code/parser/dictionnary_spec.rb +1 -1
  30. data/spec/code/parser/equal_spec.rb +1 -1
  31. data/spec/code/parser/equality_spec.rb +1 -1
  32. data/spec/code/parser/function_spec.rb +1 -1
  33. data/spec/code/parser/greater_than_spec.rb +1 -1
  34. data/spec/code/parser/group_spec.rb +1 -1
  35. data/spec/code/parser/if_modifier_spec.rb +1 -1
  36. data/spec/code/parser/if_spec.rb +1 -1
  37. data/spec/code/parser/list_spec.rb +1 -1
  38. data/spec/code/parser/multiplication_spec.rb +1 -1
  39. data/spec/code/parser/negation_spec.rb +1 -1
  40. data/spec/code/parser/not_keyword_spec.rb +1 -1
  41. data/spec/code/parser/nothing_spec.rb +1 -1
  42. data/spec/code/parser/number_spec.rb +1 -1
  43. data/spec/code/parser/or_keyword_spec.rb +1 -1
  44. data/spec/code/parser/or_operator_spec.rb +1 -1
  45. data/spec/code/parser/power_spec.rb +1 -1
  46. data/spec/code/parser/range_spec.rb +1 -1
  47. data/spec/code/parser/rescue_spec.rb +1 -1
  48. data/spec/code/parser/shift_spec.rb +1 -1
  49. data/spec/code/parser/string_spec.rb +1 -1
  50. data/spec/code/parser/ternary_spec.rb +1 -1
  51. data/spec/code/parser/unary_minus_spec.rb +1 -1
  52. data/spec/code/parser/while_spec.rb +1 -1
  53. data/spec/code/parser_spec.rb +13 -0
  54. metadata +8 -3
  55. data/lib/code/parser/identifier.rb +0 -40
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e0b771db0340e7e46f375f056056480d1b92ec6210fae8aa91025b3b10cdccad
4
- data.tar.gz: 71fff0149a4e017fc03e0b4b9798d23fb94c874c937f51b8ee89a3c752619cc9
3
+ metadata.gz: b15c16ff3280c0d1e95cb596d6996470d7addfe9fecdc706daa3b4e38ab6e8e1
4
+ data.tar.gz: 23b55a3ea3c729dc7fd62a19ff9ba1a2760a66f5781a9015fc2a9b3a3cee7131
5
5
  SHA512:
6
- metadata.gz: 6480f03895aa2958809b4d7cf849b2720de2d8eba33af43e2999db8d6609cb83936a4649e931da459dd376c489f9c8d4f0671cdb56a6a45706c931adc0fd9cff
7
- data.tar.gz: 3a51ac65786932de2ed2bd1c64f022e7a498e78233aea3085ffb6acd4f26970bcfb7ef3520078c7a94bdc7bf7f2c6e7d4d72a95155cac6e3b2c9d3ba9d84a6a8
6
+ metadata.gz: '077491d9fe0c1b251f8e576b9a444751b61faf061e5c7961ad3ae0540027a33fb5da0dfe4439c009c8f6eea5f0806344ea98d8dbb60e3ffa0b9a496fb231d213'
7
+ data.tar.gz: 83183df4672061421e1160d9203f6b7cdc9c967b39fcc2e3df376bd92aa0ab4b39a258539a0ee9ca400e43a5af3151f6645adc52a8aef6248e9df3b351cd5a7f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ### 0.1.3 - November 13, 2022
2
+
3
+ - Fix parsing &, *, **
4
+
1
5
  ### 0.1.2 - November 12, 2022
2
6
 
3
7
  - Fix parsing `&:even?`
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,35 @@
1
+ - Code
2
+ - Statement
3
+ - Class
4
+ - While
5
+ - If
6
+ - IfModifier
7
+ - OrKeyword
8
+ - NotKeyword
9
+ - Equal
10
+ - Rescue
11
+ - Ternary
12
+ - Range
13
+ - OrOperator
14
+ - AndOperator
15
+ - Equality
16
+ - GreaterThan
17
+ - BitwiseOr
18
+ - BitwiseAnd
19
+ - Shift
20
+ - Addition
21
+ - Multiplication
22
+ - UnaryMinus
23
+ - Power
24
+ - Negation
25
+ - Splat
26
+ - Function
27
+ - ChainedCall
28
+ - Dictionnary
29
+ - List
30
+ - String
31
+ - Number
32
+ - Boolean
33
+ - Nothing
34
+ - Group
35
+ - Call
@@ -5,7 +5,7 @@ class Code
5
5
  parse_subclass(
6
6
  ::Code::Parser::Operation,
7
7
  operators: [AMPERSAND + AMPERSAND],
8
- subclass: ::Code::Parser::GreaterThan
8
+ subclass: ::Code::Parser::Equality
9
9
  )
10
10
  end
11
11
  end
@@ -2,8 +2,8 @@ class Code
2
2
  class Parser
3
3
  class Call < ::Code::Parser
4
4
  def parse
5
- identifier = parse_subclass(::Code::Parser::Identifier)
6
- return unless identifier
5
+ name = parse_subclass(::Code::Parser::Name)
6
+ return unless name
7
7
 
8
8
  if match(OPENING_PARENTHESIS)
9
9
  arguments = []
@@ -38,7 +38,7 @@ class Code
38
38
 
39
39
  {
40
40
  call: {
41
- identifier: identifier,
41
+ name: name,
42
42
  arguments: arguments,
43
43
  block: block,
44
44
  comments: comments
@@ -106,18 +106,18 @@ class Code
106
106
  previous_cursor = cursor
107
107
 
108
108
  comments_before = parse_comments
109
- key = parse_subclass(::Code::Parser::Identifier)
109
+ name = parse_subclass(::Code::Parser::Name)
110
110
  comments_after = parse_comments
111
111
 
112
- if key && match(COLON) || match(EQUAL + GREATER)
112
+ if name && match(COLON) || match(EQUAL + GREATER)
113
113
  default = parse_default
114
114
 
115
115
  {
116
- comments_before: comments_before,
117
- comments_after: comments_after,
116
+ kind: :keyword,
117
+ name: name,
118
118
  default: default,
119
- keyword: true,
120
- identifier: key
119
+ comments_before: comments_before,
120
+ comments_after: comments_after
121
121
  }.compact
122
122
  else
123
123
  @cursor = previous_cursor
@@ -129,26 +129,35 @@ class Code
129
129
  def parse_regular_parameter
130
130
  previous_cursor = cursor
131
131
  comments_before = parse_comments
132
- identifier = parse_subclass(::Code::Parser::Identifier)
133
- if identifier
132
+
133
+ if match(AMPERSAND)
134
+ kind = :block
135
+ elsif match(ASTERISK + ASTERISK)
136
+ kind = :keyword_splat
137
+ elsif match(ASTERISK)
138
+ kind = :regular_splat
139
+ else
140
+ kind = nil
141
+ end
142
+
143
+ name = parse_subclass(::Code::Parser::Name)
144
+
145
+ if name
134
146
  comments_after = parse_comments
135
147
 
136
148
  if match(EQUAL)
137
149
  default = parse_default
138
-
139
- {
140
- comments_before: comments_before,
141
- comments_after: comments_after,
142
- default: default,
143
- identifier: identifier
144
- }.compact
145
150
  else
146
- {
147
- comments_before: comments_before,
148
- comments_after: comments_after,
149
- identifier: identifier
150
- }.compact
151
+ default = nil
151
152
  end
153
+
154
+ {
155
+ comments_before: comments_before,
156
+ comments_after: comments_after,
157
+ default: default,
158
+ name: name,
159
+ kind: kind
160
+ }.compact
152
161
  else
153
162
  @cursor = previous_cursor
154
163
  buffer!
@@ -162,8 +171,8 @@ class Code
162
171
  comments_after = parse_comments
163
172
 
164
173
  default = {
165
- comments_before: comments_before,
166
174
  statement: statement,
175
+ comments_before: comments_before,
167
176
  comments_after: comments_after
168
177
  }.compact
169
178
 
@@ -2,8 +2,8 @@ class Code
2
2
  class Parser
3
3
  class ChainedCall < ::Code::Parser
4
4
  def parse
5
- previous_cursor = cursor
6
5
  left = parse_dictionnary
6
+ previous_cursor = cursor
7
7
  comments_before = parse_comments
8
8
 
9
9
  if left && match([DOT, COLON + COLON])
@@ -24,12 +24,12 @@ class Code
24
24
  else
25
25
  @cursor = previous_cursor
26
26
  buffer!
27
- parse_dictionnary
27
+ left
28
28
  end
29
29
  else
30
30
  @cursor = previous_cursor
31
31
  buffer!
32
- parse_dictionnary
32
+ left
33
33
  end
34
34
  end
35
35
 
@@ -7,7 +7,7 @@ class Code
7
7
  if match(CLASS_KEYWORD)
8
8
  first_comments = parse_comments
9
9
 
10
- name = parse_subclass(::Code::Parser::Identifier, simple: true)
10
+ name = parse_subclass(::Code::Parser::Name)
11
11
 
12
12
  if name
13
13
  second_comments = parse_comments
@@ -15,8 +15,7 @@ class Code
15
15
  if match(LESSER)
16
16
  previous_cursor = cursor
17
17
  third_comments = parse_comments
18
- superclass =
19
- parse_subclass(::Code::Parser::Identifier, simple: true)
18
+ superclass = parse_subclass(::Code::Parser::Name)
20
19
 
21
20
  if !superclass
22
21
  @cursor = previous_cursor
@@ -13,34 +13,38 @@ class Code
13
13
 
14
14
  match(CLOSING_CURLY_BRACKET)
15
15
 
16
- { dictionnary: dictionnary.compact, comments: comments }
16
+ { dictionnary: dictionnary.compact, comments: comments }.compact
17
17
  else
18
18
  parse_subclass(::Code::Parser::List)
19
19
  end
20
20
  end
21
21
 
22
22
  def parse_key_value
23
+ previous_cursor = cursor
24
+
23
25
  comments_before = parse_comments
24
26
 
25
27
  key = parse_subclass(::Code::Parser::Statement)
26
28
 
27
29
  comments_after = parse_comments
28
30
 
29
- return unless key
31
+ if key
32
+ if match(COLON) || match(EQUAL + GREATER)
33
+ value = parse_code
34
+ else
35
+ value = nil
36
+ end
30
37
 
31
- if match(COLON) || match(EQUAL + GREATER)
32
38
  {
33
39
  key: key,
34
- value: parse_code,
40
+ value: value,
35
41
  comments_before: comments_before,
36
42
  comments_after: comments_after
37
43
  }.compact
38
44
  else
39
- {
40
- key: key,
41
- comments_before: comments_before,
42
- comments_after: comments_after
43
- }.compact
45
+ @cursor = previous_cursor
46
+ buffer!
47
+ return
44
48
  end
45
49
  end
46
50
  end
@@ -9,7 +9,6 @@ class Code
9
9
  comments_before = parse_comments
10
10
 
11
11
  if operator = match(EQUALS)
12
- previous_cursor = cursor
13
12
  comments_after = parse_comments
14
13
 
15
14
  right = parse_subclass(::Code::Parser::Equal)
@@ -26,7 +25,7 @@ class Code
26
25
  else
27
26
  @cursor = previous_cursor
28
27
  buffer!
29
- { equal: { left: left, comments_before: comments_before } }
28
+ left
30
29
  end
31
30
  else
32
31
  @cursor = previous_cursor
@@ -12,7 +12,7 @@ class Code
12
12
  EQUAL + EQUAL,
13
13
  EXCLAMATION_POINT + EQUAL
14
14
  ],
15
- subclass: ::Code::Parser::While
15
+ subclass: ::Code::Parser::GreaterThan
16
16
  )
17
17
  end
18
18
  end
@@ -55,20 +55,18 @@ class Code
55
55
  previous_cursor = cursor
56
56
 
57
57
  comments_before = parse_comments
58
-
59
- key = parse_subclass(::Code::Parser::Identifier)
60
-
58
+ name = parse_subclass(::Code::Parser::Name)
61
59
  comments_after = parse_comments
62
60
 
63
- if key && (match(COLON) || match(EQUAL + GREATER))
61
+ if name && (match(COLON) || match(EQUAL + GREATER))
64
62
  default = parse_code
65
63
 
66
64
  {
65
+ kind: :keyword,
66
+ name: name,
67
67
  default: default,
68
- keyword: true,
69
68
  comments_before: comments_before,
70
- comments_after: comments_after,
71
- identifier: key
69
+ comments_after: comments_after
72
70
  }.compact
73
71
  else
74
72
  @cursor = previous_cursor
@@ -79,13 +77,23 @@ class Code
79
77
 
80
78
  def parse_regular_parameter
81
79
  previous_cursor = cursor
80
+
82
81
  comments_before = parse_comments
83
82
 
84
- identifier = parse_subclass(::Code::Parser::Identifier)
83
+ if match(AMPERSAND)
84
+ kind = :block
85
+ elsif match(ASTERISK + ASTERISK)
86
+ kind = :keyword_splat
87
+ elsif match(ASTERISK)
88
+ kind = :regular_splat
89
+ else
90
+ kind = nil
91
+ end
85
92
 
93
+ name = parse_subclass(::Code::Parser::Name)
86
94
  comments_after = parse_comments
87
95
 
88
- if identifier
96
+ if name
89
97
  if match(EQUAL)
90
98
  default = parse_code
91
99
  else
@@ -93,10 +101,11 @@ class Code
93
101
  end
94
102
 
95
103
  {
104
+ kind: kind,
105
+ name: name,
96
106
  default: default,
97
107
  comments_before: comments_before,
98
- comments_after: comments_after,
99
- identifier: identifier
108
+ comments_after: comments_after
100
109
  }.compact
101
110
  else
102
111
  @cursor = previous_cursor
@@ -0,0 +1,14 @@
1
+ class Code
2
+ class Parser
3
+ class Name < ::Code::Parser
4
+ def parse
5
+ return if end_of_input?
6
+ return if next?(SPECIAL)
7
+ return if next?(KEYWORDS)
8
+ consume while !next?(SPECIAL) && !end_of_input?
9
+ match(QUESTION_MARK) || match(EXCLAMATION_POINT)
10
+ buffer!
11
+ end
12
+ end
13
+ end
14
+ end
@@ -10,7 +10,7 @@ class Code
10
10
  }
11
11
  }
12
12
  else
13
- parse_subclass(::Code::Parser::Function)
13
+ parse_subclass(::Code::Parser::Splat)
14
14
  end
15
15
  end
16
16
  end
@@ -12,17 +12,21 @@ class Code
12
12
  previous_cursor = cursor
13
13
  left = parse_subclass(subclass)
14
14
  if left
15
- right = []
16
15
  previous_cursor = cursor
17
16
  comments = parse_comments
17
+ right = []
18
18
 
19
19
  while operator = match(operators)
20
- comments = parse_comments
20
+ comments_before = parse_comments
21
21
  statement = parse_subclass(subclass)
22
+ previous_cursor = cursor
23
+ comments_after = parse_comments
24
+
22
25
  right << {
23
- comments: comments,
24
26
  statement: statement,
25
- operator: operator
27
+ operator: operator,
28
+ comments_before: comments_before,
29
+ comments_after: comments_after
26
30
  }.compact
27
31
  end
28
32
 
@@ -31,11 +35,16 @@ class Code
31
35
  buffer!
32
36
  left
33
37
  else
38
+ @cursor = previous_cursor
39
+ buffer!
40
+
41
+ right[-1].delete(:comments_after)
42
+
34
43
  {
35
44
  operation: {
36
45
  left: left,
37
- comments: comments,
38
- right: right
46
+ right: right,
47
+ comments: comments
39
48
  }.compact
40
49
  }
41
50
  end
@@ -5,7 +5,7 @@ class Code
5
5
  parse_subclass(
6
6
  ::Code::Parser::Operation,
7
7
  operators: [PIPE + PIPE],
8
- subclass: ::Code::Parser::GreaterThan
8
+ subclass: ::Code::Parser::AndOperator
9
9
  )
10
10
  end
11
11
  end
@@ -2,8 +2,8 @@ class Code
2
2
  class Parser
3
3
  class Power < ::Code::Parser
4
4
  def parse
5
- previous_cursor = cursor
6
5
  left = parse_subclass(::Code::Parser::Negation)
6
+ previous_cursor = cursor
7
7
  comments_before = parse_comments
8
8
  if match(ASTERISK + ASTERISK)
9
9
  comments_after = parse_comments
@@ -20,12 +20,12 @@ class Code
20
20
  else
21
21
  @cursor = previous_cursor
22
22
  buffer!
23
- parse_subclass(::Code::Parser::Negation)
23
+ left
24
24
  end
25
25
  else
26
26
  @cursor = previous_cursor
27
27
  buffer!
28
- parse_subclass(::Code::Parser::Negation)
28
+ left
29
29
  end
30
30
  end
31
31
  end
@@ -0,0 +1,35 @@
1
+ class Code
2
+ class Parser
3
+ class Splat < ::Code::Parser
4
+ def parse
5
+ previous_cursor = cursor
6
+
7
+ if operator = match([AMPERSAND, ASTERISK + ASTERISK, ASTERISK])
8
+ comments = parse_comments
9
+ right = parse_next
10
+ if right
11
+ {
12
+ splat: {
13
+ right: right,
14
+ operator: operator,
15
+ comments: comments
16
+ }.compact
17
+ }
18
+ else
19
+ @cursor = previous_cursor
20
+ buffer!
21
+ parse_next
22
+ end
23
+ else
24
+ parse_next
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def parse_next
31
+ parse_subclass(::Code::Parser::Function)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,6 +1,6 @@
1
1
  class Template
2
2
  class Parser < ::Code::Parser
3
- Version = Gem::Version.new("0.1.2")
3
+ Version = Gem::Version.new("0.1.3")
4
4
 
5
5
  def parse
6
6
  parts = []
@@ -7,7 +7,7 @@ RSpec.describe ::Code::Parser do
7
7
  context input do
8
8
  let!(:input) { input }
9
9
 
10
- it { expect { subject }.to_not raise_error }
10
+ it { subject }
11
11
  end
12
12
  end
13
13
 
@@ -7,7 +7,7 @@ RSpec.describe ::Code::Parser do
7
7
  context input do
8
8
  let!(:input) { input }
9
9
 
10
- it { expect { subject }.to_not raise_error }
10
+ it { subject }
11
11
  end
12
12
  end
13
13
 
@@ -7,7 +7,7 @@ RSpec.describe ::Code::Parser do
7
7
  context input do
8
8
  let!(:input) { input }
9
9
 
10
- it { expect { subject }.to_not raise_error }
10
+ it { subject }
11
11
  end
12
12
  end
13
13
 
@@ -7,7 +7,7 @@ RSpec.describe ::Code::Parser do
7
7
  context input do
8
8
  let!(:input) { input }
9
9
 
10
- it { expect { subject }.to_not raise_error }
10
+ it { subject }
11
11
  end
12
12
  end
13
13
 
@@ -7,7 +7,7 @@ RSpec.describe ::Code::Parser do
7
7
  context input do
8
8
  let!(:input) { input }
9
9
 
10
- it { expect { subject }.to_not raise_error }
10
+ it { subject }
11
11
  end
12
12
  end
13
13
  end
@@ -22,7 +22,7 @@ RSpec.describe ::Code::Parser do
22
22
  context input do
23
23
  let!(:input) { input }
24
24
 
25
- it { expect { subject }.to_not raise_error }
25
+ it { subject }
26
26
  end
27
27
  end
28
28
 
@@ -15,7 +15,7 @@ RSpec.describe ::Code::Parser do
15
15
  context input do
16
16
  let!(:input) { input }
17
17
 
18
- it { expect { subject }.to_not raise_error }
18
+ it { subject }
19
19
  end
20
20
  end
21
21
 
@@ -14,7 +14,7 @@ RSpec.describe ::Code::Parser do
14
14
  context input do
15
15
  let!(:input) { input }
16
16
 
17
- it { expect { subject }.to_not raise_error }
17
+ it { subject }
18
18
  end
19
19
  end
20
20
 
@@ -7,7 +7,7 @@ RSpec.describe ::Code::Parser do
7
7
  context input do
8
8
  let!(:input) { input }
9
9
 
10
- it { expect { subject }.to_not raise_error }
10
+ it { subject }
11
11
  end
12
12
  end
13
13
  end
@@ -14,7 +14,7 @@ RSpec.describe ::Code::Parser do
14
14
  context input do
15
15
  let!(:input) { input }
16
16
 
17
- it { expect { subject }.to_not raise_error }
17
+ it { subject }
18
18
  end
19
19
  end
20
20
 
@@ -23,7 +23,7 @@ RSpec.describe ::Code::Parser do
23
23
  context input do
24
24
  let!(:input) { input }
25
25
 
26
- it { expect { subject }.to_not raise_error }
26
+ it { subject }
27
27
  end
28
28
  end
29
29
 
@@ -7,7 +7,7 @@ RSpec.describe ::Code::Parser do
7
7
  context input do
8
8
  let!(:input) { input }
9
9
 
10
- it { expect { subject }.to_not raise_error }
10
+ it { subject }
11
11
  end
12
12
  end
13
13
 
@@ -13,7 +13,7 @@ RSpec.describe ::Code::Parser do
13
13
  context input do
14
14
  let!(:input) { input }
15
15
 
16
- it { expect { subject }.to_not raise_error }
16
+ it { subject }
17
17
  end
18
18
  end
19
19
 
@@ -7,7 +7,7 @@ RSpec.describe ::Code::Parser do
7
7
  context input do
8
8
  let!(:input) { input }
9
9
 
10
- it { expect { subject }.to_not raise_error }
10
+ it { subject }
11
11
  end
12
12
  end
13
13
 
@@ -7,7 +7,7 @@ RSpec.describe ::Code::Parser do
7
7
  context input do
8
8
  let!(:input) { input }
9
9
 
10
- it { expect { subject }.to_not raise_error }
10
+ it { subject }
11
11
  end
12
12
  end
13
13
  end
@@ -7,7 +7,7 @@ RSpec.describe ::Code::Parser do
7
7
  context input do
8
8
  let!(:input) { input }
9
9
 
10
- it { expect { subject }.to_not raise_error }
10
+ it { subject }
11
11
  end
12
12
  end
13
13
 
@@ -16,7 +16,7 @@ RSpec.describe ::Code::Parser do
16
16
  context input do
17
17
  let!(:input) { input }
18
18
 
19
- it { expect { subject }.to_not raise_error }
19
+ it { subject }
20
20
  end
21
21
  end
22
22
 
@@ -7,7 +7,7 @@ RSpec.describe ::Code::Parser do
7
7
  context input do
8
8
  let!(:input) { input }
9
9
 
10
- it { expect { subject }.to_not raise_error }
10
+ it { subject }
11
11
  end
12
12
  end
13
13
 
@@ -7,7 +7,7 @@ RSpec.describe ::Code::Parser do
7
7
  context input do
8
8
  let!(:input) { input }
9
9
 
10
- it { expect { subject }.to_not raise_error }
10
+ it { subject }
11
11
  end
12
12
  end
13
13
 
@@ -7,7 +7,7 @@ RSpec.describe ::Code::Parser do
7
7
  context input do
8
8
  let!(:input) { input }
9
9
 
10
- it { expect { subject }.to_not raise_error }
10
+ it { subject }
11
11
  end
12
12
  end
13
13
  end
@@ -7,7 +7,7 @@ RSpec.describe ::Code::Parser do
7
7
  context input do
8
8
  let!(:input) { input }
9
9
 
10
- it { expect { subject }.to_not raise_error }
10
+ it { subject }
11
11
  end
12
12
  end
13
13
 
@@ -14,7 +14,7 @@ RSpec.describe ::Code::Parser do
14
14
  context input do
15
15
  let!(:input) { input }
16
16
 
17
- it { expect { subject }.to_not raise_error }
17
+ it { subject }
18
18
  end
19
19
  end
20
20
  end
@@ -18,7 +18,7 @@ RSpec.describe ::Code::Parser do
18
18
  context input do
19
19
  let!(:input) { input }
20
20
 
21
- it { expect { subject }.to_not raise_error }
21
+ it { subject }
22
22
  end
23
23
  end
24
24
  end
@@ -7,7 +7,7 @@ RSpec.describe ::Code::Parser do
7
7
  context input do
8
8
  let!(:input) { input }
9
9
 
10
- it { expect { subject }.to_not raise_error }
10
+ it { subject }
11
11
  end
12
12
  end
13
13
 
@@ -7,7 +7,7 @@ RSpec.describe ::Code::Parser do
7
7
  context input do
8
8
  let!(:input) { input }
9
9
 
10
- it { expect { subject }.to_not raise_error }
10
+ it { subject }
11
11
  end
12
12
  end
13
13
 
@@ -7,7 +7,7 @@ RSpec.describe ::Code::Parser do
7
7
  context input do
8
8
  let!(:input) { input }
9
9
 
10
- it { expect { subject }.to_not raise_error }
10
+ it { subject }
11
11
  end
12
12
  end
13
13
 
@@ -7,7 +7,7 @@ RSpec.describe ::Code::Parser do
7
7
  context input do
8
8
  let!(:input) { input }
9
9
 
10
- it { expect { subject }.to_not raise_error }
10
+ it { subject }
11
11
  end
12
12
  end
13
13
 
@@ -7,7 +7,7 @@ RSpec.describe ::Code::Parser do
7
7
  context input do
8
8
  let!(:input) { input }
9
9
 
10
- it { expect { subject }.to_not raise_error }
10
+ it { subject }
11
11
  end
12
12
  end
13
13
 
@@ -7,7 +7,7 @@ RSpec.describe ::Code::Parser do
7
7
  context input do
8
8
  let!(:input) { input }
9
9
 
10
- it { expect { subject }.to_not raise_error }
10
+ it { subject }
11
11
  end
12
12
  end
13
13
 
@@ -22,7 +22,7 @@ RSpec.describe ::Code::Parser do
22
22
  context input do
23
23
  let!(:input) { input }
24
24
 
25
- it { expect { subject }.to_not raise_error }
25
+ it { subject }
26
26
  end
27
27
  end
28
28
  end
@@ -7,7 +7,7 @@ RSpec.describe ::Code::Parser do
7
7
  context input do
8
8
  let!(:input) { input }
9
9
 
10
- it { expect { subject }.to_not raise_error }
10
+ it { subject }
11
11
  end
12
12
  end
13
13
 
@@ -7,7 +7,7 @@ RSpec.describe ::Code::Parser do
7
7
  context input do
8
8
  let!(:input) { input }
9
9
 
10
- it { expect { subject }.to_not raise_error }
10
+ it { subject }
11
11
  end
12
12
  end
13
13
 
@@ -14,7 +14,7 @@ RSpec.describe ::Code::Parser do
14
14
  context input do
15
15
  let!(:input) { input }
16
16
 
17
- it { expect { subject }.to_not raise_error }
17
+ it { subject }
18
18
  end
19
19
  end
20
20
 
@@ -0,0 +1,13 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe ::Code::Parser do
4
+ subject { ::Code::Parser.parse(input) }
5
+
6
+ ["(1..2).any?(&:even?)"].each do |input|
7
+ context input do
8
+ let!(:input) { input }
9
+
10
+ it { subject }
11
+ end
12
+ end
13
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code-ruby-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Marié
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-12 00:00:00.000000000 Z
11
+ date: 2022-11-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A parser for the Code programming language, like 1 + 1 and user.first_name
14
14
  email: dorian@dorianmarie.fr
@@ -28,6 +28,8 @@ files:
28
28
  - code-ruby-parser.gemspec
29
29
  - docs/class.code
30
30
  - docs/meetup.code
31
+ - docs/precedence.code
32
+ - docs/precedence.template
31
33
  - docs/rain.code
32
34
  - docs/slack.code
33
35
  - docs/stripe.code
@@ -53,11 +55,11 @@ files:
53
55
  - lib/code/parser/function.rb
54
56
  - lib/code/parser/greater_than.rb
55
57
  - lib/code/parser/group.rb
56
- - lib/code/parser/identifier.rb
57
58
  - lib/code/parser/if.rb
58
59
  - lib/code/parser/if_modifier.rb
59
60
  - lib/code/parser/list.rb
60
61
  - lib/code/parser/multiplication.rb
62
+ - lib/code/parser/name.rb
61
63
  - lib/code/parser/negation.rb
62
64
  - lib/code/parser/not_keyword.rb
63
65
  - lib/code/parser/nothing.rb
@@ -69,6 +71,7 @@ files:
69
71
  - lib/code/parser/range.rb
70
72
  - lib/code/parser/rescue.rb
71
73
  - lib/code/parser/shift.rb
74
+ - lib/code/parser/splat.rb
72
75
  - lib/code/parser/statement.rb
73
76
  - lib/code/parser/string.rb
74
77
  - lib/code/parser/ternary.rb
@@ -110,6 +113,7 @@ files:
110
113
  - spec/code/parser/ternary_spec.rb
111
114
  - spec/code/parser/unary_minus_spec.rb
112
115
  - spec/code/parser/while_spec.rb
116
+ - spec/code/parser_spec.rb
113
117
  - spec/spec_helper.rb
114
118
  - spec/template/parser_spec.rb
115
119
  - template-ruby-parser.gemspec
@@ -170,5 +174,6 @@ test_files:
170
174
  - spec/code/parser/ternary_spec.rb
171
175
  - spec/code/parser/unary_minus_spec.rb
172
176
  - spec/code/parser/while_spec.rb
177
+ - spec/code/parser_spec.rb
173
178
  - spec/spec_helper.rb
174
179
  - spec/template/parser_spec.rb
@@ -1,40 +0,0 @@
1
- class Code
2
- class Parser
3
- class Identifier < ::Code::Parser
4
- def initialize(input, simple: false, **kargs)
5
- super(input, **kargs)
6
- @simple = simple
7
- end
8
-
9
- def parse
10
- return if end_of_input?
11
-
12
- if !simple? && match(AMPERSAND)
13
- { block: parse_subclass(::Code::Parser::Statement) }
14
- elsif !simple && match(ASTERISK + ASTERISK)
15
- { keyword_splat: parse_subclass(::Code::Parser::Statement) }
16
- elsif !simple? && match(ASTERISK)
17
- { regular_splat: parse_subclass(::Code::Parser::Statement) }
18
- elsif !next?(SPECIAL) && !next?(KEYWORDS)
19
- consume while !next?(SPECIAL) && !end_of_input?
20
-
21
- match(QUESTION_MARK) || match(EXCLAMATION_POINT) if !simple?
22
-
23
- name = buffer!
24
-
25
- { name: name }
26
- else
27
- return
28
- end
29
- end
30
-
31
- private
32
-
33
- attr_reader :simple
34
-
35
- def simple?
36
- !!simple
37
- end
38
- end
39
- end
40
- end