yaparc 0.2.2 → 0.2.3
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.
- data/lib/yaparc.rb +141 -122
- data/test/n3-report.html +169 -0
- data/test/n3.bnf +129 -0
- data/{tests/test_abc.rb → test/test_abc.rb.bak} +0 -0
- data/{tests → test}/test_calc.rb +3 -3
- data/test/test_lambda.rb +87 -0
- data/test/test_metric.rb +617 -0
- data/{tests → test}/test_owl.rb +0 -0
- data/{tests → test}/test_parser.rb +42 -22
- data/test/test_prolog.rb +287 -0
- data/{tests → test}/test_sql.rb +11 -10
- data/{tests → test}/test_uri.rb +0 -0
- metadata +24 -18
- data/tests/abc20bnf.txt +0 -264
data/test/n3.bnf
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
#
|
2
|
+
# Taken from http://www.w3.org/DesignIssues/Notation3.html
|
3
|
+
# on 2001-08-03 (version of 2001-04-10)
|
4
|
+
#
|
5
|
+
# Modifications:
|
6
|
+
#
|
7
|
+
# $Log: n3.bnf,v $
|
8
|
+
# Revision 1.4 2001/08/06 20:56:21 sandro
|
9
|
+
# added space* and space+ in several places
|
10
|
+
# removed "#" from forbidden chars in URI_Reference
|
11
|
+
# handles comments
|
12
|
+
# made directives actually part of the grammar (!)
|
13
|
+
# allowed nprefix to be zero-length
|
14
|
+
#
|
15
|
+
# Revision 1.3 2001/08/03 13:44:43 sandro
|
16
|
+
# filled in remaining non-terminals
|
17
|
+
#
|
18
|
+
# Revision 1.2 2001/08/03 13:02:48 sandro
|
19
|
+
# standardized BNF so blindfold can compile it
|
20
|
+
# added ::= for each rule
|
21
|
+
# added | for branches
|
22
|
+
# added ; at end of rule
|
23
|
+
# added # before comments
|
24
|
+
# put quotes around literals
|
25
|
+
# turn hypen into underscore in identifiers
|
26
|
+
# rename prefix to nprefix (hack around blindfold keyword for now)
|
27
|
+
#
|
28
|
+
# Revision 1.1 2001/08/03 12:34:38 sandro
|
29
|
+
# added opening comments
|
30
|
+
#
|
31
|
+
|
32
|
+
|
33
|
+
document ::= void
|
34
|
+
| statementlist;
|
35
|
+
|
36
|
+
space ::= " " | "\n" | "\r" | comment;
|
37
|
+
|
38
|
+
comment ::= "#" [^\r\n]*;
|
39
|
+
|
40
|
+
statement ::= subject space+ property_list
|
41
|
+
| directive
|
42
|
+
;
|
43
|
+
|
44
|
+
statementlist ::= (statement space* ("." space*)?)* ;
|
45
|
+
|
46
|
+
subject ::= node;
|
47
|
+
|
48
|
+
verb ::= ">-" prop "->" # has xxx of
|
49
|
+
| "<-" prop "<-" # is xxx of
|
50
|
+
# | operator # has operator:xxx of??? NOT IMPLMENTED
|
51
|
+
| prop # has xxx of -- shorthand
|
52
|
+
| "has" prop # has xxx of
|
53
|
+
| "is" prop "of" # is xxx of
|
54
|
+
| "a" # has rdf:type of
|
55
|
+
| "=" # has daml:equivaent of
|
56
|
+
;
|
57
|
+
|
58
|
+
prop ::= node;
|
59
|
+
|
60
|
+
node ::= uri_ref2
|
61
|
+
| anonnode
|
62
|
+
| "this"
|
63
|
+
| node
|
64
|
+
;
|
65
|
+
|
66
|
+
nodelist ::= void # (used in lists)
|
67
|
+
| node
|
68
|
+
| node nodelist
|
69
|
+
;
|
70
|
+
|
71
|
+
anonnode ::= "[" property_list "]" # something which ...
|
72
|
+
| "{" statementlist "}" # the statementlist itself as a resource
|
73
|
+
| "(" nodelist ")" # short for eg [ n3:first node1; n3:rest [ n3:first node2; n3:rest: n3:null ]]
|
74
|
+
;
|
75
|
+
|
76
|
+
property_list ::= void # to allow [...].
|
77
|
+
| verb space+ object_list
|
78
|
+
| verb space+ object_list space+ ";" space+ property_list
|
79
|
+
| ":-" anonnode #to allow two anonymous forms to be given eg [ a :Truth; :- { :sky :color :blue } ] )
|
80
|
+
| ":-" anonnode ";" property_list
|
81
|
+
;
|
82
|
+
|
83
|
+
object_list ::= object
|
84
|
+
| object "," object_list
|
85
|
+
;
|
86
|
+
|
87
|
+
uri_ref2 ::= qname
|
88
|
+
| "<" URI_Reference ">"
|
89
|
+
;
|
90
|
+
|
91
|
+
qname ::= nprefix ":" localname; # ??? Allow omit colon when prefix void - keyword clash
|
92
|
+
|
93
|
+
object ::= subject
|
94
|
+
| string1 # " constant-value-with-escaping "
|
95
|
+
| string2 # """ constant value with escaping including single or double occurences of quotes and/or newlines """
|
96
|
+
# well-formed-xml-element ???? legacy or structured stuff - not implemented or distinguished
|
97
|
+
;
|
98
|
+
|
99
|
+
directive ::= "bind" space+ nprefix ":" uri_ref2 # Namespace declartion. Trailing "#" is omitted & assumed. Obsolete.
|
100
|
+
| "@prefix" space+ nprefix ":" space+ uri_ref2 # Namespace declaration
|
101
|
+
;
|
102
|
+
|
103
|
+
# operator ::= (Not implemented)
|
104
|
+
# + >- operator:plus ->
|
105
|
+
# - >- operator:minus ->
|
106
|
+
# / >- operator:slash->
|
107
|
+
# * >- operator:star-> (etc? @@)
|
108
|
+
|
109
|
+
fragid ::= alpha alphanumeric* ;
|
110
|
+
|
111
|
+
alpha ::= [a-zA-Z];
|
112
|
+
|
113
|
+
alphanumeric ::= alpha | [0-9] | "_";
|
114
|
+
|
115
|
+
void ::= "" ; # nothing
|
116
|
+
|
117
|
+
URI_Reference ::= [^{}<>]*; # short version
|
118
|
+
|
119
|
+
nprefix ::= "" | ((alpha | "_") alphanumeric*);
|
120
|
+
|
121
|
+
localname ::= fragid;
|
122
|
+
|
123
|
+
string1 ::= '"' string1_char* '"';
|
124
|
+
|
125
|
+
string1_char ::= '\\"' | [^\"] ; # should disallow some other characters, etc.
|
126
|
+
|
127
|
+
string2 ::= '"""' string2_char* '"""';
|
128
|
+
|
129
|
+
string2_char ::= [^"] | ([^] [^] [^"]); # something like this; need to think about it some more
|
File without changes
|
data/{tests → test}/test_calc.rb
RENAMED
@@ -7,7 +7,7 @@ module Calc
|
|
7
7
|
include Yaparc::Parsable
|
8
8
|
|
9
9
|
def initialize
|
10
|
-
@parser = lambda do
|
10
|
+
@parser = lambda do |input|
|
11
11
|
Yaparc::Alt.new(
|
12
12
|
Yaparc::Seq.new(Term.new,
|
13
13
|
Yaparc::Symbol.new('+'),
|
@@ -48,7 +48,7 @@ module Calc
|
|
48
48
|
include Yaparc::Parsable
|
49
49
|
|
50
50
|
def initialize
|
51
|
-
@parser = lambda do
|
51
|
+
@parser = lambda do |input|
|
52
52
|
Yaparc::Alt.new(
|
53
53
|
Yaparc::Seq.new(Factor.new,
|
54
54
|
Yaparc::Symbol.new('*'),
|
@@ -64,7 +64,7 @@ module Calc
|
|
64
64
|
include Yaparc::Parsable
|
65
65
|
|
66
66
|
def initialize
|
67
|
-
@parser = lambda do
|
67
|
+
@parser = lambda do |input|
|
68
68
|
Yaparc::Alt.new(
|
69
69
|
Yaparc::Seq.new(
|
70
70
|
Yaparc::Symbol.new('('),
|
data/test/test_lambda.rb
ADDED
@@ -0,0 +1,87 @@
|
|
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
|
data/test/test_metric.rb
ADDED
@@ -0,0 +1,617 @@
|
|
1
|
+
require 'lib/yaparc.rb'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
|
5
|
+
=begin Metric Interchange Syntax
|
6
|
+
|
7
|
+
c.f. http://people.csail.mit.edu/jaffer/MIXF/MIXF-08
|
8
|
+
Here is a YACC-like syntax for metric quantities (with [ISO 6093] numbers).
|
9
|
+
|
10
|
+
|
11
|
+
quantity_value
|
12
|
+
: numerical_value
|
13
|
+
| numerical_value '.' unit
|
14
|
+
;
|
15
|
+
|
16
|
+
unit
|
17
|
+
: unit_product
|
18
|
+
| unit_product '/' single_unit
|
19
|
+
;
|
20
|
+
|
21
|
+
unit_product
|
22
|
+
: single_unit
|
23
|
+
| unit_product '.' single_unit
|
24
|
+
;
|
25
|
+
|
26
|
+
single_unit
|
27
|
+
: punit
|
28
|
+
| punit '^' uxponent
|
29
|
+
| '(' unit ')'
|
30
|
+
| '(' unit ')^' uxponent
|
31
|
+
;
|
32
|
+
|
33
|
+
uxponent
|
34
|
+
: uinteger
|
35
|
+
| '-' uinteger
|
36
|
+
| '(' uinteger '/' uinteger ')'
|
37
|
+
| '(-' uinteger '/' uinteger ')'
|
38
|
+
;
|
39
|
+
|
40
|
+
punit
|
41
|
+
: decimal_multiple_prefix unit_p_symbol
|
42
|
+
| decimal_submultiple_prefix unit_n_symbol
|
43
|
+
| decimal_multiple_prefix unit_b_symbol
|
44
|
+
| decimal_submultiple_prefix unit_b_symbol
|
45
|
+
| binary_prefix 'B'
|
46
|
+
| binary_prefix 'bit'
|
47
|
+
| unit_p_symbol
|
48
|
+
| unit_n_symbol
|
49
|
+
| unit_b_symbol
|
50
|
+
| unit___symbol
|
51
|
+
;
|
52
|
+
|
53
|
+
decimal_multiple_prefix
|
54
|
+
: 'E' | 'G' | 'M' | 'P' | 'T' | 'Y' | 'Z' | 'da' | 'h' | 'k'
|
55
|
+
;
|
56
|
+
|
57
|
+
decimal_submultiple_prefix
|
58
|
+
: 'a' | 'c' | 'd' | 'f' | 'm' | 'n' | 'p' | 'u' | 'y' | 'z'
|
59
|
+
;
|
60
|
+
|
61
|
+
binary_prefix
|
62
|
+
: 'Ei' | 'Gi' | 'Ki' | 'Mi' | 'Pi' | 'Ti'
|
63
|
+
;
|
64
|
+
|
65
|
+
unit_p_symbol
|
66
|
+
: 'B' | 'Bd' | 'r' | 't'
|
67
|
+
;
|
68
|
+
|
69
|
+
unit_n_symbol
|
70
|
+
: 'L' | 'Np' | 'o' | 'oC' | 'rad' | 'sr'
|
71
|
+
;
|
72
|
+
|
73
|
+
unit_b_symbol
|
74
|
+
: 'A' | 'Bq' | 'C' | 'F' | 'Gy' | 'H' | 'Hz' | 'J' | 'K' | 'N'
|
75
|
+
| 'Ohm' | 'Pa' | 'S' | 'Sv' | 'T' | 'V' | 'W' | 'Wb' | 'bit'
|
76
|
+
| 'cd' | 'eV' | 'g' | 'kat' | 'lm' | 'lx' | 'm' | 'mol' | 's'
|
77
|
+
;
|
78
|
+
|
79
|
+
unit___symbol
|
80
|
+
: 'd' | 'dB' | 'h' | 'min' | 'u'
|
81
|
+
;
|
82
|
+
|
83
|
+
real
|
84
|
+
: ureal
|
85
|
+
| '-' ureal
|
86
|
+
;
|
87
|
+
|
88
|
+
ureal
|
89
|
+
: numerical_value
|
90
|
+
| numerical_value suffix
|
91
|
+
;
|
92
|
+
|
93
|
+
numerical_value
|
94
|
+
: uinteger
|
95
|
+
| dot uinteger
|
96
|
+
| uinteger dot uinteger
|
97
|
+
| uinteger dot
|
98
|
+
;
|
99
|
+
|
100
|
+
dot
|
101
|
+
: '.' | ','
|
102
|
+
;
|
103
|
+
|
104
|
+
uinteger
|
105
|
+
: digit uinteger
|
106
|
+
| uinteger
|
107
|
+
;
|
108
|
+
|
109
|
+
suffix
|
110
|
+
: exponent_marker uinteger
|
111
|
+
| exponent_marker '-' uinteger
|
112
|
+
;
|
113
|
+
|
114
|
+
exponent_marker
|
115
|
+
: 'e' | 'E'
|
116
|
+
;
|
117
|
+
|
118
|
+
digit
|
119
|
+
: '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
|
120
|
+
;
|
121
|
+
|
122
|
+
=end
|
123
|
+
|
124
|
+
|
125
|
+
module MISParser
|
126
|
+
|
127
|
+
=begin
|
128
|
+
quantity_value
|
129
|
+
: numerical_value ['.' unit]*
|
130
|
+
;
|
131
|
+
=end
|
132
|
+
class QuantityValue
|
133
|
+
include Yaparc::Parsable
|
134
|
+
|
135
|
+
def initialize
|
136
|
+
@parser = lambda do |input|
|
137
|
+
Yaparc::Seq.new(NumericalValue.new,
|
138
|
+
Yaparc::ZeroOne.new(
|
139
|
+
Yaparc::Seq.new(Yaparc::Literal.new('.'),Unit.new)))
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
|
145
|
+
=begin
|
146
|
+
unit
|
147
|
+
: unit_product ['/' single_unit]*
|
148
|
+
;
|
149
|
+
=end
|
150
|
+
class Unit
|
151
|
+
include Yaparc::Parsable
|
152
|
+
|
153
|
+
def initialize
|
154
|
+
@parser = lambda do |input|
|
155
|
+
Yaparc::Seq.new(UnitProduct.new,
|
156
|
+
Yaparc::ZeroOne.new(
|
157
|
+
Yaparc::Seq.new(Yaparc::Literal.new('/'),SingleUnit.new)))
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
=begin
|
163
|
+
unit_product
|
164
|
+
: single_unit [unit_product '.' single_unit]*
|
165
|
+
;
|
166
|
+
=end
|
167
|
+
class UnitProduct
|
168
|
+
include Yaparc::Parsable
|
169
|
+
|
170
|
+
def initialize
|
171
|
+
@parser = lambda do |input|
|
172
|
+
Yaparc::Seq.new(SingleUnit.new,
|
173
|
+
Yaparc::ZeroOne.new(
|
174
|
+
Yaparc::Seq.new(UnitProduct.new, Yaparc::Literal.new('.'), SingleUnit.new)))
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
=begin
|
180
|
+
single_unit
|
181
|
+
: punit
|
182
|
+
| punit '^' uxponent
|
183
|
+
| '(' unit ')'
|
184
|
+
| '(' unit ')^' uxponent
|
185
|
+
;
|
186
|
+
=end
|
187
|
+
class SingleUnit
|
188
|
+
include Yaparc::Parsable
|
189
|
+
|
190
|
+
def initialize
|
191
|
+
@parser = lambda do |input|
|
192
|
+
Yaparc::Alt.new(
|
193
|
+
Yaparc::Seq.new(Punit.new,Yaparc::Literal.new('^'),Uxponent.new),
|
194
|
+
Punit.new,
|
195
|
+
Yaparc::Seq.new(Yaparc::Literal.new('('),Unit.new,Yaparc::Literal.new(')^'),Uxponent.new),
|
196
|
+
Yaparc::Seq.new(Yaparc::Literal.new('('),Unit.new,Yaparc::Literal.new(')')))
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
=begin
|
202
|
+
uxponent
|
203
|
+
: uinteger
|
204
|
+
| '-' uinteger
|
205
|
+
| '(' uinteger '/' uinteger ')'
|
206
|
+
| '(-' uinteger '/' uinteger ')'
|
207
|
+
;
|
208
|
+
=end
|
209
|
+
class Uxponent
|
210
|
+
include Yaparc::Parsable
|
211
|
+
|
212
|
+
def initialize
|
213
|
+
@parser = lambda do |input|
|
214
|
+
Yaparc::Alt.new(
|
215
|
+
Uinteger.new,
|
216
|
+
Yaparc::Seq.new(Yaparc::Literal.new('-'),Uinteger.new),
|
217
|
+
Yaparc::Seq.new(Yaparc::Literal.new('('),Uinteger.new,Yaparc::Literal.new('/'),Uinteger.new,Yaparc::Literal.new(')')),
|
218
|
+
Yaparc::Seq.new(Yaparc::Literal.new('(-'),Uinteger.new,Yaparc::Literal.new('/'),Uinteger.new,Yaparc::Literal.new(')')))
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
=begin
|
224
|
+
punit
|
225
|
+
: decimal_multiple_prefix unit_p_symbol
|
226
|
+
| decimal_submultiple_prefix unit_n_symbol
|
227
|
+
| decimal_multiple_prefix unit_b_symbol
|
228
|
+
| decimal_submultiple_prefix unit_b_symbol
|
229
|
+
| binary_prefix 'B'
|
230
|
+
| binary_prefix 'bit'
|
231
|
+
| unit_p_symbol
|
232
|
+
| unit_n_symbol
|
233
|
+
| unit_b_symbol
|
234
|
+
| unit___symbol
|
235
|
+
;
|
236
|
+
=end
|
237
|
+
class Punit
|
238
|
+
include Yaparc::Parsable
|
239
|
+
|
240
|
+
def initialize
|
241
|
+
@parser = lambda do |input|
|
242
|
+
Yaparc::Alt.new(
|
243
|
+
Yaparc::Seq.new(DecimalMultiplePrefix.new, UnitPSymbol.new),
|
244
|
+
Yaparc::Seq.new(DecimalSubmultiplePrefix.new, UnitNSymbol.new),
|
245
|
+
Yaparc::Seq.new(DecimalMultiplePrefix.new, UnitBSymbol.new),
|
246
|
+
Yaparc::Seq.new(DecimalSubmultiplePrefix.new, UnitBSymbol.new),
|
247
|
+
Yaparc::Seq.new(BinaryPrefix.new, Yaparc::Literal.new('B')),
|
248
|
+
Yaparc::Seq.new(BinaryPrefix.new, Yaparc::Literal.new('bit')),
|
249
|
+
UnitPSymbol.new,
|
250
|
+
UnitNSymbol.new,
|
251
|
+
UnitBSymbol.new,
|
252
|
+
UnitSymbol.new)
|
253
|
+
|
254
|
+
|
255
|
+
end
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
|
260
|
+
=begin
|
261
|
+
decimal_multiple_prefix
|
262
|
+
=end
|
263
|
+
class DecimalMultiplePrefix
|
264
|
+
include Yaparc::Parsable
|
265
|
+
|
266
|
+
def initialize
|
267
|
+
@parser = lambda do |input|
|
268
|
+
Yaparc::Regex.new(/\AE|G|M|P|T|Y|Z|da|h|k/)
|
269
|
+
end
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
=begin
|
274
|
+
decimal_submultiple_prefix
|
275
|
+
: 'a' | 'c' | 'd' | 'f' | 'm' | 'n' | 'p' | 'u' | 'y' | 'z'
|
276
|
+
;
|
277
|
+
=end
|
278
|
+
class DecimalSubmultiplePrefix
|
279
|
+
include Yaparc::Parsable
|
280
|
+
|
281
|
+
def initialize
|
282
|
+
@parser = lambda do |input|
|
283
|
+
Yaparc::Regex.new(/\A[acdfmnpuyz]/)
|
284
|
+
end
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
=begin
|
289
|
+
binary_prefix
|
290
|
+
: 'Ei' | 'Gi' | 'Ki' | 'Mi' | 'Pi' | 'Ti'
|
291
|
+
;
|
292
|
+
=end
|
293
|
+
class BinaryPrefix
|
294
|
+
include Yaparc::Parsable
|
295
|
+
|
296
|
+
def initialize
|
297
|
+
@parser = lambda do |input|
|
298
|
+
Yaparc::Regex.new(/\AEi|Gi|Ki|Mi|Pi|Ti/)
|
299
|
+
end
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
=begin
|
304
|
+
unit_p_symbol
|
305
|
+
: 'B' | 'Bd' | 'r' | 't'
|
306
|
+
;
|
307
|
+
=end
|
308
|
+
class UnitPSymbol
|
309
|
+
include Yaparc::Parsable
|
310
|
+
|
311
|
+
def initialize
|
312
|
+
@parser = lambda do |input|
|
313
|
+
Yaparc::Regex.new(/\ABd|B|r|t/)
|
314
|
+
end
|
315
|
+
end
|
316
|
+
end
|
317
|
+
|
318
|
+
=begin
|
319
|
+
unit_n_symbol
|
320
|
+
: 'L' | 'Np' | 'o' | 'oC' | 'rad' | 'sr'
|
321
|
+
;
|
322
|
+
=end
|
323
|
+
class UnitNSymbol
|
324
|
+
include Yaparc::Parsable
|
325
|
+
|
326
|
+
def initialize
|
327
|
+
@parser = lambda do |input|
|
328
|
+
Yaparc::Regex.new(/\AL|Np|o|oC|rad|sr/)
|
329
|
+
end
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
=begin
|
334
|
+
unit_b_symbol
|
335
|
+
: 'A' | 'Bq' | 'C' | 'F' | 'Gy' | 'H' | 'Hz' | 'J' | 'K' | 'N'
|
336
|
+
| 'Ohm' | 'Pa' | 'S' | 'Sv' | 'T' | 'V' | 'W' | 'Wb' | 'bit'
|
337
|
+
| 'cd' | 'eV' | 'g' | 'kat' | 'lm' | 'lx' | 'm' | 'mol' | 's'
|
338
|
+
;
|
339
|
+
=end
|
340
|
+
class UnitBSymbol
|
341
|
+
include Yaparc::Parsable
|
342
|
+
|
343
|
+
def initialize
|
344
|
+
@parser = lambda do |input|
|
345
|
+
Yaparc::Regex.new(/\AA|Bq|C|F|Gy|H|Hz|J|K|N|Ohm|Pa|S|Sv|T|V|W|Wb|bit|cd|eV|g|kat|lm|lx|m|mol|s/)
|
346
|
+
end
|
347
|
+
end
|
348
|
+
end
|
349
|
+
|
350
|
+
=begin
|
351
|
+
unit___symbol
|
352
|
+
: 'd' | 'dB' | 'h' | 'min' | 'u'
|
353
|
+
;
|
354
|
+
=end
|
355
|
+
class UnitSymbol
|
356
|
+
include Yaparc::Parsable
|
357
|
+
|
358
|
+
def initialize
|
359
|
+
@parser = lambda do |input|
|
360
|
+
Yaparc::Regex.new(/\Ad|dB|h|min|u/)
|
361
|
+
end
|
362
|
+
end
|
363
|
+
end
|
364
|
+
|
365
|
+
=begin
|
366
|
+
real
|
367
|
+
: ureal
|
368
|
+
| '-' ureal
|
369
|
+
;
|
370
|
+
=end
|
371
|
+
class Real
|
372
|
+
include Yaparc::Parsable
|
373
|
+
|
374
|
+
def initialize
|
375
|
+
@parser = lambda do |input|
|
376
|
+
Yaparc::Seq.new(Yaparc::ZeroOne.new(Yaparc::Literal.new('-'),""),Ureal.new)
|
377
|
+
end
|
378
|
+
end
|
379
|
+
end
|
380
|
+
|
381
|
+
=begin
|
382
|
+
ureal
|
383
|
+
: numerical_value
|
384
|
+
| numerical_value suffix
|
385
|
+
;
|
386
|
+
=end
|
387
|
+
class Ureal
|
388
|
+
include Yaparc::Parsable
|
389
|
+
|
390
|
+
def initialize
|
391
|
+
@parser = lambda do |input|
|
392
|
+
Yaparc::Seq.new(NumericalValue.new, Yaparc::ZeroOne.new(Suffix.new,""))
|
393
|
+
end
|
394
|
+
end
|
395
|
+
end
|
396
|
+
|
397
|
+
=begin
|
398
|
+
numerical_value
|
399
|
+
: uinteger
|
400
|
+
| dot uinteger
|
401
|
+
| uinteger dot uinteger
|
402
|
+
| uinteger dot
|
403
|
+
;
|
404
|
+
=end
|
405
|
+
|
406
|
+
class NumericalValue
|
407
|
+
include Yaparc::Parsable
|
408
|
+
|
409
|
+
def initialize
|
410
|
+
@parser = lambda do |input|
|
411
|
+
Yaparc::Alt.new(Uinteger.new,
|
412
|
+
Yaparc::Seq.new(Dot.new,Uinteger.new),
|
413
|
+
Yaparc::Seq.new(Uinteger.new, Dot.new, Yaparc::ZeroOne.new(Uinteger.new,"")))
|
414
|
+
end
|
415
|
+
end
|
416
|
+
end
|
417
|
+
|
418
|
+
=begin
|
419
|
+
dot
|
420
|
+
: '.' | ','
|
421
|
+
;
|
422
|
+
=end
|
423
|
+
|
424
|
+
class Dot
|
425
|
+
include Yaparc::Parsable
|
426
|
+
|
427
|
+
def initialize
|
428
|
+
@parser = lambda do |input|
|
429
|
+
Yaparc::Regex.new(/\A[.,]/)
|
430
|
+
end
|
431
|
+
end
|
432
|
+
end
|
433
|
+
|
434
|
+
=begin
|
435
|
+
suffix
|
436
|
+
: exponent_marker uinteger
|
437
|
+
| exponent_marker '-' uinteger
|
438
|
+
;
|
439
|
+
=end
|
440
|
+
|
441
|
+
class Suffix
|
442
|
+
include Yaparc::Parsable
|
443
|
+
|
444
|
+
def initialize
|
445
|
+
@parser = lambda do |input|
|
446
|
+
Yaparc::Seq.new(ExponentMarker.new,
|
447
|
+
Yaparc::ZeroOne.new(Yaparc::Literal.new('-'),''),
|
448
|
+
Uinteger.new)
|
449
|
+
end
|
450
|
+
end
|
451
|
+
end
|
452
|
+
|
453
|
+
|
454
|
+
=begin
|
455
|
+
uinteger
|
456
|
+
: [digit]+
|
457
|
+
;
|
458
|
+
=end
|
459
|
+
class Uinteger
|
460
|
+
include Yaparc::Parsable
|
461
|
+
|
462
|
+
def initialize
|
463
|
+
@parser = lambda do |input|
|
464
|
+
Yaparc::ManyOne.new(Digit.new,'')
|
465
|
+
end
|
466
|
+
end
|
467
|
+
end
|
468
|
+
|
469
|
+
|
470
|
+
=begin
|
471
|
+
exponent_marker
|
472
|
+
: 'e' | 'E'
|
473
|
+
;
|
474
|
+
=end
|
475
|
+
|
476
|
+
class ExponentMarker
|
477
|
+
include Yaparc::Parsable
|
478
|
+
|
479
|
+
def initialize
|
480
|
+
@parser = lambda do |input|
|
481
|
+
Yaparc::Regex.new(/\A[eE]/)
|
482
|
+
end
|
483
|
+
end
|
484
|
+
end
|
485
|
+
|
486
|
+
=begin
|
487
|
+
digit
|
488
|
+
: '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
|
489
|
+
;
|
490
|
+
=end
|
491
|
+
|
492
|
+
class Digit
|
493
|
+
include Yaparc::Parsable
|
494
|
+
|
495
|
+
def initialize
|
496
|
+
@parser = lambda do |input|
|
497
|
+
Yaparc::Regex.new(/\A\d/)
|
498
|
+
end
|
499
|
+
end
|
500
|
+
end
|
501
|
+
|
502
|
+
|
503
|
+
end # of MISParser
|
504
|
+
|
505
|
+
class MISTest < Test::Unit::TestCase
|
506
|
+
include ::Yaparc
|
507
|
+
|
508
|
+
def test_digit
|
509
|
+
digit = MISParser::Digit.new
|
510
|
+
assert_instance_of Result::OK, digit.parse("3")
|
511
|
+
end
|
512
|
+
|
513
|
+
def test_uinteger
|
514
|
+
uinteger = MISParser::Digit.new
|
515
|
+
assert_instance_of Result::OK, uinteger.parse("3")
|
516
|
+
assert_instance_of Result::OK, uinteger.parse("123")
|
517
|
+
assert_instance_of Result::OK, uinteger.parse("0123")
|
518
|
+
end
|
519
|
+
|
520
|
+
def test_suffix
|
521
|
+
suffix = MISParser::Suffix.new
|
522
|
+
assert_instance_of Result::OK, suffix.parse("e3")
|
523
|
+
assert_instance_of Result::OK, suffix.parse("E-10")
|
524
|
+
assert_instance_of Result::OK, suffix.parse("e09876")
|
525
|
+
end
|
526
|
+
|
527
|
+
def test_numerical_value
|
528
|
+
numerical_value = MISParser::NumericalValue.new
|
529
|
+
assert_instance_of Result::OK, numerical_value.parse("3")
|
530
|
+
assert_instance_of Result::OK, numerical_value.parse("0.9")
|
531
|
+
assert_instance_of Result::OK, numerical_value.parse(".987")
|
532
|
+
assert_instance_of Result::OK, numerical_value.parse("0987.")
|
533
|
+
end
|
534
|
+
|
535
|
+
|
536
|
+
def test_ureal
|
537
|
+
ureal = MISParser::Ureal.new
|
538
|
+
assert_instance_of Result::OK, ureal.parse("3")
|
539
|
+
assert_instance_of Result::OK, ureal.parse("0.9e10")
|
540
|
+
assert_instance_of Result::OK, ureal.parse(".987E-098")
|
541
|
+
end
|
542
|
+
|
543
|
+
def test_real
|
544
|
+
real = MISParser::Real.new
|
545
|
+
assert_instance_of Result::OK, real.parse("-0.9e10")
|
546
|
+
assert_instance_of Result::OK, real.parse("-.987E-098")
|
547
|
+
end
|
548
|
+
|
549
|
+
def test_unit
|
550
|
+
unit = MISParser::Unit.new
|
551
|
+
assert_instance_of Result::OK, unit.parse("s^-1")
|
552
|
+
assert_instance_of Result::OK, unit.parse("dm^3")
|
553
|
+
assert_instance_of Result::OK, unit.parse("rad^2")
|
554
|
+
assert_instance_of Result::OK, unit.parse("Mg")
|
555
|
+
assert_instance_of Result::OK, unit.parse("mol/s")
|
556
|
+
assert_instance_of Result::OK, unit.parse("cd.sr")
|
557
|
+
assert_instance_of Result::OK, unit.parse("lm/m^2")
|
558
|
+
assert_instance_of Result::OK, unit.parse("m.kg.s^-2")
|
559
|
+
assert_instance_of Result::OK, unit.parse("N/m^2")
|
560
|
+
assert_instance_of Result::OK, unit.parse("N.m")
|
561
|
+
assert_instance_of Result::OK, unit.parse("J/s")
|
562
|
+
assert_instance_of Result::OK, unit.parse("s.A")
|
563
|
+
assert_instance_of Result::OK, unit.parse("W/A")
|
564
|
+
assert_instance_of Result::OK, unit.parse("C/V")
|
565
|
+
assert_instance_of Result::OK, unit.parse("V/A")
|
566
|
+
assert_instance_of Result::OK, unit.parse("A/V")
|
567
|
+
assert_instance_of Result::OK, unit.parse("V.s")
|
568
|
+
assert_instance_of Result::OK, unit.parse("Wb/m^2")
|
569
|
+
assert_instance_of Result::OK, unit.parse("Wb/A")
|
570
|
+
assert_instance_of Result::OK, unit.parse("m^2.s^-2")
|
571
|
+
assert_instance_of Result::OK, unit.parse("m^2")
|
572
|
+
assert_instance_of Result::OK, unit.parse("m^3")
|
573
|
+
assert_instance_of Result::OK, unit.parse("m/s")
|
574
|
+
assert_instance_of Result::OK, unit.parse("m/s^2")
|
575
|
+
assert_instance_of Result::OK, unit.parse("m^-1")
|
576
|
+
assert_instance_of Result::OK, unit.parse("kg/m^3")
|
577
|
+
assert_instance_of Result::OK, unit.parse("m^3/kg")
|
578
|
+
assert_instance_of Result::OK, unit.parse("A/m^2")
|
579
|
+
assert_instance_of Result::OK, unit.parse("mol/m^3")
|
580
|
+
assert_instance_of Result::OK, unit.parse("cd/m^3")
|
581
|
+
assert_instance_of Result::OK, unit.parse("rad/s")
|
582
|
+
assert_instance_of Result::OK, unit.parse("rad/s^2")
|
583
|
+
assert_instance_of Result::OK, unit.parse("Pa.s")
|
584
|
+
assert_instance_of Result::OK, unit.parse("W/m^2")
|
585
|
+
assert_instance_of Result::OK, unit.parse("W/sr")
|
586
|
+
assert_instance_of Result::OK, unit.parse("W/(m^2.sr)")
|
587
|
+
assert_instance_of Result::OK, unit.parse("J/K")
|
588
|
+
assert_instance_of Result::OK, unit.parse("J/(kg.K)")
|
589
|
+
assert_instance_of Result::OK, unit.parse("J/kg")
|
590
|
+
assert_instance_of Result::OK, unit.parse("W/(m.k)")
|
591
|
+
assert_instance_of Result::OK, unit.parse("J/m^3")
|
592
|
+
assert_instance_of Result::OK, unit.parse("C/m^3")
|
593
|
+
assert_instance_of Result::OK, unit.parse("F/m")
|
594
|
+
assert_instance_of Result::OK, unit.parse("H/m")
|
595
|
+
assert_instance_of Result::OK, unit.parse("J/mol")
|
596
|
+
assert_instance_of Result::OK, unit.parse("J/(mol.k)")
|
597
|
+
assert_instance_of Result::OK, unit.parse("C/kg")
|
598
|
+
assert_instance_of Result::OK, unit.parse("r/min")
|
599
|
+
assert_instance_of Result::OK, unit.parse("kat/m^3")
|
600
|
+
assert_instance_of Result::OK, unit.parse("Mib/s")
|
601
|
+
assert_instance_of Result::OK, unit.parse("nV/Hz^(1/2)")
|
602
|
+
end
|
603
|
+
|
604
|
+
def test_quantity_value
|
605
|
+
quantity_value = MISParser::QuantityValue.new
|
606
|
+
assert_instance_of Result::OK, quantity_value.parse("60.s")
|
607
|
+
assert_instance_of Result::OK, quantity_value.parse("60.min")
|
608
|
+
assert_instance_of Result::OK, quantity_value.parse("24.h")
|
609
|
+
assert_instance_of Result::OK, quantity_value.parse("6.283185307179586.rad")
|
610
|
+
assert_instance_of Result::OK, quantity_value.parse("2.777777777777778e-3.r")
|
611
|
+
assert_instance_of Result::OK, quantity_value.parse("8.bit")
|
612
|
+
assert_instance_of Result::OK, quantity_value.parse("1.660538782e-27.kg")
|
613
|
+
assert_instance_of Result::OK, quantity_value.parse("1.602176487e-19.J")
|
614
|
+
assert_instance_of Result::OK, quantity_value.parse("0.1151293.Np")
|
615
|
+
end
|
616
|
+
|
617
|
+
end
|