fabulator-grammar 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
data/History.txt
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.6
|
data/features/library.feature
CHANGED
@@ -31,8 +31,8 @@ Feature: Grammars embedded in libraries
|
|
31
31
|
</g:grammar>
|
32
32
|
</l:library>
|
33
33
|
"""
|
34
|
-
Then the expression (m:something?('a0A')) should
|
35
|
-
And the expression (m:something?('a0a')) should
|
34
|
+
Then the expression (m:something?('a0A')) should be true
|
35
|
+
And the expression (m:something?('a0a')) should be false
|
36
36
|
And the expression (m:something('a0A')/NUMBER) should equal ['0']
|
37
37
|
And the expression (m:something2('a0A')/foo) should equal ['0']
|
38
38
|
|
@@ -73,11 +73,31 @@ Feature: Grammars embedded in libraries
|
|
73
73
|
<f:value-of f:select="$1 - $2" />
|
74
74
|
</l:function>
|
75
75
|
<l:action l:name="actn" l:has-actions="true">
|
76
|
+
<l:attribute l:name="foo" />
|
76
77
|
<f:value-of f:select="f:eval($actions) * 3" />
|
77
78
|
</l:action>
|
78
79
|
<l:action l:name="actn2" l:has-actions="true">
|
79
80
|
<my:actn><f:value-of f:select="f:eval($actions) * 5" /></my:actn>
|
80
81
|
</l:action>
|
82
|
+
<l:action l:name="actn3">
|
83
|
+
<l:attribute l:name="path" l:eval="true" />
|
84
|
+
<f:value f:path="f:eval($path)" f:select="3" />
|
85
|
+
</l:action>
|
86
|
+
<l:action l:name="actn4">
|
87
|
+
<l:attribute l:name="foo" l:eval="false" />
|
88
|
+
<f:value f:path="/actn4foo" f:select="f:eval($foo)" />
|
89
|
+
</l:action>
|
90
|
+
<l:template l:name="tmpl">
|
91
|
+
Foo
|
92
|
+
</l:template>
|
93
|
+
<l:template l:name="tmpl2">
|
94
|
+
<f:value-of f:select="$1" />
|
95
|
+
</l:template>
|
96
|
+
<l:template l:name="tmpl3">
|
97
|
+
<p>
|
98
|
+
<f:value-of f:select="$1" />
|
99
|
+
</p>
|
100
|
+
</l:template>
|
81
101
|
</l:library>
|
82
102
|
"""
|
83
103
|
And the statemachine
|
@@ -85,6 +105,8 @@ Feature: Grammars embedded in libraries
|
|
85
105
|
<f:application xmlns:f="http://dh.tamu.edu/ns/fabulator/1.0#"
|
86
106
|
xmlns:m="http://example.com/ns/grammar"
|
87
107
|
>
|
108
|
+
<m:actn3 m:path="/actn3" />
|
109
|
+
<m:actn4 m:foo="bar" />
|
88
110
|
<f:view f:name="start">
|
89
111
|
<f:goes-to f:view="step1">
|
90
112
|
<f:params>
|
@@ -116,6 +138,8 @@ Feature: Grammars embedded in libraries
|
|
116
138
|
</f:application>
|
117
139
|
"""
|
118
140
|
Then it should be in the 'start' state
|
141
|
+
And the expression (/actn3) should equal [3]
|
142
|
+
And the expression (/actn4foo) should equal ['bar']
|
119
143
|
When I run it with the following params:
|
120
144
|
| key | value |
|
121
145
|
| foo | bar a0a que |
|
@@ -139,3 +163,6 @@ Feature: Grammars embedded in libraries
|
|
139
163
|
Then it should be in the 'stop' state
|
140
164
|
And the expression (/bar) should equal ['a0B']
|
141
165
|
And the expression (m:fctn(3,2)) should equal [1]
|
166
|
+
And the expression (f:normalize-space(m:tmpl())) should equal ['Foo']
|
167
|
+
And the expression (f:normalize-space(m:tmpl2('Foo'))) should equal ['Foo']
|
168
|
+
And the expression (f:normalize-space(m:tmpl3('Foo'))) should equal ['<p> Foo </p>']
|
@@ -98,6 +98,14 @@ Then /the (expression \(.*\)) should equal (\[.*\])/ do |x, y|
|
|
98
98
|
a.first.value.should == b.first.value
|
99
99
|
end
|
100
100
|
|
101
|
+
Then /the (expression \(.*\)) should be true/ do |x|
|
102
|
+
x.run(@context).first.value.should == true
|
103
|
+
end
|
104
|
+
|
105
|
+
Then /the (expression \(.*\)) should be false/ do |x|
|
106
|
+
x.run(@context).first.value.should == false
|
107
|
+
end
|
108
|
+
|
101
109
|
Then /the (expression \(.*\)) should be nil/ do |x|
|
102
110
|
x.run(@context).first.should == nil
|
103
111
|
end
|
@@ -73,7 +73,7 @@ module Fabulator
|
|
73
73
|
nom.gsub!(/\?$/, '')
|
74
74
|
ret = matching ? strings.collect{ |s| self.match(context, nom, s) } :
|
75
75
|
strings.collect{ |s| self.parse(context, nom, s) }
|
76
|
-
|
76
|
+
ret -= [ nil ]
|
77
77
|
if matching
|
78
78
|
ret = ret.collect{ |r| context.root.anon_node(!!r, [FAB_NS, 'boolean']) }
|
79
79
|
else
|
@@ -30,6 +30,7 @@ module Fabulator::Grammar::Expr
|
|
30
30
|
}
|
31
31
|
end
|
32
32
|
end
|
33
|
+
self.compute_regex
|
33
34
|
end
|
34
35
|
|
35
36
|
def set
|
@@ -38,20 +39,27 @@ module Fabulator::Grammar::Expr
|
|
38
39
|
|
39
40
|
def or(c)
|
40
41
|
@set = @set | c.set
|
42
|
+
self.compute_regex
|
41
43
|
self
|
42
44
|
end
|
43
45
|
|
44
46
|
def but_not(c)
|
45
47
|
@set = @set - c.set
|
48
|
+
self.compute_regex
|
46
49
|
self
|
47
50
|
end
|
48
51
|
|
49
52
|
# for now, we restrict ourselves to 8-bit characters
|
50
53
|
def universal
|
51
54
|
@set.on(0..0xff)
|
55
|
+
self.compute_regex
|
52
56
|
end
|
53
57
|
|
54
58
|
def to_regex
|
59
|
+
@regex
|
60
|
+
end
|
61
|
+
|
62
|
+
def compute_regex
|
55
63
|
# want a compact set of ranges for the regex
|
56
64
|
set_def = ''
|
57
65
|
@set.to_ary.each do |r|
|
@@ -62,9 +70,9 @@ module Fabulator::Grammar::Expr
|
|
62
70
|
end
|
63
71
|
end
|
64
72
|
if set_def == ''
|
65
|
-
|
73
|
+
@regex = %r{.}
|
66
74
|
else
|
67
|
-
%r{[#{set_def}]}
|
75
|
+
@regex = %r{[#{set_def}]}
|
68
76
|
end
|
69
77
|
end
|
70
78
|
end
|
@@ -89,6 +97,7 @@ module Fabulator::Grammar::Expr
|
|
89
97
|
|
90
98
|
def initialize(cs)
|
91
99
|
@set = BitSet.new.on(@@charsets[cs.downcase] || [])
|
100
|
+
self.compute_regex
|
92
101
|
end
|
93
102
|
end
|
94
103
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fabulator-grammar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 6
|
10
|
+
version: 0.0.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- James Smith
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-12-08 00:00:00 +00:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|