ebnf 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/README.md +8 -58
- data/VERSION +1 -1
- data/bin/ebnf +7 -5
- data/etc/doap.ttl +11 -12
- data/etc/ebnf.ebnf +45 -41
- data/etc/ebnf.ll1.sxp +114 -197
- data/etc/ebnf.rb +149 -459
- data/etc/ebnf.sxp +27 -22
- data/etc/turtle.ll1.sxp +5 -5
- data/etc/turtle.rb +55 -50
- data/etc/turtle.sxp +20 -21
- data/lib/ebnf/base.rb +32 -17
- data/lib/ebnf/ll1.rb +39 -7
- data/lib/ebnf/ll1/lexer.rb +8 -20
- data/lib/ebnf/ll1/parser.rb +4 -0
- data/lib/ebnf/parser.rb +55 -51
- data/lib/ebnf/rule.rb +36 -0
- metadata +15 -15
data/lib/ebnf/rule.rb
CHANGED
@@ -60,11 +60,17 @@ module EBNF
|
|
60
60
|
# @param [Hash{Symbol => Object}] options
|
61
61
|
# @option options [Symbol] :kind
|
62
62
|
# @option options [String] :ebnf
|
63
|
+
# @option options [Array] :first
|
64
|
+
# @option options [Array] :follow
|
65
|
+
# option options [Boolean] :start
|
63
66
|
def initialize(sym, id, expr, options = {})
|
64
67
|
@sym, @id = sym, id
|
65
68
|
@expr = expr.is_a?(Array) ? expr : [:seq, expr]
|
66
69
|
@ebnf = options[:ebnf]
|
67
70
|
@top_rule = options.fetch(:top_rule, self)
|
71
|
+
@first = options[:first]
|
72
|
+
@follow = options[:follow]
|
73
|
+
@start = options[:start]
|
68
74
|
@kind = case
|
69
75
|
when options[:kind] then options[:kind]
|
70
76
|
when sym.to_s == sym.to_s.upcase then :terminal
|
@@ -73,6 +79,30 @@ module EBNF
|
|
73
79
|
end
|
74
80
|
end
|
75
81
|
|
82
|
+
##
|
83
|
+
# Return a rule from its SXP representation:
|
84
|
+
#
|
85
|
+
# @example inputs
|
86
|
+
# (pass (plus (range "#x20\\t\\r\\n")))
|
87
|
+
# (rule ebnf "1" (star (alt declaration rule)))
|
88
|
+
# (terminal O_ENUM "17" (seq "[^" (plus CHAR) "]"))
|
89
|
+
#
|
90
|
+
# Also may have (first ...), (follow ...), or (start #t)
|
91
|
+
#
|
92
|
+
# @param [Array] sxp
|
93
|
+
# @return [Rule]
|
94
|
+
def self.from_sxp(sxp)
|
95
|
+
expr = sxp.detect {|e| e.is_a?(Array) && ![:first, :follow, :start].include?(e.first.to_sym)}
|
96
|
+
first = sxp.detect {|e| e.is_a?(Array) && e.first.to_sym == :first}
|
97
|
+
first = first[1..-1] if first
|
98
|
+
follow = sxp.detect {|e| e.is_a?(Array) && e.first.to_sym == :follow}
|
99
|
+
follow = follow[1..-1] if follow
|
100
|
+
start = sxp.any? {|e| e.is_a?(Array) && e.first.to_sym == :start}
|
101
|
+
sym = sxp[1] if sxp[1].is_a?(Symbol)
|
102
|
+
id = sxp[2] if sxp[2].is_a?(String)
|
103
|
+
Rule.new(sym, id, expr, :kind => sxp.first, :first => first, :follow => follow, :start => start)
|
104
|
+
end
|
105
|
+
|
76
106
|
# Build a new rule creating a symbol and numbering from the current rule
|
77
107
|
# Symbol and number creation is handled by the top-most rule in such a chain
|
78
108
|
#
|
@@ -277,6 +307,12 @@ module EBNF
|
|
277
307
|
kind == :terminal
|
278
308
|
end
|
279
309
|
|
310
|
+
# Is this a pass?
|
311
|
+
# @return [Boolean]
|
312
|
+
def pass?
|
313
|
+
kind == :pass
|
314
|
+
end
|
315
|
+
|
280
316
|
# Is this a rule?
|
281
317
|
# @return [Boolean]
|
282
318
|
def rule?
|
metadata
CHANGED
@@ -1,83 +1,83 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ebnf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gregg Kellogg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sxp
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rdf
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: 2.12.0
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 2.12.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: yard
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 0.8.3
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 0.8.3
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - '>='
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
description: EBNF is a Ruby parser for W3C EBNF and a parser generator for compliant
|
@@ -123,17 +123,17 @@ require_paths:
|
|
123
123
|
- lib
|
124
124
|
required_ruby_version: !ruby/object:Gem::Requirement
|
125
125
|
requirements:
|
126
|
-
- -
|
126
|
+
- - '>='
|
127
127
|
- !ruby/object:Gem::Version
|
128
128
|
version: 1.8.7
|
129
129
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
130
|
requirements:
|
131
|
-
- -
|
131
|
+
- - '>='
|
132
132
|
- !ruby/object:Gem::Version
|
133
133
|
version: '0'
|
134
134
|
requirements: []
|
135
135
|
rubyforge_project:
|
136
|
-
rubygems_version: 2.
|
136
|
+
rubygems_version: 2.1.11
|
137
137
|
signing_key:
|
138
138
|
specification_version: 4
|
139
139
|
summary: EBNF parser and parser generator.
|