bool 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,120 @@
1
+ /* A Bison parser, made by GNU Bison 2.7. */
2
+
3
+ /* Bison interface for Yacc-like parsers in C
4
+
5
+ Copyright (C) 1984, 1989-1990, 2000-2012 Free Software Foundation, Inc.
6
+
7
+ This program is free software: you can redistribute it and/or modify
8
+ it under the terms of the GNU General Public License as published by
9
+ the Free Software Foundation, either version 3 of the License, or
10
+ (at your option) any later version.
11
+
12
+ This program is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ GNU General Public License for more details.
16
+
17
+ You should have received a copy of the GNU General Public License
18
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
+
20
+ /* As a special exception, you may create a larger work that contains
21
+ part or all of the Bison parser skeleton and distribute that work
22
+ under terms of your choice, so long as that work isn't itself a
23
+ parser generator using the skeleton or a modified version thereof
24
+ as a parser skeleton. Alternatively, if you modify or redistribute
25
+ the parser skeleton itself, you may (at your option) remove this
26
+ special exception, which will cause the skeleton and the resulting
27
+ Bison output files to be licensed under the GNU General Public
28
+ License without this special exception.
29
+
30
+ This special exception was added by the Free Software Foundation in
31
+ version 2.2 of Bison. */
32
+
33
+ #ifndef YY_YY_PARSER_H_INCLUDED
34
+ # define YY_YY_PARSER_H_INCLUDED
35
+ /* Enabling traces. */
36
+ #ifndef YYDEBUG
37
+ # define YYDEBUG 0
38
+ #endif
39
+ #if YYDEBUG
40
+ extern int yydebug;
41
+ #endif
42
+ /* "%code requires" blocks. */
43
+ /* Line 2065 of yacc.c */
44
+ #line 10 "parser.y"
45
+
46
+
47
+ #include "ast.h"
48
+ #ifndef YY_TYPEDEF_YY_SCANNER_T
49
+ #define YY_TYPEDEF_YY_SCANNER_T
50
+ typedef void* yyscan_t;
51
+ #endif
52
+
53
+
54
+ /* Line 2065 of yacc.c */
55
+ #line 56 "parser.h"
56
+
57
+ /* Tokens. */
58
+ #ifndef YYTOKENTYPE
59
+ # define YYTOKENTYPE
60
+ /* Put the tokens into the symbol table, so that GDB and other debuggers
61
+ know about them. */
62
+ enum yytokentype {
63
+ TOKEN_OR = 258,
64
+ TOKEN_AND = 259,
65
+ UNOT = 260,
66
+ TOKEN_VAR = 261,
67
+ TOKEN_NOT = 262,
68
+ TOKEN_LPAREN = 263,
69
+ TOKEN_RPAREN = 264
70
+ };
71
+ #endif
72
+
73
+
74
+ #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
75
+ typedef union YYSTYPE
76
+ {
77
+ /* Line 2065 of yacc.c */
78
+ #line 30 "parser.y"
79
+
80
+ char* value;
81
+ Node* node;
82
+
83
+
84
+ /* Line 2065 of yacc.c */
85
+ #line 86 "parser.h"
86
+ } YYSTYPE;
87
+ # define YYSTYPE_IS_TRIVIAL 1
88
+ # define yystype YYSTYPE /* obsolescent; will be withdrawn */
89
+ # define YYSTYPE_IS_DECLARED 1
90
+ #endif
91
+
92
+ #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
93
+ typedef struct YYLTYPE
94
+ {
95
+ int first_line;
96
+ int first_column;
97
+ int last_line;
98
+ int last_column;
99
+ } YYLTYPE;
100
+ # define yyltype YYLTYPE /* obsolescent; will be withdrawn */
101
+ # define YYLTYPE_IS_DECLARED 1
102
+ # define YYLTYPE_IS_TRIVIAL 1
103
+ #endif
104
+
105
+
106
+ #ifdef YYPARSE_PARAM
107
+ #if defined __STDC__ || defined __cplusplus
108
+ int yyparse (void *YYPARSE_PARAM);
109
+ #else
110
+ int yyparse ();
111
+ #endif
112
+ #else /* ! YYPARSE_PARAM */
113
+ #if defined __STDC__ || defined __cplusplus
114
+ int yyparse (Node** node, yyscan_t scanner);
115
+ #else
116
+ int yyparse ();
117
+ #endif
118
+ #endif /* ! YYPARSE_PARAM */
119
+
120
+ #endif /* !YY_YY_PARSER_H_INCLUDED */
@@ -0,0 +1,6 @@
1
+ #ifndef __UNUSED_H__
2
+ #define __UNUSED_H__
3
+
4
+ #define UNUSED(x) (void)(x)
5
+
6
+ #endif
@@ -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
@@ -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
+
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bool
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
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: rake-compiler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 0.8.2
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: 0.8.2
46
+ description:
47
+ email:
48
+ executables: []
49
+ extensions:
50
+ - ext/bool_ext/extconf.rb
51
+ extra_rdoc_files: []
52
+ files:
53
+ - lib/bool/ast.rb
54
+ - lib/bool/evaluator.rb
55
+ - lib/bool.rb
56
+ - ext/bool_ext/extconf.rb
57
+ - ext/bool_ext/ast.c
58
+ - ext/bool_ext/ext.c
59
+ - ext/bool_ext/lexer.c
60
+ - ext/bool_ext/parser.c
61
+ - ext/bool_ext/ast.h
62
+ - ext/bool_ext/lexer.h
63
+ - ext/bool_ext/parser.h
64
+ - ext/bool_ext/unused.h
65
+ homepage:
66
+ licenses: []
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 1.8.24
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: Boolean expression evaluator
89
+ test_files: []
90
+ has_rdoc: