yaparc 0.2.3 → 0.4.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.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/.document +3 -0
  3. data/.envrc +1 -0
  4. data/.rdoc_options +1 -0
  5. data/CHANGELOG.md +19 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE +20 -0
  8. data/README +106 -86
  9. data/Rakefile +27 -0
  10. data/TODO +11 -0
  11. data/lib/yaparc/abstract_parser.rb +16 -0
  12. data/lib/yaparc/alt.rb +22 -0
  13. data/lib/yaparc/apply.rb +18 -0
  14. data/lib/yaparc/char.rb +16 -0
  15. data/lib/yaparc/cr.rb +11 -0
  16. data/lib/yaparc/digit.rb +11 -0
  17. data/lib/yaparc/fail_parser.rb +11 -0
  18. data/lib/yaparc/ident.rb +18 -0
  19. data/lib/yaparc/identifier.rb +32 -0
  20. data/lib/yaparc/item.rb +17 -0
  21. data/lib/yaparc/literal.rb +13 -0
  22. data/lib/yaparc/many.rb +14 -0
  23. data/lib/yaparc/many_one.rb +27 -0
  24. data/lib/yaparc/nat.rb +11 -0
  25. data/lib/yaparc/natural.rb +12 -0
  26. data/lib/yaparc/no_fail.rb +20 -0
  27. data/lib/yaparc/parsable.rb +20 -0
  28. data/lib/yaparc/regex.rb +22 -0
  29. data/lib/yaparc/satisfy.rb +28 -0
  30. data/lib/yaparc/seq.rb +33 -0
  31. data/lib/yaparc/space.rb +11 -0
  32. data/lib/yaparc/string.rb +24 -0
  33. data/lib/yaparc/succeed.rb +14 -0
  34. data/lib/yaparc/symbol.rb +11 -0
  35. data/lib/yaparc/tokenize.rb +18 -0
  36. data/lib/yaparc/white_space.rb +11 -0
  37. data/lib/yaparc/zero_one.rb +20 -0
  38. data/lib/yaparc.rb +40 -605
  39. data/sig/yaparc.gen.rbs +217 -0
  40. data/sig/yaparc.rbs +4 -0
  41. data/yaparc.gemspec +36 -0
  42. metadata +115 -58
  43. data/test/n3-report.html +0 -169
  44. data/test/n3.bnf +0 -129
  45. data/test/test_abc.rb.bak +0 -112
  46. data/test/test_calc.rb +0 -112
  47. data/test/test_lambda.rb +0 -87
  48. data/test/test_metric.rb +0 -617
  49. data/test/test_owl.rb +0 -1039
  50. data/test/test_parser.rb +0 -460
  51. data/test/test_prolog.rb +0 -287
  52. data/test/test_sql.rb +0 -317
  53. data/test/test_uri.rb +0 -752
data/test/n3.bnf DELETED
@@ -1,129 +0,0 @@
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
data/test/test_abc.rb.bak DELETED
@@ -1,112 +0,0 @@
1
-
2
- require 'lib/yaparc.rb'
3
- require 'test/unit'
4
-
5
- ### c.f. http://www.norbeck.nu/abc/bnf/abc20bnf.htm###
6
-
7
- module ABC
8
-
9
- # KEYWORDS = %w{NOT AND OR ALL IN select from where EXISTS}
10
-
11
- # abc-file ::= *(abc-tune / comment / xcommand / file-field / text-line / tex)
12
- class AbcFile
13
- include Yaparc::Parsable
14
-
15
- def initialize
16
- @parser = lambda do
17
- Yaparc::Many.new(
18
- Yaparc::Alt.new(AbcTune.new,
19
- Comment.new,
20
- Xcommand.new,
21
- FileField.new,
22
- TextLine.new,
23
- Tex.new))
24
- end
25
- end
26
- end
27
-
28
- # file-field ::= field-area / field-book / field-composer / field-discography / field-file / field-group / field-history / field-length / field-meter / field-notes / field-origin / field-parts / field-tempo / field-rhythm / field-source / field-userdef-print / field-userdef-play / field-words / field-transcription / field-key / unused-field ; Default values for the whole file - all fields except number, title and voice
29
- class FileField
30
- include Yaparc::Parsable
31
-
32
- def initialize
33
- @parser = lambda do
34
- Yaparc::Alt.new(
35
- FieldArea.new,
36
- FieldBook.new,
37
- FieldComposer.new,
38
- FieldDiscography.new,
39
- FieldFile.new,
40
- FieldGroup.new,
41
- FieldHistory.new,
42
- FieldLength.new,
43
- FieldMeter.new,
44
- FieldNotes.new,
45
- FieldOrigin.new,
46
- FieldParts.new,
47
- FieldTempo.new,
48
- FieldRhythm.new,
49
- FieldSource.new,
50
- FieldUserdefPrint.new,
51
- FieldUserdefPlay.new,
52
- FieldWords.new,
53
- FieldTranscription.new,
54
- FieldKey.new,
55
- UnusedField.new)
56
- end
57
- end
58
- end
59
-
60
- # abc-tune ::= abc-header abc-music eol
61
- class AbcTune
62
- include Yaparc::Parsable
63
-
64
- def initialize
65
- @parser = lambda do
66
- Yaparc::Seq.new(AbcHeader.new,
67
- AbcMusic.new,
68
- Eol.new)
69
- end
70
- end
71
- end
72
-
73
- # abc-header ::= [field-number] title-fields *other-field field-key ; note that field-number is optional.
74
- class AbcTune
75
- include Yaparc::Parsable
76
-
77
- def initialize
78
- @parser = lambda do
79
- Yaparc::Seq.new(
80
- ZeroOne.new(FieldNumber.new)
81
- TitleFields.new,
82
- Many.new(OtherField.new),
83
- FieldKey.new)
84
- end
85
- end
86
- end
87
-
88
- # field-number ::= %x58.3A *WSP 1*DIGIT header-eol ; X:
89
- class FieldNumber
90
- include Yaparc::Parsable
91
-
92
- def initialize
93
- @parser = lambda do
94
- Yaparc::Seq.new(
95
-
96
- %x58.3A *WSP 1*DIGIT header-eol ; X:
97
- end
98
- end
99
- end
100
-
101
- ### eol ::= CRLF / LF / CR ; only one version should occur in the whole file - win / *nix / mac line breaks
102
- class Eol
103
- include Yaparc::Parsable
104
-
105
- def initialize
106
- @parser = lambda do
107
- Yaparc::Alt.new(Regex.new(/\n/))
108
- end
109
- end
110
- end
111
-
112
- end
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