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.
- data/.gemspec +2 -2
- data/.profile +2 -0
- data/CHANGELOG.yaml +3 -0
- data/LICENSE +1 -1
- data/README.rdoc +26 -24
- data/Rakefile +10 -1
- data/ToDo +3 -0
- data/lib/pegex.rb +4 -5
- data/lib/pegex/grammar.rb +1 -0
- data/lib/pegex/input.rb +1 -0
- data/lib/pegex/parser.rb +52 -54
- data/lib/pegex/pegex/ast.rb +6 -6
- data/lib/pegex/tree.rb +1 -1
- data/lib/pegex/tree/wrap.rb +2 -2
- data/test/export-api.rb +38 -0
- data/test/flatten.rb +30 -0
- data/test/grammar-api.rb +20 -8
- data/test/lib/xxx.rb +4 -4
- data/test/mice.pgx +7 -0
- data/test/parse.rb +18 -0
- data/test/repeat.rb +10 -0
- data/test/sample.rb +72 -0
- data/test/testml.rb +25 -0
- data/test/testml.yaml +3 -0
- data/test/{compiler-checks.tml → testml/compiler-checks.tml} +8 -11
- data/test/{compiler-equivalence.rb → testml/compiler-equivalence.tml} +2 -8
- data/test/{compiler.tml → testml/compiler.tml} +13 -0
- data/test/{error.rb → testml/error.tml} +2 -13
- data/test/testml/optimize.tml +14 -0
- data/test/{tree-pegex.tml → testml/tree-pegex.tml} +11 -1
- data/test/{tree.tml → testml/tree.tml} +23 -9
- data/test/testml_bridge.rb +64 -0
- metadata +22 -17
- data/test/compiler-checks.rb +0 -271
- data/test/compiler.rb +0 -42
- data/test/export_ok.rb +0 -36
- data/test/lib/test_pegex.rb +0 -33
- data/test/optimize.rb +0 -18
- data/test/tree.rb +0 -47
data/test/export_ok.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
require './test/lib/test_pegex'
|
2
|
-
|
3
|
-
TestML.run do |t|
|
4
|
-
require 'pegex'
|
5
|
-
t.assert method('pegex'),
|
6
|
-
'pegex is exported'
|
7
|
-
|
8
|
-
parser1 = pegex "foo: <bar>\n"
|
9
|
-
|
10
|
-
t.assert parser1.kind_of?(Pegex::Parser),
|
11
|
-
'pegex returns a Pegex::Parser object'
|
12
|
-
|
13
|
-
t.assert_equal parser1.grammar.tree['+toprule'], 'foo',
|
14
|
-
'pegex() contains a grammar with a compiled tree'
|
15
|
-
|
16
|
-
parser2 = pegex(<<'...');
|
17
|
-
number: /<DIGIT>+/
|
18
|
-
...
|
19
|
-
|
20
|
-
begin
|
21
|
-
parser2.parse '123'
|
22
|
-
t.assert true, 'parser2.parse worked'
|
23
|
-
rescue
|
24
|
-
t.assert false, "parser2.parse failed: #{$!.message}"
|
25
|
-
end
|
26
|
-
|
27
|
-
t.assert parser2.kind_of?(Pegex::Parser),
|
28
|
-
'grammar property is Pegex::Parser object'
|
29
|
-
|
30
|
-
tree2 = parser2.grammar.tree
|
31
|
-
t.assert tree2, 'Grammar object has tree';
|
32
|
-
t.assert tree2.kind_of?(Hash), 'Grammar object is compiled to a tree'
|
33
|
-
|
34
|
-
t.assert_equal tree2['+toprule'], 'number',
|
35
|
-
'_FIRST_RULE is set correctly'
|
36
|
-
end
|
data/test/lib/test_pegex.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'testml/lite'
|
2
|
-
require 'pegex/compiler'
|
3
|
-
require 'recursive_sort'
|
4
|
-
|
5
|
-
class TestPegex < TestML::Lite
|
6
|
-
include TestML::Lite::TestCases
|
7
|
-
|
8
|
-
def compile grammar_text
|
9
|
-
$grammar_text = grammar_text
|
10
|
-
tree = Pegex::Compiler.new.parse(grammar_text).combinate.tree
|
11
|
-
tree.delete '+toprule'
|
12
|
-
return tree
|
13
|
-
end
|
14
|
-
|
15
|
-
def yaml object
|
16
|
-
require 'psych'
|
17
|
-
Psych.dump object.recursive_sort
|
18
|
-
end
|
19
|
-
|
20
|
-
def clean yaml
|
21
|
-
yaml.sub! /^\.\.\.\n/, ''
|
22
|
-
yaml.sub! /\A---\s/, ''
|
23
|
-
yaml.gsub! /'(\d+)'/, '\1'
|
24
|
-
yaml.gsub! /\+eok: true/, '+eok: 1'
|
25
|
-
return yaml
|
26
|
-
end
|
27
|
-
|
28
|
-
def on_fail
|
29
|
-
puts "Parsing this Pegex grammar:"
|
30
|
-
puts $grammar_text
|
31
|
-
puts
|
32
|
-
end
|
33
|
-
end
|
data/test/optimize.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require './test/lib/test_pegex'
|
2
|
-
|
3
|
-
__END__
|
4
|
-
#TODO
|
5
|
-
TestML.require_or_skip 'psych'
|
6
|
-
|
7
|
-
TestML.run do |t|
|
8
|
-
t.eval '*grammar.compile.optimize.yaml.clean == *yaml'
|
9
|
-
end
|
10
|
-
|
11
|
-
TestML.data <<'...'
|
12
|
-
=== Question Mark Expansion
|
13
|
-
--- grammar
|
14
|
-
a: /(:foo)/
|
15
|
-
--- yaml
|
16
|
-
a:
|
17
|
-
.rgx: /(?:foo)/
|
18
|
-
...
|
data/test/tree.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
require './test/lib/test_pegex'
|
2
|
-
|
3
|
-
TestML.require_or_skip 'psych'
|
4
|
-
|
5
|
-
TestML.run do |t|
|
6
|
-
files = [
|
7
|
-
'test/tree.tml',
|
8
|
-
'test/tree-pegex.tml',
|
9
|
-
]
|
10
|
-
|
11
|
-
files.each do |f|
|
12
|
-
t.data f
|
13
|
-
t.eval '*grammar', t.method('run_tree_tests')
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
class TestPegex
|
18
|
-
require 'pegex/tree'
|
19
|
-
require 'pegex/tree/wrap'
|
20
|
-
require 'testast'
|
21
|
-
def run_tree_tests block, expr=nil
|
22
|
-
label '$BlockLabel - Pegex::Tree'
|
23
|
-
run_test(
|
24
|
-
block,
|
25
|
-
"parse_to_tree('Pegex::Tree', *grammar, *input).yaml.clean == *tree",
|
26
|
-
)
|
27
|
-
|
28
|
-
label('$BlockLabel - Pegex::Tree::Wrap');
|
29
|
-
run_test(
|
30
|
-
block,
|
31
|
-
"parse_to_tree('Pegex::Tree::Wrap', *grammar, *input).yaml.clean == *wrap",
|
32
|
-
)
|
33
|
-
|
34
|
-
label('$BlockLabel - t::TestAST');
|
35
|
-
run_test(
|
36
|
-
block,
|
37
|
-
"parse_to_tree('TestAST', *grammar, *input).yaml.clean == *ast",
|
38
|
-
)
|
39
|
-
end
|
40
|
-
|
41
|
-
require 'pegex'
|
42
|
-
def parse_to_tree(receiver, grammar, input)
|
43
|
-
require receiver.downcase.gsub /::/, '/'
|
44
|
-
parser = pegex(grammar, Kernel.eval(receiver))
|
45
|
-
return parser.parse(input)
|
46
|
-
end
|
47
|
-
end
|