bool 1.0.14-java → 1.0.15-java

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
  SHA1:
3
- metadata.gz: a6525d665c03b835411b27c11fcee59715f7c7bf
4
- data.tar.gz: ae27b0e0560f4e5a6300b3d08f04cf5f016043cf
3
+ metadata.gz: 5342f4b1b2dc7581b554c8d34f81d1b6a1983ce2
4
+ data.tar.gz: 6d382073a0589287a004c01a168758d091376511
5
5
  SHA512:
6
- metadata.gz: 5b824781a4d2875e8677aa5a30ef281925a01ba49223f26bb3b60c7bf8ce6831e003b7e62216decde2c56017a9060749822392f5d131e3ea2db2348bc3896561
7
- data.tar.gz: 5ddeb11b2d0e2380119a3cd0940ddfa20ec308a5fae7f84508b1616f2574364c8aeaedfff353e413b951e88bbd025506af6559e2f0f6e5cefec234062fef2dbd
6
+ metadata.gz: 4c3184884662028e84bed61bf4f46070b8b6165fdbb90f3f37d93416bef0766c90ede6e3000f242ea54d766db8a8912621e9abb8afc7211f1fc4b0d0660483e5
7
+ data.tar.gz: c784bb5129c6c4143574cfeee2fa1bc56dbb47846225f1f180e3864873e84b83e39fe0130c3cabc6e2c5c5b3bf948911d5970ddb48120fa8454219857261a03b
@@ -7,11 +7,11 @@ require 'bool/renderer'
7
7
 
8
8
  module Bool
9
9
  class SyntaxError < StandardError
10
- attr_reader :first_line, :last_line, :first_column, :last_column
10
+ attr_reader :token
11
11
 
12
- def initialize(message, first_line, last_line, first_column, last_column)
12
+ def initialize(message, token)
13
13
  super(message)
14
- @first_line, @last_line, @first_column, @last_column = first_line, last_line, first_column, last_column
14
+ @token = token
15
15
  end
16
16
  end
17
17
 
@@ -19,9 +19,9 @@ module Bool
19
19
  def parse(source)
20
20
  lexer = Java::Bool::Lexer.new(source)
21
21
  parser = Java::Bool::Parser.new(lexer)
22
- parser.parseExpr()
22
+ parser.buildAst()
23
23
  rescue => e
24
- raise SyntaxError.new(e.message, e.line, e.line, e.column, e.column)
24
+ raise SyntaxError.new(e.message, e.token)
25
25
  end
26
26
  module_function(:parse)
27
27
  else
@@ -2,22 +2,33 @@ module Bool
2
2
  if RUBY_PLATFORM =~ /java/
3
3
  # AST classes defined in bool_ext.jar
4
4
  else
5
- class Var
6
- attr_reader :name
5
+ class Token
6
+ attr_reader :value, :first_line, :last_line, :first_column, :last_column
7
7
 
8
- def initialize(name)
9
- @name = name
8
+ def initialize(value, first_line, last_line, first_column, last_column)
9
+ @value, @first_line, @last_line, @first_column, @last_column = value, first_line, last_line, first_column, last_column
10
10
  end
11
+ end
12
+
13
+ class Node
14
+ attr_reader :token
15
+
16
+ def initialize(token)
17
+ @token = token
18
+ end
19
+ end
11
20
 
21
+ class Var < Node
12
22
  def accept(visitor, arg)
13
23
  visitor.visit_var(self, arg)
14
24
  end
15
25
  end
16
26
 
17
- class And
27
+ class And < Node
18
28
  attr_reader :left, :right
19
29
 
20
- def initialize(left, right)
30
+ def initialize(token, left, right)
31
+ super(token)
21
32
  @left, @right = left, right
22
33
  end
23
34
 
@@ -26,10 +37,11 @@ module Bool
26
37
  end
27
38
  end
28
39
 
29
- class Or
40
+ class Or < Node
30
41
  attr_reader :left, :right
31
42
 
32
- def initialize(left, right)
43
+ def initialize(token, left, right)
44
+ super(token)
33
45
  @left, @right = left, right
34
46
  end
35
47
 
@@ -38,10 +50,11 @@ module Bool
38
50
  end
39
51
  end
40
52
 
41
- class Not
53
+ class Not < Node
42
54
  attr_reader :operand
43
55
 
44
- def initialize(operand)
56
+ def initialize(token, operand)
57
+ super(token)
45
58
  @operand = operand
46
59
  end
47
60
 
@@ -9,7 +9,7 @@ module Bool
9
9
 
10
10
  else
11
11
  def visit_var(node, vars)
12
- !!vars.index(node.name)
12
+ !!vars.index(node.token.value)
13
13
  end
14
14
 
15
15
  def visit_and(node, vars)
@@ -9,19 +9,19 @@ module Bool
9
9
 
10
10
  else
11
11
  def visit_var(node, vars)
12
- node.name
12
+ node.token.value
13
13
  end
14
14
 
15
15
  def visit_and(node, vars)
16
- "(" + render(node.left) + " && " + render(node.right) + ")"
16
+ "(#{render(node.left)} #{node.token.value} #{render(node.right)})"
17
17
  end
18
18
 
19
19
  def visit_or(node, vars)
20
- "(" + render(node.left) + " || " + render(node.right) + ")"
20
+ "(#{render(node.left)} #{node.token.value} #{render(node.right)})"
21
21
  end
22
22
 
23
23
  def visit_not(node, vars)
24
- "!" + render(node.operand)
24
+ "#{node.token.value}#{render(node.operand)}"
25
25
  end
26
26
 
27
27
  private
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bool
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.14
4
+ version: 1.0.15
5
5
  platform: java
6
6
  authors:
7
7
  - Aslak Hellesøy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-16 00:00:00.000000000 Z
11
+ date: 2013-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -68,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
68
  version: '0'
69
69
  requirements: []
70
70
  rubyforge_project:
71
- rubygems_version: 2.0.0.rc.2
71
+ rubygems_version: 2.0.0
72
72
  signing_key:
73
73
  specification_version: 4
74
74
  summary: Boolean expression evaluator