chomsky 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
data/lib/chomsky/action.rb
CHANGED
@@ -2,8 +2,9 @@ require 'chomsky/parser_generators/combinators'
|
|
2
2
|
|
3
3
|
module Chomsky
|
4
4
|
class ParserGenerator
|
5
|
-
autoload :
|
5
|
+
autoload :Sequence, "chomsky/parser_generators/sequence"
|
6
6
|
autoload :Compose, "chomsky/parser_generators/compose"
|
7
|
+
autoload :Bypass, "chomsky/parser_generators/bypass"
|
7
8
|
autoload :Repeat, "chomsky/parser_generators/repeat"
|
8
9
|
autoload :Not, "chomsky/parser_generators/not"
|
9
10
|
autoload :Or, "chomsky/parser_generators/or"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'chomsky'
|
2
|
+
|
3
|
+
module Chomsky
|
4
|
+
class ParserGenerator
|
5
|
+
class Bypass < ParserGenerator
|
6
|
+
def initialize left, right
|
7
|
+
@left, @right = left, right
|
8
|
+
end
|
9
|
+
|
10
|
+
def call string
|
11
|
+
head, rest = @left.(string)
|
12
|
+
if head
|
13
|
+
more = @right.(head)
|
14
|
+
if more
|
15
|
+
[head, rest]
|
16
|
+
else
|
17
|
+
[nil, string]
|
18
|
+
end
|
19
|
+
else
|
20
|
+
[nil, string]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -12,7 +12,7 @@ module Chomsky
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def & other
|
15
|
-
|
15
|
+
Sequence.(self.to_pg, other.to_pg)
|
16
16
|
end
|
17
17
|
|
18
18
|
def | other
|
@@ -63,6 +63,10 @@ module Chomsky
|
|
63
63
|
Compose.(self.to_pg, other.to_pg)
|
64
64
|
end
|
65
65
|
|
66
|
+
def >= other
|
67
|
+
Bypass.(self.to_pg, other.to_pg)
|
68
|
+
end
|
69
|
+
|
66
70
|
def capture name
|
67
71
|
captures[name] = Capture.new
|
68
72
|
end
|
data/lib/chomsky/rule.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chomsky
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04
|
12
|
+
date: 2013-05-04 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Chomsky generates parsing expression grammars with a nice pure-Ruby DSL,
|
15
15
|
eliminating the need for secondary grammar definition files or out-of-band compilation,
|
@@ -24,8 +24,8 @@ files:
|
|
24
24
|
- lib/chomsky/grammar.rb
|
25
25
|
- lib/chomsky/parser.rb
|
26
26
|
- lib/chomsky/parser_generator.rb
|
27
|
-
- lib/chomsky/parser_generators/and.rb
|
28
27
|
- lib/chomsky/parser_generators/backreference.rb
|
28
|
+
- lib/chomsky/parser_generators/bypass.rb
|
29
29
|
- lib/chomsky/parser_generators/capture.rb
|
30
30
|
- lib/chomsky/parser_generators/combinators.rb
|
31
31
|
- lib/chomsky/parser_generators/compose.rb
|
@@ -34,6 +34,7 @@ files:
|
|
34
34
|
- lib/chomsky/parser_generators/peek.rb
|
35
35
|
- lib/chomsky/parser_generators/perhaps.rb
|
36
36
|
- lib/chomsky/parser_generators/repeat.rb
|
37
|
+
- lib/chomsky/parser_generators/sequence.rb
|
37
38
|
- lib/chomsky/parser_generators/skip.rb
|
38
39
|
- lib/chomsky/parser_generators/some.rb
|
39
40
|
- lib/chomsky/parsers/anything.rb
|