ghostwheel 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +46 -0
- data/lib/ghost_wheel.rb +28 -0
- data/lib/ghost_wheel/build_parser.rb +11 -0
- data/lib/ghost_wheel/errors.rb +9 -0
- data/lib/ghost_wheel/expression.rb +22 -0
- data/lib/ghost_wheel/expression/alternation.rb +25 -0
- data/lib/ghost_wheel/expression/empty.rb +15 -0
- data/lib/ghost_wheel/expression/end_of_file.rb +19 -0
- data/lib/ghost_wheel/expression/literal.rb +31 -0
- data/lib/ghost_wheel/expression/look_ahead.rb +33 -0
- data/lib/ghost_wheel/expression/optional.rb +26 -0
- data/lib/ghost_wheel/expression/query.rb +32 -0
- data/lib/ghost_wheel/expression/repetition.rb +44 -0
- data/lib/ghost_wheel/expression/rule.rb +24 -0
- data/lib/ghost_wheel/expression/sequence.rb +30 -0
- data/lib/ghost_wheel/expression/transform.rb +30 -0
- data/lib/ghost_wheel/parse_results.rb +9 -0
- data/lib/ghost_wheel/parser.rb +71 -0
- data/lib/ghost_wheel/parser_builder/ghost_wheel.rb +100 -0
- data/lib/ghost_wheel/parser_builder/ruby.rb +175 -0
- data/lib/ghost_wheel/scanner.rb +42 -0
- data/setup.rb +1360 -0
- data/test/dsl/tc_build_parser.rb +29 -0
- data/test/dsl/tc_ghost_wheel_dsl.rb +143 -0
- data/test/dsl/tc_ruby_dsl.rb +227 -0
- data/test/example/tc_json_core.rb +95 -0
- data/test/example/tc_json_ghost_wheel.rb +48 -0
- data/test/example/tc_json_ruby.rb +81 -0
- data/test/helpers/ghost_wheel_namespace.rb +24 -0
- data/test/helpers/json_tests.rb +63 -0
- data/test/helpers/parse_helpers.rb +83 -0
- data/test/parser/tc_alternation_expression.rb +27 -0
- data/test/parser/tc_empty_expression.rb +15 -0
- data/test/parser/tc_end_of_file_expression.rb +27 -0
- data/test/parser/tc_literal_expression.rb +55 -0
- data/test/parser/tc_look_ahead_expression.rb +41 -0
- data/test/parser/tc_memoization.rb +31 -0
- data/test/parser/tc_optional_expression.rb +31 -0
- data/test/parser/tc_parser.rb +78 -0
- data/test/parser/tc_query_expression.rb +40 -0
- data/test/parser/tc_repetition_expression.rb +76 -0
- data/test/parser/tc_rule_expression.rb +32 -0
- data/test/parser/tc_scanning.rb +192 -0
- data/test/parser/tc_sequence_expression.rb +42 -0
- data/test/parser/tc_transform_expression.rb +77 -0
- data/test/ts_all.rb +7 -0
- data/test/ts_dsl.rb +8 -0
- data/test/ts_example.rb +7 -0
- data/test/ts_parser.rb +19 -0
- metadata +94 -0
@@ -0,0 +1,42 @@
|
|
1
|
+
#!/usr/bin/env ruby -w
|
2
|
+
|
3
|
+
require "test/unit"
|
4
|
+
|
5
|
+
require File.join(File.dirname(__FILE__), %w[.. helpers ghost_wheel_namespace])
|
6
|
+
require File.join(File.dirname(__FILE__), %w[.. helpers parse_helpers])
|
7
|
+
|
8
|
+
class TestSequenceExpression < Test::Unit::TestCase
|
9
|
+
include GhostWheelNamespace
|
10
|
+
include ParseHelpers
|
11
|
+
|
12
|
+
def setup
|
13
|
+
@source = Scanner.new("3 + 42")
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_match
|
17
|
+
assert_parses( %w[3 \ + \ 42],
|
18
|
+
parse_sequence("3", /\s*/, ?+, /\s*/, /\d+/) )
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_failed_match
|
22
|
+
assert_doesnt_parse(parse_sequence("3", /\s*/, ?*, /\s*/, /\d+/))
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_sequence_trims_empty_results
|
26
|
+
e = Empty.instance
|
27
|
+
assert_parses( %w[3 \ + \ 42],
|
28
|
+
parse_sequence("3", e, /\s*/, ?+, e, /\s*/, /\d+/, e) )
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_equality
|
32
|
+
assert_not_equal(Sequence.new(Literal.new("one")), Sequence.new)
|
33
|
+
assert_not_equal( Sequence.new(Literal.new("one"), Literal.new("two")),
|
34
|
+
Sequence.new(Literal.new("one")) )
|
35
|
+
assert_not_equal( Sequence.new(Literal.new("one"), Literal.new("two")),
|
36
|
+
Sequence.new(Literal.new("a"), Literal.new("b")) )
|
37
|
+
|
38
|
+
assert_equal(Sequence.new, Sequence.new)
|
39
|
+
assert_equal( Sequence.new(Literal.new("one"), Literal.new("two")),
|
40
|
+
Sequence.new(Literal.new("one"), Literal.new("two")) )
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
#!/usr/bin/env ruby -w
|
2
|
+
|
3
|
+
require "test/unit"
|
4
|
+
|
5
|
+
require File.join(File.dirname(__FILE__), %w[.. helpers ghost_wheel_namespace])
|
6
|
+
require File.join(File.dirname(__FILE__), %w[.. helpers parse_helpers])
|
7
|
+
|
8
|
+
class TestTransformExpression < Test::Unit::TestCase
|
9
|
+
include GhostWheelNamespace
|
10
|
+
include ParseHelpers
|
11
|
+
|
12
|
+
def test_transform_changes_parse_result
|
13
|
+
@parser = Transform.new(Literal.new(/(?:\\n|\\\\|[^\\]+)/)) do |str|
|
14
|
+
str == "\\\\" ? "\\" : str == "\\n" ? "\n" : str
|
15
|
+
end
|
16
|
+
|
17
|
+
assert_parses("\n", parse("\\n"))
|
18
|
+
assert_parses("word", parse("word"))
|
19
|
+
assert_parses("\\", parse("\\\\"))
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_building_up_a_complex_object_with_transforms
|
23
|
+
build_hash_parser
|
24
|
+
|
25
|
+
assert_parses(Hash.new, parse("{}"))
|
26
|
+
assert_parses({"James" => "Gray"}, parse(%Q{{"James" : "Gray"}}))
|
27
|
+
assert_parses( {"James" => "Gray", "Greg" => "Brown"},
|
28
|
+
parse(%Q{{"James": "Gray"; "Greg": "Brown"}}) )
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_yields_empty
|
32
|
+
Transform.new(Empty.instance) do |empty|
|
33
|
+
assert_instance_of(EmptyParseResult, empty)
|
34
|
+
end.parse(Scanner.new("not_used"))
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_equality
|
38
|
+
assert_not_equal( Transform.new(Literal.new("one")) { },
|
39
|
+
Transform.new(Literal.new("two")) { } )
|
40
|
+
assert_not_equal( Transform.new(Literal.new("one")) { Array.new },
|
41
|
+
Transform.new(Literal.new("one")) { } )
|
42
|
+
|
43
|
+
block = lambda { Array.new } # must be *exact* same block
|
44
|
+
assert_equal( Transform.new(Literal.new("one"), &block),
|
45
|
+
Transform.new(Literal.new("one"), &block) )
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def build_hash_parser
|
51
|
+
# optional whitespace
|
52
|
+
space = Optional.new(Literal.new(/\s+/, true))
|
53
|
+
# a string literal
|
54
|
+
string = Transform.new(Literal.new(/"[^"]*"/)) { |str| str[1..-2] }
|
55
|
+
# a key/value pair in the Hash
|
56
|
+
pair = Transform.new(
|
57
|
+
Sequence.new(string, space, Literal.new(":"), space, string)
|
58
|
+
) { |key_and_val| {key_and_val.first => key_and_val.last} }
|
59
|
+
# a pair plus separator
|
60
|
+
join = Sequence.new(pair, space, Literal.new(";", true), space)
|
61
|
+
# the primary parser for merging a sequence of pairs into a Ruby Hash
|
62
|
+
@parser = Transform.new(
|
63
|
+
Sequence.new(
|
64
|
+
Literal.new("{", true),
|
65
|
+
space,
|
66
|
+
Alternation.new(
|
67
|
+
Transform.new(
|
68
|
+
Sequence.new(Repetition.new(join, 1), pair)
|
69
|
+
) { |pairs| pairs.first.first + [pairs.last] },
|
70
|
+
Sequence.new(Optional.new(pair))
|
71
|
+
),
|
72
|
+
space,
|
73
|
+
Literal.new("}", true)
|
74
|
+
)
|
75
|
+
) { |pairs| pairs.first.inject(Hash.new) { |hash, pair| hash.merge(pair) } }
|
76
|
+
end
|
77
|
+
end
|
data/test/ts_all.rb
ADDED
data/test/ts_dsl.rb
ADDED
data/test/ts_example.rb
ADDED
data/test/ts_parser.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby -w
|
2
|
+
|
3
|
+
require "test/unit"
|
4
|
+
|
5
|
+
require "parser/tc_scanning"
|
6
|
+
|
7
|
+
require "parser/tc_literal_expression"
|
8
|
+
require "parser/tc_sequence_expression"
|
9
|
+
require "parser/tc_alternation_expression"
|
10
|
+
require "parser/tc_empty_expression"
|
11
|
+
require "parser/tc_optional_expression"
|
12
|
+
require "parser/tc_repetition_expression"
|
13
|
+
require "parser/tc_look_ahead_expression"
|
14
|
+
require "parser/tc_end_of_file_expression"
|
15
|
+
require "parser/tc_query_expression"
|
16
|
+
require "parser/tc_transform_expression"
|
17
|
+
require "parser/tc_rule_expression"
|
18
|
+
|
19
|
+
require "parser/tc_memoization"
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.4
|
3
|
+
specification_version: 1
|
4
|
+
name: ghostwheel
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.0.1
|
7
|
+
date: 2007-07-02 00:00:00 -05:00
|
8
|
+
summary: Ghost Wheel is a pure Ruby parser generator.
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: james@grayproductions.net
|
12
|
+
homepage: http://ghostwheel.rubyforge.org
|
13
|
+
rubyforge_project: ghostwheel
|
14
|
+
description: Ghost Wheel is a packrat parser generator handling scanning and parsing of context-free grammars. Parsers can be built using an EBNF-like syntax or a with a Ruby DSL.
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: false
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- James Edward Gray II
|
31
|
+
files:
|
32
|
+
- lib/ghost_wheel/build_parser.rb
|
33
|
+
- lib/ghost_wheel/errors.rb
|
34
|
+
- lib/ghost_wheel/expression/alternation.rb
|
35
|
+
- lib/ghost_wheel/expression/empty.rb
|
36
|
+
- lib/ghost_wheel/expression/end_of_file.rb
|
37
|
+
- lib/ghost_wheel/expression/literal.rb
|
38
|
+
- lib/ghost_wheel/expression/look_ahead.rb
|
39
|
+
- lib/ghost_wheel/expression/optional.rb
|
40
|
+
- lib/ghost_wheel/expression/query.rb
|
41
|
+
- lib/ghost_wheel/expression/repetition.rb
|
42
|
+
- lib/ghost_wheel/expression/rule.rb
|
43
|
+
- lib/ghost_wheel/expression/sequence.rb
|
44
|
+
- lib/ghost_wheel/expression/transform.rb
|
45
|
+
- lib/ghost_wheel/expression.rb
|
46
|
+
- lib/ghost_wheel/parse_results.rb
|
47
|
+
- lib/ghost_wheel/parser.rb
|
48
|
+
- lib/ghost_wheel/parser_builder/ghost_wheel.rb
|
49
|
+
- lib/ghost_wheel/parser_builder/ruby.rb
|
50
|
+
- lib/ghost_wheel/scanner.rb
|
51
|
+
- lib/ghost_wheel.rb
|
52
|
+
- test/dsl/tc_build_parser.rb
|
53
|
+
- test/dsl/tc_ghost_wheel_dsl.rb
|
54
|
+
- test/dsl/tc_ruby_dsl.rb
|
55
|
+
- test/example/tc_json_core.rb
|
56
|
+
- test/example/tc_json_ghost_wheel.rb
|
57
|
+
- test/example/tc_json_ruby.rb
|
58
|
+
- test/helpers/ghost_wheel_namespace.rb
|
59
|
+
- test/helpers/json_tests.rb
|
60
|
+
- test/helpers/parse_helpers.rb
|
61
|
+
- test/parser/tc_alternation_expression.rb
|
62
|
+
- test/parser/tc_empty_expression.rb
|
63
|
+
- test/parser/tc_end_of_file_expression.rb
|
64
|
+
- test/parser/tc_literal_expression.rb
|
65
|
+
- test/parser/tc_look_ahead_expression.rb
|
66
|
+
- test/parser/tc_memoization.rb
|
67
|
+
- test/parser/tc_optional_expression.rb
|
68
|
+
- test/parser/tc_parser.rb
|
69
|
+
- test/parser/tc_query_expression.rb
|
70
|
+
- test/parser/tc_repetition_expression.rb
|
71
|
+
- test/parser/tc_rule_expression.rb
|
72
|
+
- test/parser/tc_scanning.rb
|
73
|
+
- test/parser/tc_sequence_expression.rb
|
74
|
+
- test/parser/tc_transform_expression.rb
|
75
|
+
- test/ts_all.rb
|
76
|
+
- test/ts_dsl.rb
|
77
|
+
- test/ts_example.rb
|
78
|
+
- test/ts_parser.rb
|
79
|
+
- Rakefile
|
80
|
+
- setup.rb
|
81
|
+
test_files:
|
82
|
+
- test/ts_all.rb
|
83
|
+
rdoc_options: []
|
84
|
+
|
85
|
+
extra_rdoc_files: []
|
86
|
+
|
87
|
+
executables: []
|
88
|
+
|
89
|
+
extensions: []
|
90
|
+
|
91
|
+
requirements: []
|
92
|
+
|
93
|
+
dependencies: []
|
94
|
+
|