citrus 2.2.0 → 2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/citrus.rb +31 -10
- data/test/alias_test.rb +7 -7
- data/test/super_test.rb +28 -4
- metadata +9 -21
data/lib/citrus.rb
CHANGED
@@ -8,7 +8,7 @@ require 'strscan'
|
|
8
8
|
module Citrus
|
9
9
|
autoload :File, 'citrus/file'
|
10
10
|
|
11
|
-
VERSION = [2, 2,
|
11
|
+
VERSION = [2, 2, 1]
|
12
12
|
|
13
13
|
# Returns the current version of Citrus as a string.
|
14
14
|
def self.version
|
@@ -551,7 +551,6 @@ module Citrus
|
|
551
551
|
input.memoize! if opts[:memoize]
|
552
552
|
input.pos = opts[:offset] if opts[:offset] > 0
|
553
553
|
|
554
|
-
start = input.pos
|
555
554
|
events = input.exec(self)
|
556
555
|
length = events[-1]
|
557
556
|
|
@@ -559,7 +558,7 @@ module Citrus
|
|
559
558
|
raise ParseError.new(input)
|
560
559
|
end
|
561
560
|
|
562
|
-
Match.new(string.slice(
|
561
|
+
Match.new(string.slice(opts[:offset], length), events)
|
563
562
|
end
|
564
563
|
|
565
564
|
# The default set of options to use when parsing.
|
@@ -720,7 +719,18 @@ module Citrus
|
|
720
719
|
|
721
720
|
# Returns an array of events for this rule on the given +input+.
|
722
721
|
def exec(input, events=[])
|
723
|
-
|
722
|
+
events << id
|
723
|
+
|
724
|
+
index = events.size
|
725
|
+
start = index - 1
|
726
|
+
if input.exec(rule, events).size > index
|
727
|
+
events << CLOSE
|
728
|
+
events << events[-2]
|
729
|
+
else
|
730
|
+
events.slice!(start, events.size)
|
731
|
+
end
|
732
|
+
|
733
|
+
events
|
724
734
|
end
|
725
735
|
end
|
726
736
|
|
@@ -916,7 +926,18 @@ module Citrus
|
|
916
926
|
|
917
927
|
# Returns an array of events for this rule on the given +input+.
|
918
928
|
def exec(input, events=[])
|
919
|
-
|
929
|
+
events << id
|
930
|
+
|
931
|
+
index = events.size
|
932
|
+
start = index - 1
|
933
|
+
if input.exec(rule, events).size > index
|
934
|
+
events << CLOSE
|
935
|
+
events << events[-2]
|
936
|
+
else
|
937
|
+
events.slice!(start, events.size)
|
938
|
+
end
|
939
|
+
|
940
|
+
events
|
920
941
|
end
|
921
942
|
|
922
943
|
# Returns the Citrus notation of this rule as a string.
|
@@ -1135,11 +1156,6 @@ module Citrus
|
|
1135
1156
|
end
|
1136
1157
|
end
|
1137
1158
|
|
1138
|
-
# Returns a reference to the Rule object that first created this match.
|
1139
|
-
def creator
|
1140
|
-
extenders.first
|
1141
|
-
end
|
1142
|
-
|
1143
1159
|
# Returns an array of Match objects that are submatches of this match in the
|
1144
1160
|
# order they appeared in the input.
|
1145
1161
|
def matches
|
@@ -1187,6 +1203,11 @@ module Citrus
|
|
1187
1203
|
name ? find(name, false).first : matches.first
|
1188
1204
|
end
|
1189
1205
|
|
1206
|
+
# The default value for a match is its string value. This method is
|
1207
|
+
# overridden in most cases to be more meaningful according to the desired
|
1208
|
+
# interpretation.
|
1209
|
+
alias value to_s
|
1210
|
+
|
1190
1211
|
# Allows sub-matches of this match to be retrieved by name as instance
|
1191
1212
|
# methods.
|
1192
1213
|
def method_missing(sym, *args)
|
data/test/alias_test.rb
CHANGED
@@ -11,10 +11,10 @@ class AliasTest < Test::Unit::TestCase
|
|
11
11
|
rule :a, :b
|
12
12
|
rule :b, 'abc'
|
13
13
|
}
|
14
|
-
|
14
|
+
rule_a = grammar.rule(:a)
|
15
15
|
rule_b = grammar.rule(:b)
|
16
|
-
events =
|
17
|
-
assert_equal([rule_b.id, CLOSE, 3], events)
|
16
|
+
events = rule_a.exec(Input.new('abc'))
|
17
|
+
assert_equal([rule_a.id, rule_b.id, CLOSE, 3, CLOSE, 3], events)
|
18
18
|
end
|
19
19
|
|
20
20
|
def test_exec_miss
|
@@ -35,10 +35,10 @@ class AliasTest < Test::Unit::TestCase
|
|
35
35
|
include grammar1
|
36
36
|
rule :b, :a
|
37
37
|
}
|
38
|
-
|
39
|
-
|
40
|
-
events =
|
41
|
-
assert_equal([
|
38
|
+
rule_b2 = grammar2.rule(:b)
|
39
|
+
rule_a1 = grammar1.rule(:a)
|
40
|
+
events = rule_b2.exec(Input.new('abc'))
|
41
|
+
assert_equal([rule_b2.id, rule_a1.id, CLOSE, 3, CLOSE, 3], events)
|
42
42
|
end
|
43
43
|
|
44
44
|
def test_to_s
|
data/test/super_test.rb
CHANGED
@@ -16,10 +16,17 @@ class SuperTest < Test::Unit::TestCase
|
|
16
16
|
rule :a, any(ghi, sup)
|
17
17
|
}
|
18
18
|
rule_2a = grammar2.rule(:a)
|
19
|
+
rule_2a_sup = rule_2a.rules[1]
|
19
20
|
rule_1a = grammar1.rule(:a)
|
20
21
|
|
21
22
|
events = rule_2a.exec(Input.new('abc'))
|
22
|
-
assert_equal([
|
23
|
+
assert_equal([
|
24
|
+
rule_2a.id,
|
25
|
+
rule_2a_sup.id,
|
26
|
+
rule_1a.id, CLOSE, 3,
|
27
|
+
CLOSE, 3,
|
28
|
+
CLOSE, 3
|
29
|
+
], events)
|
23
30
|
|
24
31
|
events = rule_2a.exec(Input.new('ghi'))
|
25
32
|
assert_equal([rule_2a.id, ghi.id, CLOSE, 3, CLOSE, 3], events)
|
@@ -48,15 +55,32 @@ class SuperTest < Test::Unit::TestCase
|
|
48
55
|
rule :a, any(sup, :b)
|
49
56
|
rule :b, sup
|
50
57
|
}
|
51
|
-
rule_2a = grammar2.rule(:a)
|
52
58
|
rule_1a = grammar1.rule(:a)
|
53
59
|
rule_1b = grammar1.rule(:b)
|
60
|
+
rule_2a = grammar2.rule(:a)
|
61
|
+
rule_2a_sup = rule_2a.rules[0]
|
62
|
+
rule_2a_als = rule_2a.rules[1]
|
63
|
+
rule_2b = grammar2.rule(:b)
|
54
64
|
|
55
65
|
events = rule_2a.exec(Input.new('abc'))
|
56
|
-
assert_equal([
|
66
|
+
assert_equal([
|
67
|
+
rule_2a.id,
|
68
|
+
rule_2a_sup.id,
|
69
|
+
rule_1a.id, CLOSE, 3,
|
70
|
+
CLOSE, 3,
|
71
|
+
CLOSE, 3
|
72
|
+
], events)
|
57
73
|
|
58
74
|
events = rule_2a.exec(Input.new('def'))
|
59
|
-
assert_equal([
|
75
|
+
assert_equal([
|
76
|
+
rule_2a.id,
|
77
|
+
rule_2a_als.id,
|
78
|
+
rule_2b.id,
|
79
|
+
rule_1b.id, CLOSE, 3,
|
80
|
+
CLOSE, 3,
|
81
|
+
CLOSE, 3,
|
82
|
+
CLOSE, 3
|
83
|
+
], events)
|
60
84
|
end
|
61
85
|
|
62
86
|
def test_to_s
|
metadata
CHANGED
@@ -1,12 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: citrus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
segments:
|
6
|
-
- 2
|
7
|
-
- 2
|
8
|
-
- 0
|
9
|
-
version: 2.2.0
|
4
|
+
version: 2.2.1
|
10
5
|
platform: ruby
|
11
6
|
authors:
|
12
7
|
- Michael Jackson
|
@@ -14,22 +9,19 @@ autorequire:
|
|
14
9
|
bindir: bin
|
15
10
|
cert_chain: []
|
16
11
|
|
17
|
-
date: 2010-11-
|
12
|
+
date: 2010-11-15 00:00:00 -08:00
|
18
13
|
default_executable:
|
19
14
|
dependencies:
|
20
15
|
- !ruby/object:Gem::Dependency
|
21
16
|
name: rake
|
22
|
-
|
23
|
-
|
24
|
-
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
20
|
requirements:
|
26
21
|
- - ">="
|
27
22
|
- !ruby/object:Gem::Version
|
28
|
-
segments:
|
29
|
-
- 0
|
30
23
|
version: "0"
|
31
|
-
|
32
|
-
version_requirements: *id001
|
24
|
+
version:
|
33
25
|
description: Parsing Expressions for Ruby
|
34
26
|
email: mjijackson@gmail.com
|
35
27
|
executables: []
|
@@ -106,25 +98,21 @@ rdoc_options:
|
|
106
98
|
require_paths:
|
107
99
|
- lib
|
108
100
|
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
-
none: false
|
110
101
|
requirements:
|
111
102
|
- - ">="
|
112
103
|
- !ruby/object:Gem::Version
|
113
|
-
segments:
|
114
|
-
- 0
|
115
104
|
version: "0"
|
105
|
+
version:
|
116
106
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
-
none: false
|
118
107
|
requirements:
|
119
108
|
- - ">="
|
120
109
|
- !ruby/object:Gem::Version
|
121
|
-
segments:
|
122
|
-
- 0
|
123
110
|
version: "0"
|
111
|
+
version:
|
124
112
|
requirements: []
|
125
113
|
|
126
114
|
rubyforge_project:
|
127
|
-
rubygems_version: 1.3.
|
115
|
+
rubygems_version: 1.3.5
|
128
116
|
signing_key:
|
129
117
|
specification_version: 3
|
130
118
|
summary: Parsing Expressions for Ruby
|