bool 1.0.0-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/bool.rb +29 -0
- data/lib/bool/ast.rb +53 -0
- data/lib/bool/evaluator.rb +35 -0
- data/lib/bool_ext.so +0 -0
- metadata +81 -0
data/lib/bool.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# This loads either bool_ext.so, bool_ext.bundle or
|
2
|
+
# bool_ext.jar, depending on your Ruby platform and OS
|
3
|
+
require 'bool_ext'
|
4
|
+
require 'bool/ast'
|
5
|
+
require 'bool/evaluator'
|
6
|
+
|
7
|
+
module Bool
|
8
|
+
class SyntaxError < StandardError
|
9
|
+
attr_reader :first_line, :last_line, :first_column, :last_column
|
10
|
+
|
11
|
+
def initialize(message, first_line, last_line, first_column, last_column)
|
12
|
+
super(message)
|
13
|
+
@first_line, @last_line, @first_column, @last_column = first_line, last_line, first_column, last_column
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
if RUBY_PLATFORM =~ /java/
|
18
|
+
def parse(source)
|
19
|
+
lexer = Java::Bool::Lexer.new(source)
|
20
|
+
parser = Java::Bool::Parser.new(lexer)
|
21
|
+
parser.parseExpr()
|
22
|
+
rescue => e
|
23
|
+
raise SyntaxError.new(e.message, e.line, e.line, e.column, e.column)
|
24
|
+
end
|
25
|
+
module_function(:parse)
|
26
|
+
else
|
27
|
+
# parse is defined in ruby_bool.c
|
28
|
+
end
|
29
|
+
end
|
data/lib/bool/ast.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
module Bool
|
2
|
+
if RUBY_PLATFORM =~ /java/
|
3
|
+
# AST classes defined in bool_ext.jar (bool-jvm)
|
4
|
+
else
|
5
|
+
class Var
|
6
|
+
attr_reader :name
|
7
|
+
|
8
|
+
def initialize(name)
|
9
|
+
@name = name
|
10
|
+
end
|
11
|
+
|
12
|
+
def describe_to(visitor, arg)
|
13
|
+
visitor.var(self, arg)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class And
|
18
|
+
attr_reader :left, :right
|
19
|
+
|
20
|
+
def initialize(left, right)
|
21
|
+
@left, @right = left, right
|
22
|
+
end
|
23
|
+
|
24
|
+
def describe_to(visitor, arg)
|
25
|
+
visitor.and(self, arg)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class Or
|
30
|
+
attr_reader :left, :right
|
31
|
+
|
32
|
+
def initialize(left, right)
|
33
|
+
@left, @right = left, right
|
34
|
+
end
|
35
|
+
|
36
|
+
def describe_to(visitor, arg)
|
37
|
+
visitor.or(self, arg)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class Not
|
42
|
+
attr_reader :other
|
43
|
+
|
44
|
+
def initialize(other)
|
45
|
+
@other = other
|
46
|
+
end
|
47
|
+
|
48
|
+
def describe_to(visitor, arg)
|
49
|
+
visitor.not(self, arg)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Bool
|
2
|
+
class Evaluator
|
3
|
+
if RUBY_PLATFORM =~ /java/
|
4
|
+
require 'libbool'
|
5
|
+
|
6
|
+
def self.new
|
7
|
+
Java::Bool::Evaluator.new
|
8
|
+
end
|
9
|
+
|
10
|
+
else
|
11
|
+
def var(node, vars)
|
12
|
+
!!vars.index(node.name)
|
13
|
+
end
|
14
|
+
|
15
|
+
def and(node, vars)
|
16
|
+
evaluate(node.left, vars) && evaluate(node.right, vars)
|
17
|
+
end
|
18
|
+
|
19
|
+
def or(node, vars)
|
20
|
+
evaluate(node.left, vars) || evaluate(node.right, vars)
|
21
|
+
end
|
22
|
+
|
23
|
+
def not(node, vars)
|
24
|
+
!evaluate(node.other, vars)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def evaluate(node, vars)
|
30
|
+
node.describe_to(self, vars)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
data/lib/bool_ext.so
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bool
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: x86-mingw32
|
7
|
+
authors:
|
8
|
+
- Aslak Hellesøy
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: bundler
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.3.0.pre
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.3.0.pre
|
46
|
+
description:
|
47
|
+
email:
|
48
|
+
executables: []
|
49
|
+
extensions: []
|
50
|
+
extra_rdoc_files: []
|
51
|
+
files:
|
52
|
+
- lib/bool/ast.rb
|
53
|
+
- lib/bool/evaluator.rb
|
54
|
+
- lib/bool.rb
|
55
|
+
- lib/bool_ext.so
|
56
|
+
homepage:
|
57
|
+
licenses: []
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ! '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 1.8.24
|
77
|
+
signing_key:
|
78
|
+
specification_version: 3
|
79
|
+
summary: Boolean expression evaluator
|
80
|
+
test_files: []
|
81
|
+
has_rdoc:
|