loxxy 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e4f33203580d2b83ee7139e449787b439c0fb56c5a8c3dcc8035d114ffd957d3
4
- data.tar.gz: 46c9fb2f55849c6aa9b9e4d58588746ddb3ac3353f7ed09922d9394a9fc512c6
3
+ metadata.gz: 583f5c2f620ea8f45b339607103955eda2f32c02f0358ccb88cf4d20b4398d21
4
+ data.tar.gz: f349b949c1315473027eaaab589ff1cf2da89deca3b243cd1508c088bf9a9cc5
5
5
  SHA512:
6
- metadata.gz: 30f554af6338b50297ce6befaa62c86c8406df681e25098cc95dc28da64bb6feabbb9e085846eb8032f51d8d3655332105eb1d7165903bbd0d6be24cb13c4d0b
7
- data.tar.gz: d9d9a69a010d16807f6c4bf24b15e8135367bb62b6d2e052943e0d6030751f282c777f652dd3fced08093aee8abae228e63d365cae156fa6e87ac7f52fc7e2e6
6
+ metadata.gz: 9c93648c634783348a22b3b65cf710a59c0ca5e3cefc5a20d7c60b9b429b4334e1e5603cc2bf74f302aed881daa71634cb7253445b3f376838197637f79f8cc7
7
+ data.tar.gz: 67d60e89985322911a7842a2b5fc2e22b4ccc3136ffa216027089ea05ea56a6932d1de9b8917173ad072695aaa6abb2147d456f54d09f2878d7831937c42af74
@@ -1,3 +1,15 @@
1
+ ## [0.0.11] - 2021-01-08
2
+ - AST node generation for logical expression (and, or).
3
+
4
+ ## Changed
5
+ - Class `AST::ASTBuilder` added `reduce_` methods for logical operations.
6
+ - File `grammar.rb`added name to logical expression rules
7
+ - File `README.md` added gem version and license badges, expanded roadmap section.
8
+
9
+ ## Fixed
10
+ - File `grammar.rb`: a rule had incomplete non-terminal name `conjunct_` in its lhs.
11
+
12
+
1
13
  ## [0.0.10] - 2021-01-08
2
14
  - AST node generation for equality expression.
3
15
 
data/README.md CHANGED
@@ -35,7 +35,7 @@ The __loxxy__ gem hosts two distinct parsers classes (`RawParser` and `Parser`).
35
35
  AST Node generation
36
36
  Goal: parser should generate AST for any input Lox program
37
37
  - [X] Equality operator
38
- - [] Logical operator (and, or)
38
+ - [X] Logical operator (and, or)
39
39
  - [] Unary expressions (negate, not)
40
40
  - [] Grouping expressions
41
41
  - [] Print statement
@@ -117,6 +117,36 @@ module Loxxy
117
117
  [[operator, operand2]]
118
118
  end
119
119
 
120
+ # rule('logic_or' => 'logic_and disjunct_plus')
121
+ def reduce_logic_or_plus(production, range, tokens, theChildren)
122
+ reduce_binary_operator(production, range, tokens, theChildren)
123
+ end
124
+
125
+ # rule('disjunct_plus' => 'disjunct_plus OR logic_and')
126
+ def reduce_logic_or_plus_more(production, range, tokens, theChildren)
127
+ reduce_binary_plus_more(production, range, tokens, theChildren)
128
+ end
129
+
130
+ # rule('disjunct_plus' => 'OR logic_and')
131
+ def reduce_logic_or_plus_end(production, range, tokens, theChildren)
132
+ reduce_binary_plus_end(production, range, tokens, theChildren)
133
+ end
134
+
135
+ # rule('logic_and' => 'equality conjunct_plus')
136
+ def reduce_logic_and_plus(production, range, tokens, theChildren)
137
+ reduce_binary_operator(production, range, tokens, theChildren)
138
+ end
139
+
140
+ # rule('conjunct_plus' => 'conjunct_plus AND equality')
141
+ def reduce_logic_and_plus_more(production, range, tokens, theChildren)
142
+ reduce_binary_plus_more(production, range, tokens, theChildren)
143
+ end
144
+
145
+ # rule('conjunct_plus' => 'AND equality')
146
+ def reduce_logic_and_plus_end(production, range, tokens, theChildren)
147
+ reduce_binary_plus_end(production, range, tokens, theChildren)
148
+ end
149
+
120
150
  # rule('equality' => 'comparison equalityTest_plus')
121
151
  def reduce_equality_plus(production, range, tokens, theChildren)
122
152
  reduce_binary_operator(production, range, tokens, theChildren)
@@ -88,13 +88,13 @@ module Loxxy
88
88
  rule('owner_opt' => 'call DOT')
89
89
  rule('owner_opt' => [])
90
90
  rule('logic_or' => 'logic_and')
91
- rule('logic_or' => 'logic_and disjunct_plus')
92
- rule('disjunct_plus' => 'disjunct_plus OR logic_and')
93
- rule('disjunct_plus' => 'OR logic_and')
91
+ rule('logic_or' => 'logic_and disjunct_plus').as 'logic_or_plus'
92
+ rule('disjunct_plus' => 'disjunct_plus OR logic_and').as 'logic_or_plus_more'
93
+ rule('disjunct_plus' => 'OR logic_and').as 'logic_or_plus_end'
94
94
  rule('logic_and' => 'equality')
95
- rule('logic_and' => 'equality conjunct_plus')
96
- rule('conjunct_plus' => 'conjunct_plus AND equality')
97
- rule('conjunct_' => 'AND equality')
95
+ rule('logic_and' => 'equality conjunct_plus').as 'logic_and_plus'
96
+ rule('conjunct_plus' => 'conjunct_plus AND equality').as 'logic_and_plus_more'
97
+ rule('conjunct_plus' => 'AND equality').as 'logic_and_plus_end'
98
98
  rule('equality' => 'comparison')
99
99
  rule('equality' => 'comparison equalityTest_plus').as 'equality_plus'
100
100
  rule('equalityTest_plus' => 'equalityTest_plus equalityTest comparison').as 'equality_t_plus_more'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Loxxy
4
- VERSION = '0.0.10'
4
+ VERSION = '0.0.11'
5
5
  end
@@ -303,6 +303,55 @@ LOX_END
303
303
  expect(expr.operands[1].literal.value).to be_falsey
304
304
  end
305
305
  end # context
306
+
307
+ context 'Parsing logical expressions' do
308
+ it 'should parse the logical operations betweentwo sub-expression' do
309
+ %w[or and].each do |connector|
310
+ input = "5 > 2 #{connector} 3 <= 4;"
311
+ ptree = subject.parse(input)
312
+ parent = ptree.root.subnodes[0]
313
+ expect(parent).to be_kind_of(Rley::PTree::NonTerminalNode)
314
+ expect(parent.symbol.name).to eq('exprStmt')
315
+ expr = parent.subnodes[0]
316
+ expect(expr).to be_kind_of(Ast::LoxBinaryExpr)
317
+ expect(expr.operator).to eq(connector.to_sym)
318
+ expect(expr.operands[0]).to be_kind_of(Ast::LoxBinaryExpr)
319
+ expect(expr.operands[0].operator).to eq(:>)
320
+ expect(expr.operands[0].operands[0].literal.value).to eq(5)
321
+ expect(expr.operands[0].operands[1].literal.value).to eq(2)
322
+ expect(expr.operands[1]).to be_kind_of(Ast::LoxBinaryExpr)
323
+ expect(expr.operands[1].operator).to eq(:<=)
324
+ expect(expr.operands[1].operands[0].literal.value).to eq(3)
325
+ expect(expr.operands[1].operands[1].literal.value).to eq(4)
326
+ end
327
+ end
328
+
329
+ it 'should parse a combinations of logical expressions' do
330
+ input = '4 > 3 and 1 < 2 or 4 >= 5;'
331
+ ptree = subject.parse(input)
332
+ parent = ptree.root.subnodes[0]
333
+ expect(parent).to be_kind_of(Rley::PTree::NonTerminalNode)
334
+ expect(parent.symbol.name).to eq('exprStmt')
335
+ expr = parent.subnodes[0]
336
+ expect(expr).to be_kind_of(Ast::LoxBinaryExpr)
337
+ expect(expr.operator).to eq(:or) # or has lower precedence than and
338
+ expect(expr.operands[0]).to be_kind_of(Ast::LoxBinaryExpr)
339
+ expect(expr.operands[0].operator).to eq(:and)
340
+ conjuncts = expr.operands[0].operands
341
+ expect(conjuncts[0]).to be_kind_of(Ast::LoxBinaryExpr)
342
+ expect(conjuncts[0].operator).to eq(:>)
343
+ expect(conjuncts[0].operands[0].literal.value).to eq(4)
344
+ expect(conjuncts[0].operands[1].literal.value).to eq(3)
345
+ expect(conjuncts[1]).to be_kind_of(Ast::LoxBinaryExpr)
346
+ expect(conjuncts[1].operator).to eq(:<)
347
+ expect(conjuncts[1].operands[0].literal.value).to eq(1)
348
+ expect(conjuncts[1].operands[1].literal.value).to eq(2)
349
+ expect(expr.operands[1]).to be_kind_of(Ast::LoxBinaryExpr)
350
+ expect(expr.operands[1].operator).to eq(:>=)
351
+ expect(expr.operands[1].operands[0].literal.value).to eq(4)
352
+ expect(expr.operands[1].operands[1].literal.value).to eq(5)
353
+ end
354
+ end # context
306
355
  end # describe
307
356
  end # module
308
357
  end # module
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loxxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitri Geshef