yaparc 0.2.3 → 0.3.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.
- checksums.yaml +7 -0
- data/.document +3 -0
- data/.rdoc_options +1 -0
- data/CHANGELOG.md +9 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README +105 -85
- data/Rakefile +21 -0
- data/lib/yaparc.rb +7 -2
- data/manifest.scm +1 -0
- data/sig/yaparc.gen.rbs +220 -0
- data/sig/yaparc.rbs +4 -0
- data/yaparc.gemspec +36 -0
- metadata +91 -58
- data/test/n3-report.html +0 -169
- data/test/n3.bnf +0 -129
- data/test/test_abc.rb.bak +0 -112
- data/test/test_calc.rb +0 -112
- data/test/test_lambda.rb +0 -87
- data/test/test_metric.rb +0 -617
- data/test/test_owl.rb +0 -1039
- data/test/test_parser.rb +0 -460
- data/test/test_prolog.rb +0 -287
- data/test/test_sql.rb +0 -317
- data/test/test_uri.rb +0 -752
data/test/test_calc.rb
DELETED
@@ -1,112 +0,0 @@
|
|
1
|
-
require 'lib/yaparc.rb'
|
2
|
-
require 'test/unit'
|
3
|
-
|
4
|
-
module Calc
|
5
|
-
|
6
|
-
class Expr
|
7
|
-
include Yaparc::Parsable
|
8
|
-
|
9
|
-
def initialize
|
10
|
-
@parser = lambda do |input|
|
11
|
-
Yaparc::Alt.new(
|
12
|
-
Yaparc::Seq.new(Term.new,
|
13
|
-
Yaparc::Symbol.new('+'),
|
14
|
-
Expr.new) do |term, _, expr|
|
15
|
-
['+', term,expr]
|
16
|
-
end,
|
17
|
-
Term.new
|
18
|
-
)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def evaluate(input)
|
23
|
-
result = parse(input)
|
24
|
-
tree = result.value
|
25
|
-
eval_tree(tree)
|
26
|
-
end
|
27
|
-
|
28
|
-
def eval_tree(tree)
|
29
|
-
case tree
|
30
|
-
when Array
|
31
|
-
case tree[0]
|
32
|
-
when '+'
|
33
|
-
eval_tree(tree[1]) + eval_tree(tree[2])
|
34
|
-
when '-'
|
35
|
-
eval_tree(tree[1]) - eval_tree(tree[2])
|
36
|
-
when '*'
|
37
|
-
eval_tree(tree[1]) * eval_tree(tree[2])
|
38
|
-
when '/'
|
39
|
-
eval_tree(tree[1]) / eval_tree(tree[2])
|
40
|
-
end
|
41
|
-
else
|
42
|
-
tree
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
class Term
|
48
|
-
include Yaparc::Parsable
|
49
|
-
|
50
|
-
def initialize
|
51
|
-
@parser = lambda do |input|
|
52
|
-
Yaparc::Alt.new(
|
53
|
-
Yaparc::Seq.new(Factor.new,
|
54
|
-
Yaparc::Symbol.new('*'),
|
55
|
-
Term.new) do |factor, _, term|
|
56
|
-
['*', factor,term]
|
57
|
-
end,
|
58
|
-
Factor.new)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
class Factor
|
64
|
-
include Yaparc::Parsable
|
65
|
-
|
66
|
-
def initialize
|
67
|
-
@parser = lambda do |input|
|
68
|
-
Yaparc::Alt.new(
|
69
|
-
Yaparc::Seq.new(
|
70
|
-
Yaparc::Symbol.new('('),
|
71
|
-
Expr.new,
|
72
|
-
Yaparc::Symbol.new(')')
|
73
|
-
) do |_,expr, _|
|
74
|
-
expr
|
75
|
-
end,
|
76
|
-
Yaparc::Natural.new)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end # of Calc
|
81
|
-
|
82
|
-
class YaparcCalcTest < Test::Unit::TestCase
|
83
|
-
include ::Yaparc
|
84
|
-
|
85
|
-
def setup
|
86
|
-
@expr = Calc::Expr.new
|
87
|
-
@factor = Calc::Factor.new
|
88
|
-
end
|
89
|
-
|
90
|
-
def test_expr
|
91
|
-
result = @expr.parse("1 + 2 ")
|
92
|
-
assert_instance_of Result::OK, result
|
93
|
-
assert_equal ["+", 1, 2], result.value
|
94
|
-
assert_equal "", result.input
|
95
|
-
assert_equal 3, @expr.evaluate("1 + 2 ")
|
96
|
-
assert_equal 9, @expr.evaluate("(1 + 2) * 3 ")
|
97
|
-
end
|
98
|
-
|
99
|
-
def test_factor
|
100
|
-
result = @factor.parse("1")
|
101
|
-
assert_equal 1, result.value
|
102
|
-
assert_equal "", result.input
|
103
|
-
|
104
|
-
result = @factor.parse("( 1 )")
|
105
|
-
assert_equal 1, result.value
|
106
|
-
assert_equal "", result.input
|
107
|
-
|
108
|
-
result = @factor.parse("( 312 )")
|
109
|
-
assert_equal 312, result.value
|
110
|
-
assert_equal "", result.input
|
111
|
-
end
|
112
|
-
end
|
data/test/test_lambda.rb
DELETED
@@ -1,87 +0,0 @@
|
|
1
|
-
require 'lib/yaparc.rb'
|
2
|
-
require 'test/unit'
|
3
|
-
|
4
|
-
=begin
|
5
|
-
<expression> ::= <identifier>
|
6
|
-
::= "(" lambda (<identifier> <expression> ")"
|
7
|
-
::= "(" <expression> <expression> ")"
|
8
|
-
=end
|
9
|
-
|
10
|
-
module LambdaParser
|
11
|
-
|
12
|
-
|
13
|
-
class Identifier
|
14
|
-
include Yaparc::Parsable
|
15
|
-
RESERVED = %w{lambda}
|
16
|
-
|
17
|
-
def initialize
|
18
|
-
@parser = lambda do |input|
|
19
|
-
Yaparc::Identifier.new(:exclude => RESERVED)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
# KEYWORDS = %w{lambda}
|
25
|
-
# <expression> ::= <identifier>
|
26
|
-
class Expression
|
27
|
-
include Yaparc::Parsable
|
28
|
-
OPEN_PAREN = Yaparc::String.new("(")
|
29
|
-
CLOSE_PAREN = Yaparc::String.new(")")
|
30
|
-
|
31
|
-
def initialize
|
32
|
-
@parser = lambda do |input|
|
33
|
-
Yaparc::Alt.new(#<identifier>
|
34
|
-
Identifier.new,
|
35
|
-
#"(" lambda "(" <identifier> ")" <expression> ")"
|
36
|
-
Yaparc::Seq.new(OPEN_PAREN,
|
37
|
-
Yaparc::String.new("lambda"),
|
38
|
-
Yaparc::Tokenize.new(OPEN_PAREN),
|
39
|
-
Identifier.new,
|
40
|
-
CLOSE_PAREN,
|
41
|
-
Expression.new),
|
42
|
-
#"(" <expression> <expression> ")"
|
43
|
-
Yaparc::Seq.new(OPEN_PAREN,
|
44
|
-
Expression.new,
|
45
|
-
Expression.new,
|
46
|
-
CLOSE_PAREN))
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end # of LambdaParser
|
51
|
-
|
52
|
-
|
53
|
-
class LambdaIdentifierParserTest < Test::Unit::TestCase
|
54
|
-
include ::Yaparc
|
55
|
-
|
56
|
-
def setup
|
57
|
-
@parser = LambdaParser::Identifier.new
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_identifier
|
61
|
-
result = @parser.parse("identifier")
|
62
|
-
assert_instance_of Result::OK, result
|
63
|
-
result = @parser.parse("lambda")
|
64
|
-
assert_instance_of Result::Fail, result
|
65
|
-
|
66
|
-
result = @parser.parse(" identifier")
|
67
|
-
assert_instance_of Result::OK, result
|
68
|
-
result = @parser.parse(" identifier ")
|
69
|
-
assert_instance_of Result::OK, result
|
70
|
-
result = @parser.parse("identifier ")
|
71
|
-
assert_instance_of Result::OK, result
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
class LambdaExpressionParserTest < Test::Unit::TestCase
|
76
|
-
include ::Yaparc
|
77
|
-
|
78
|
-
def setup
|
79
|
-
@parser = LambdaParser::Expression.new
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_expression
|
83
|
-
assert_instance_of Result::OK, @parser.parse("identifier")
|
84
|
-
assert_instance_of Result::OK, @parser.parse("(lambda (x) x)")
|
85
|
-
assert_instance_of Result::OK, @parser.parse("(apply argument)")
|
86
|
-
end
|
87
|
-
end
|