pegex 0.0.2 → 0.0.3

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.
@@ -0,0 +1,64 @@
1
+ require 'testml/bridge'
2
+ require 'testml/util'; include TestML::Util
3
+ require 'pegex'
4
+ require 'pegex/compiler'
5
+ require 'pegex/tree'
6
+ require 'pegex/tree/wrap'
7
+ require 'testast'
8
+ require 'yaml'
9
+ # XXX can we eliminate this?
10
+ require 'recursive_sort'
11
+
12
+ class TestMLBridge < TestML::Bridge
13
+ def compile grammar
14
+ tree = Pegex::Compiler.new.parse(grammar.value).combinate.tree
15
+ tree.delete '+toprule'
16
+ return native tree
17
+ end
18
+
19
+ alias bootstrap_compile compile
20
+
21
+ def compress grammar
22
+ grammar = grammar.value
23
+ grammar.gsub! /([^;])\n(\w+\s*:)/, '\1;\2'
24
+ grammar.gsub! /\s/, ''
25
+
26
+ # XXX mod/quant ERROR rules are too protective here:
27
+ grammar.gsub! />%</, '> % <'
28
+
29
+ return str "#{grammar}\n"
30
+ end
31
+
32
+ def yaml object
33
+ return str YAML.dump(object.value.recursive_sort)
34
+ end
35
+
36
+ def clean yaml
37
+ yaml = yaml.value
38
+ yaml.sub! /^\.\.\.\n/, ''
39
+ yaml.sub! /\A---\s/, ''
40
+ yaml.gsub! /'(\d+)'/, '\1'
41
+ yaml.gsub! /\+eok: true/, '+eok: 1'
42
+ return str yaml
43
+ end
44
+
45
+ def parse_input grammar, input
46
+ parser = pegex(grammar.value)
47
+ return native parser.parse input.value
48
+ end
49
+
50
+ def parse_to_tree(grammar, input)
51
+ parser = pegex(grammar.value, Pegex::Tree)
52
+ return native parser.parse(input.value)
53
+ end
54
+
55
+ def parse_to_tree_wrap(grammar, input)
56
+ parser = pegex(grammar.value, Pegex::Tree::Wrap)
57
+ return native parser.parse(input.value)
58
+ end
59
+
60
+ def parse_to_tree_test(grammar, input)
61
+ parser = pegex(grammar.value, TestAST)
62
+ return native parser.parse(input.value)
63
+ end
64
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pegex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,16 +9,16 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-20 00:00:00.000000000 Z
12
+ date: 2013-04-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: testml-lite
15
+ name: testml
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 0.0.1
21
+ version: 0.0.2
22
22
  type: :development
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
- version: 0.0.1
29
+ version: 0.0.2
30
30
  description: ! 'Pegex is a Acmeist parser framework. It allows you to easily create
31
31
  parsers
32
32
 
@@ -39,6 +39,7 @@ extensions: []
39
39
  extra_rdoc_files: []
40
40
  files:
41
41
  - .gemspec
42
+ - .profile
42
43
  - CHANGELOG.yaml
43
44
  - Gemfile
44
45
  - Gemfile.lock
@@ -57,22 +58,26 @@ files:
57
58
  - lib/pegex/receiver.rb
58
59
  - lib/pegex/tree.rb
59
60
  - lib/pegex/tree/wrap.rb
60
- - test/compiler-checks.rb
61
- - test/compiler-checks.tml
62
- - test/compiler-equivalence.rb
63
- - test/compiler.rb
64
- - test/compiler.tml
65
- - test/error.rb
66
- - test/export_ok.rb
61
+ - test/export-api.rb
62
+ - test/flatten.rb
67
63
  - test/grammar-api.rb
68
64
  - test/lib/recursive_sort.rb
69
- - test/lib/test_pegex.rb
70
65
  - test/lib/testast.rb
71
66
  - test/lib/xxx.rb
72
- - test/optimize.rb
73
- - test/tree-pegex.tml
74
- - test/tree.rb
75
- - test/tree.tml
67
+ - test/mice.pgx
68
+ - test/parse.rb
69
+ - test/repeat.rb
70
+ - test/sample.rb
71
+ - test/testml.rb
72
+ - test/testml.yaml
73
+ - test/testml/compiler-checks.tml
74
+ - test/testml/compiler-equivalence.tml
75
+ - test/testml/compiler.tml
76
+ - test/testml/error.tml
77
+ - test/testml/optimize.tml
78
+ - test/testml/tree-pegex.tml
79
+ - test/testml/tree.tml
80
+ - test/testml_bridge.rb
76
81
  homepage: http://pegex.org
77
82
  licenses:
78
83
  - MIT
@@ -1,271 +0,0 @@
1
- require './test/lib/test_pegex'
2
-
3
- TestML.require_or_skip 'psych'
4
-
5
- TestML.run do |t|
6
- t.eval '*grammar.compile.yaml.clean == *yaml'
7
- end
8
-
9
- TestML.data <<'...'
10
- === Empty Grammar
11
- --- grammar
12
- --- yaml
13
- {}
14
-
15
- === Simple Grammar
16
- --- grammar
17
- a: ( <b> <c>* )+
18
- b: /x/
19
- c: <x>
20
-
21
- --- yaml
22
- a:
23
- +min: 1
24
- .all:
25
- - .ref: b
26
- - +min: 0
27
- .ref: c
28
- b:
29
- .rgx: x
30
- c:
31
- .ref: x
32
-
33
- === Single Rule Reference
34
- --- grammar
35
- a: <x>
36
- --- yaml
37
- a:
38
- .ref: x
39
-
40
- === Single Rule with no brackets
41
- --- grammar
42
- a: x
43
- --- yaml
44
- a:
45
- .ref: x
46
-
47
- === Single Rule With Trailing Quantifier
48
- --- grammar
49
- a: <x>*
50
- --- yaml
51
- a:
52
- +min: 0
53
- .ref: x
54
-
55
- === Single Rule With Trailing Quantifier (no angles)
56
- --- grammar
57
- a: x*
58
- --- yaml
59
- a:
60
- +min: 0
61
- .ref: x
62
-
63
- === Single Rule With Leading Assertion
64
- --- grammar
65
- a: =<x>
66
- --- yaml
67
- a:
68
- +asr: 1
69
- .ref: x
70
-
71
- === Negative and Positive Assertion
72
- --- grammar
73
- a: !<b> =<c>
74
- --- yaml
75
- a:
76
- .all:
77
- - +asr: -1
78
- .ref: b
79
- - +asr: 1
80
- .ref: c
81
-
82
- === Single Regex
83
- --- grammar
84
- a: /x/
85
- --- yaml
86
- a:
87
- .rgx: x
88
-
89
- === Single Error
90
- --- grammar
91
- a: `x`
92
- --- yaml
93
- a:
94
- .err: x
95
-
96
- === Skip and Wrap Marker
97
- --- grammar
98
- a: .<b> +<c>+ -<d>?
99
- --- yaml
100
- a:
101
- .all:
102
- - -skip: 1
103
- .ref: b
104
- - +min: 1
105
- -wrap: 1
106
- .ref: c
107
- - +max: 1
108
- -pass: 1
109
- .ref: d
110
-
111
- === Unbracketed All Group
112
- --- grammar
113
- a: /x/ <y>
114
- --- yaml
115
- a:
116
- .all:
117
- - .rgx: x
118
- - .ref: y
119
-
120
- === Unbracketed Any Group
121
- --- grammar
122
- a: /x/ | <y> | `z`
123
- --- yaml
124
- a:
125
- .any:
126
- - .rgx: x
127
- - .ref: y
128
- - .err: z
129
-
130
- === Bracketed All Group
131
- --- grammar
132
- a: ( <x> <y> )
133
- --- yaml
134
- a:
135
- .all:
136
- - .ref: x
137
- - .ref: y
138
-
139
- === Bracketed Group With Trailing Modifier
140
- --- grammar
141
- a: ( <x> <y> )?
142
- --- yaml
143
- a:
144
- +max: 1
145
- .all:
146
- - .ref: x
147
- - .ref: y
148
-
149
- === Bracketed Group With Leading Modifier
150
- --- grammar
151
- a: .( =<x> <y> )
152
- --- yaml
153
- a:
154
- -skip: 1
155
- .all:
156
- - +asr: 1
157
- .ref: x
158
- - .ref: y
159
-
160
- === Multiple Groups
161
- --- grammar
162
- a: ( <x> <y> ) ( <z> | /zzz/ )
163
- --- yaml
164
- a:
165
- .all:
166
- - .all:
167
- - .ref: x
168
- - .ref: y
169
- - .any:
170
- - .ref: z
171
- - .rgx: zzz
172
-
173
- === List Separator
174
- --- grammar
175
- a: <b> | <c>? %% /d/
176
- --- yaml
177
- a:
178
- .any:
179
- - .ref: b
180
- - +max: 1
181
- .ref: c
182
- .sep:
183
- +eok: 1
184
- .rgx: d
185
-
186
- === Separators with Quantifiers
187
- --- grammar
188
- a: <b>2+ % <c>* <d>* %% <e>2-3
189
- --- yaml
190
- a:
191
- .all:
192
- - +min: 2
193
- .ref: b
194
- .sep:
195
- +min: 0
196
- .ref: c
197
- - +min: 0
198
- .ref: d
199
- .sep:
200
- +eok: 1
201
- +max: 3
202
- +min: 2
203
- .ref: e
204
-
205
- === All Quantifier Forms
206
- --- grammar
207
- a: <b> <c>? <d>* <e>+ <f>55 <g>5+ <h>5-55
208
- --- yaml
209
- a:
210
- .all:
211
- - .ref: b
212
- - +max: 1
213
- .ref: c
214
- - +min: 0
215
- .ref: d
216
- - +min: 1
217
- .ref: e
218
- - +max: 55
219
- +min: 55
220
- .ref: f
221
- - +min: 5
222
- .ref: g
223
- - +max: 55
224
- +min: 5
225
- .ref: h
226
-
227
- === Whitespace in Regex
228
- --- grammar
229
- a: /<DOT>* (<DASH>{3})
230
- <BANG> <BANG>
231
- /
232
- --- yaml
233
- a:
234
- .rgx: \.*(\-{3})!!
235
-
236
- === Directives
237
- --- grammar
238
- \%grammar foo
239
- \%version 1.2.3
240
-
241
- --- yaml
242
- +grammar: foo
243
- +version: 1.2.3
244
-
245
- === Multiple Duplicate Directives
246
- --- grammar
247
- \%grammar foo
248
- \%include bar
249
- \%include baz
250
-
251
- --- yaml
252
- +grammar: foo
253
- +include:
254
- - bar
255
- - baz
256
-
257
- === Meta Lines
258
- --- grammar
259
- %grammar foo
260
- %version 1.1.1
261
- %extends bar bar
262
- %include bazzy
263
- a: /b/
264
- --- yaml
265
- +extends: bar bar
266
- +grammar: foo
267
- +include: bazzy
268
- +version: 1.1.1
269
- a:
270
- .rgx: b
271
- ...
@@ -1,42 +0,0 @@
1
- require './test/lib/test_pegex'
2
-
3
- TestML.require_or_skip 'psych'
4
-
5
- TestML.data 'test/compiler.tml'
6
-
7
- TestML.run do |t|
8
- t.eval '*grammar', t.method('run_compiler_tests')
9
- end
10
-
11
- class TestPegex
12
- def run_compiler_tests block, expr=nil
13
- label '$BlockLabel - Compiler output matches bootstrap?'
14
- run_test(
15
- block,
16
- '*grammar.compile.yaml == *grammar.compile.yaml',
17
- )
18
-
19
- label '$BlockLabel - Compressed grammar compiles the same?'
20
- run_test(
21
- block,
22
- '*grammar.compress.compile.yaml == *grammar.compress.compile.yaml',
23
- )
24
-
25
- label '$BlockLabel - Compressed grammar matches uncompressed?'
26
- run_test(
27
- block,
28
- '*grammar.compress.compile.yaml == *grammar.compile.yaml',
29
- )
30
- end
31
-
32
- def compress grammar_text
33
- grammar_text.gsub! /([^;])\n(\w+\s*:)/ do |m|
34
- "#{$1};#{$2}"
35
- end
36
- grammar_text.gsub! /\s/, ''
37
-
38
- # XXX mod/quant ERROR rules are too prtective here:
39
- grammar_text.gsub! />%</, '> % <'
40
- return "#{grammar_text}\n"
41
- end
42
- end