treetop 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +3 -0
- data/Rakefile +35 -0
- data/bin/tt +25 -0
- data/lib/treetop.rb +10 -6
- data/lib/treetop/compiler.rb +7 -0
- data/lib/treetop/compiler/grammar_compiler.rb +21 -0
- data/lib/treetop/compiler/lexical_address_space.rb +17 -0
- data/lib/treetop/compiler/load_grammar.rb +7 -0
- data/lib/treetop/compiler/metagrammar.rb +2441 -0
- data/lib/treetop/compiler/metagrammar.treetop +384 -0
- data/lib/treetop/compiler/node_classes.rb +18 -0
- data/lib/treetop/compiler/node_classes/anything_symbol.rb +10 -0
- data/lib/treetop/compiler/node_classes/atomic_expression.rb +9 -0
- data/lib/treetop/compiler/node_classes/character_class.rb +10 -0
- data/lib/treetop/compiler/node_classes/choice.rb +31 -0
- data/lib/treetop/compiler/node_classes/declaration_sequence.rb +24 -0
- data/lib/treetop/compiler/node_classes/grammar.rb +28 -0
- data/lib/treetop/compiler/node_classes/inline_module.rb +27 -0
- data/lib/treetop/compiler/node_classes/nonterminal.rb +11 -0
- data/lib/treetop/compiler/node_classes/optional.rb +19 -0
- data/lib/treetop/compiler/node_classes/parenthesized_expression.rb +9 -0
- data/lib/treetop/compiler/node_classes/parsing_expression.rb +132 -0
- data/lib/treetop/compiler/node_classes/parsing_rule.rb +55 -0
- data/lib/treetop/compiler/node_classes/predicate.rb +45 -0
- data/lib/treetop/compiler/node_classes/repetition.rb +56 -0
- data/lib/treetop/compiler/node_classes/sequence.rb +64 -0
- data/lib/treetop/compiler/node_classes/terminal.rb +10 -0
- data/lib/treetop/compiler/node_classes/treetop_file.rb +9 -0
- data/lib/treetop/compiler/ruby_builder.rb +109 -0
- data/lib/treetop/ruby_extensions.rb +2 -0
- data/lib/treetop/ruby_extensions/string.rb +19 -0
- data/lib/treetop/runtime.rb +9 -0
- data/lib/treetop/runtime/compiled_parser.rb +66 -0
- data/lib/treetop/runtime/node_cache.rb +27 -0
- data/lib/treetop/runtime/parse_cache.rb +19 -0
- data/lib/treetop/runtime/parse_failure.rb +32 -0
- data/lib/treetop/runtime/parse_result.rb +30 -0
- data/lib/treetop/runtime/syntax_node.rb +53 -0
- data/lib/treetop/runtime/terminal_parse_failure.rb +33 -0
- data/lib/treetop/runtime/terminal_syntax_node.rb +12 -0
- data/test/compilation_target/target.rb +143 -0
- data/test/compilation_target/target.treetop +15 -0
- data/test/compilation_target/target_test.rb +56 -0
- data/test/compiler/and_predicate_test.rb +33 -0
- data/test/compiler/anything_symbol_test.rb +24 -0
- data/test/compiler/character_class_test.rb +45 -0
- data/test/compiler/choice_test.rb +49 -0
- data/test/compiler/circular_compilation_test.rb +20 -0
- data/test/compiler/failure_propagation_functional_test.rb +20 -0
- data/test/compiler/grammar_compiler_test.rb +58 -0
- data/test/compiler/grammar_test.rb +33 -0
- data/test/compiler/nonterminal_symbol_test.rb +15 -0
- data/test/compiler/not_predicate_test.rb +35 -0
- data/test/compiler/one_or_more_test.rb +30 -0
- data/test/compiler/optional_test.rb +32 -0
- data/test/compiler/parsing_rule_test.rb +30 -0
- data/test/compiler/sequence_test.rb +68 -0
- data/test/compiler/terminal_symbol_test.rb +35 -0
- data/test/compiler/test_grammar.treetop +7 -0
- data/test/compiler/zero_or_more_test.rb +51 -0
- data/test/composition/a.treetop +11 -0
- data/test/composition/b.treetop +11 -0
- data/test/composition/c.treetop +10 -0
- data/test/composition/d.treetop +10 -0
- data/test/composition/grammar_composition_test.rb +23 -0
- data/test/parser/syntax_node_test.rb +53 -0
- data/test/parser/terminal_parse_failure_test.rb +22 -0
- data/test/ruby_extensions/string_test.rb +33 -0
- data/test/screw/Rakefile +16 -0
- data/test/screw/unit.rb +37 -0
- data/test/screw/unit/assertion_failed_error.rb +14 -0
- data/test/screw/unit/assertions.rb +615 -0
- data/test/screw/unit/auto_runner.rb +227 -0
- data/test/screw/unit/collector.rb +45 -0
- data/test/screw/unit/collector/dir.rb +107 -0
- data/test/screw/unit/collector/objectspace.rb +28 -0
- data/test/screw/unit/error.rb +48 -0
- data/test/screw/unit/failure.rb +45 -0
- data/test/screw/unit/sugar.rb +25 -0
- data/test/screw/unit/test_case.rb +176 -0
- data/test/screw/unit/test_result.rb +73 -0
- data/test/screw/unit/test_suite.rb +70 -0
- data/test/screw/unit/ui.rb +4 -0
- data/test/screw/unit/ui/console/test_runner.rb +118 -0
- data/test/screw/unit/ui/fox/test_runner.rb +268 -0
- data/test/screw/unit/ui/gtk/test_runner.rb +416 -0
- data/test/screw/unit/ui/gtk2/testrunner.rb +465 -0
- data/test/screw/unit/ui/test_runner_mediator.rb +58 -0
- data/test/screw/unit/ui/test_runner_utilities.rb +46 -0
- data/test/screw/unit/ui/tk/test_runner.rb +260 -0
- data/test/screw/unit/util.rb +4 -0
- data/test/screw/unit/util/backtrace_filter.rb +40 -0
- data/test/screw/unit/util/observable.rb +82 -0
- data/test/screw/unit/util/proc_wrapper.rb +48 -0
- data/test/test_helper.rb +89 -0
- metadata +127 -69
- data/lib/treetop/api.rb +0 -3
- data/lib/treetop/api/load_grammar.rb +0 -16
- data/lib/treetop/api/malformed_grammar_exception.rb +0 -9
- data/lib/treetop/grammar.rb +0 -7
- data/lib/treetop/grammar/grammar.rb +0 -48
- data/lib/treetop/grammar/grammar_builder.rb +0 -35
- data/lib/treetop/grammar/parsing_expression_builder.rb +0 -5
- data/lib/treetop/grammar/parsing_expression_builder_helper.rb +0 -121
- data/lib/treetop/grammar/parsing_expressions.rb +0 -18
- data/lib/treetop/grammar/parsing_expressions/and_predicate.rb +0 -17
- data/lib/treetop/grammar/parsing_expressions/anything_symbol.rb +0 -20
- data/lib/treetop/grammar/parsing_expressions/character_class.rb +0 -24
- data/lib/treetop/grammar/parsing_expressions/node_instantiating_parsing_expression.rb +0 -14
- data/lib/treetop/grammar/parsing_expressions/node_propagating_parsing_expression.rb +0 -4
- data/lib/treetop/grammar/parsing_expressions/nonterminal_symbol.rb +0 -42
- data/lib/treetop/grammar/parsing_expressions/not_predicate.rb +0 -18
- data/lib/treetop/grammar/parsing_expressions/one_or_more.rb +0 -12
- data/lib/treetop/grammar/parsing_expressions/optional.rb +0 -14
- data/lib/treetop/grammar/parsing_expressions/ordered_choice.rb +0 -27
- data/lib/treetop/grammar/parsing_expressions/parsing_expression.rb +0 -36
- data/lib/treetop/grammar/parsing_expressions/predicate.rb +0 -25
- data/lib/treetop/grammar/parsing_expressions/repeating_parsing_expression.rb +0 -29
- data/lib/treetop/grammar/parsing_expressions/sequence.rb +0 -41
- data/lib/treetop/grammar/parsing_expressions/terminal_parsing_expression.rb +0 -11
- data/lib/treetop/grammar/parsing_expressions/terminal_symbol.rb +0 -31
- data/lib/treetop/grammar/parsing_expressions/zero_or_more.rb +0 -11
- data/lib/treetop/grammar/parsing_rule.rb +0 -10
- data/lib/treetop/metagrammar.rb +0 -2
- data/lib/treetop/metagrammar/metagrammar.rb +0 -14
- data/lib/treetop/metagrammar/metagrammar.treetop +0 -320
- data/lib/treetop/parser.rb +0 -11
- data/lib/treetop/parser/node_cache.rb +0 -25
- data/lib/treetop/parser/parse_cache.rb +0 -17
- data/lib/treetop/parser/parse_failure.rb +0 -22
- data/lib/treetop/parser/parse_result.rb +0 -26
- data/lib/treetop/parser/parser.rb +0 -24
- data/lib/treetop/parser/sequence_syntax_node.rb +0 -14
- data/lib/treetop/parser/syntax_node.rb +0 -31
- data/lib/treetop/parser/terminal_parse_failure.rb +0 -18
- data/lib/treetop/parser/terminal_syntax_node.rb +0 -7
- data/lib/treetop/protometagrammar.rb +0 -16
- data/lib/treetop/protometagrammar/anything_symbol_expression_builder.rb +0 -13
- data/lib/treetop/protometagrammar/block_expression_builder.rb +0 -17
- data/lib/treetop/protometagrammar/character_class_expression_builder.rb +0 -25
- data/lib/treetop/protometagrammar/grammar_expression_builder.rb +0 -38
- data/lib/treetop/protometagrammar/nonterminal_symbol_expression_builder.rb +0 -45
- data/lib/treetop/protometagrammar/ordered_choice_expression_builder.rb +0 -21
- data/lib/treetop/protometagrammar/parsing_rule_expression_builder.rb +0 -23
- data/lib/treetop/protometagrammar/parsing_rule_sequence_expression_builder.rb +0 -14
- data/lib/treetop/protometagrammar/prefix_expression_builder.rb +0 -25
- data/lib/treetop/protometagrammar/primary_expression_builder.rb +0 -71
- data/lib/treetop/protometagrammar/protometagrammar.rb +0 -25
- data/lib/treetop/protometagrammar/sequence_expression_builder.rb +0 -37
- data/lib/treetop/protometagrammar/suffix_expression_builder.rb +0 -33
- data/lib/treetop/protometagrammar/terminal_symbol_expression_builder.rb +0 -52
- data/lib/treetop/protometagrammar/trailing_block_expression_builder.rb +0 -30
- data/lib/treetop/ruby_extension.rb +0 -11
@@ -1,71 +0,0 @@
|
|
1
|
-
module Treetop
|
2
|
-
class Protometagrammar
|
3
|
-
class PrimaryExpressionBuilder < ParsingExpressionBuilder
|
4
|
-
def build
|
5
|
-
seq(optional(:prefix), rest) do
|
6
|
-
def value(grammar)
|
7
|
-
if prefix.epsilon?
|
8
|
-
rest.value(grammar)
|
9
|
-
else
|
10
|
-
prefix.value(rest.value(grammar))
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def prefix
|
15
|
-
elements[0]
|
16
|
-
end
|
17
|
-
|
18
|
-
def rest
|
19
|
-
elements[1]
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def rest
|
25
|
-
seq(primary_expression, optional(:suffix)) do
|
26
|
-
def value(grammar)
|
27
|
-
if suffix.epsilon?
|
28
|
-
primary_expression.value(grammar)
|
29
|
-
else
|
30
|
-
suffix.value(primary_expression.value(grammar))
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def primary_expression
|
35
|
-
elements[0]
|
36
|
-
end
|
37
|
-
|
38
|
-
def suffix
|
39
|
-
elements[1]
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def primary_expression
|
45
|
-
choice parenthesized_ordered_choice,
|
46
|
-
:terminal_symbol,
|
47
|
-
:nonterminal_symbol
|
48
|
-
end
|
49
|
-
|
50
|
-
def parenthesized_ordered_choice
|
51
|
-
seq('(', optional(:space), :ordered_choice, optional(:space), ')', :trailing_block) do
|
52
|
-
def value(grammar)
|
53
|
-
nested_value = nested_expression.value(grammar)
|
54
|
-
unless trailing_block.epsilon? || nested_value.kind_of?(NodeInstantiatingParsingExpression)
|
55
|
-
raise "Blocks can only follow node-instantiating parsing expressions such as sequences and terminal symbols."
|
56
|
-
end
|
57
|
-
return trailing_block.value(nested_expression.value(grammar))
|
58
|
-
end
|
59
|
-
|
60
|
-
def nested_expression
|
61
|
-
elements[2]
|
62
|
-
end
|
63
|
-
|
64
|
-
def trailing_block
|
65
|
-
elements[5]
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module Treetop
|
2
|
-
class Protometagrammar < Grammar
|
3
|
-
def initialize
|
4
|
-
super
|
5
|
-
build do
|
6
|
-
rule :grammar, GrammarExpressionBuilder.new
|
7
|
-
rule :parsing_rule_sequence, ParsingRuleSequenceExpressionBuilder.new
|
8
|
-
rule :parsing_rule, ParsingRuleExpressionBuilder.new
|
9
|
-
rule :ordered_choice, OrderedChoiceExpressionBuilder.new
|
10
|
-
rule :sequence, SequenceExpressionBuilder.new
|
11
|
-
rule :primary, PrimaryExpressionBuilder.new
|
12
|
-
rule :prefix, PrefixExpressionBuilder.new
|
13
|
-
rule :suffix, SuffixExpressionBuilder.new
|
14
|
-
rule :nonterminal_symbol, NonterminalSymbolExpressionBuilder.new
|
15
|
-
rule :terminal_symbol, TerminalSymbolExpressionBuilder.new
|
16
|
-
rule :character_class, CharacterClassExpressionBuilder.new
|
17
|
-
rule :anything_symbol, AnythingSymbolExpressionBuilder.new
|
18
|
-
rule :block, BlockExpressionBuilder.new
|
19
|
-
rule :trailing_block, TrailingBlockExpressionBuilder.new
|
20
|
-
rule :space, one_or_more(char_class(" \t\n\r"))
|
21
|
-
rule :keyword, choice('rule', 'end')
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
module Treetop
|
2
|
-
class Protometagrammar
|
3
|
-
class SequenceExpressionBuilder < ParsingExpressionBuilder
|
4
|
-
def build
|
5
|
-
choice(sequence_with_block, :primary)
|
6
|
-
end
|
7
|
-
|
8
|
-
def sequence_with_block
|
9
|
-
seq(sequence, :trailing_block) do
|
10
|
-
def value(grammar)
|
11
|
-
trailing_block.value(sequence.value(grammar))
|
12
|
-
end
|
13
|
-
|
14
|
-
def sequence
|
15
|
-
elements[0]
|
16
|
-
end
|
17
|
-
|
18
|
-
def trailing_block
|
19
|
-
elements[1]
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def sequence
|
25
|
-
two_or_more_delimited(:primary, :space) do
|
26
|
-
def value(grammar)
|
27
|
-
Sequence.new(element_values(grammar))
|
28
|
-
end
|
29
|
-
|
30
|
-
def element_values(grammar)
|
31
|
-
elements.collect { |element| element.value(grammar) }
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
module Treetop
|
2
|
-
class Protometagrammar
|
3
|
-
class SuffixExpressionBuilder < ParsingExpressionBuilder
|
4
|
-
def build
|
5
|
-
choice(zero_or_more_terminal, one_or_more_terminal, optional)
|
6
|
-
end
|
7
|
-
|
8
|
-
def zero_or_more_terminal
|
9
|
-
exp('*') do
|
10
|
-
def value(parsing_expression)
|
11
|
-
parsing_expression.zero_or_more
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def one_or_more_terminal
|
17
|
-
exp('+') do
|
18
|
-
def value(parsing_expression)
|
19
|
-
parsing_expression.one_or_more
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def optional
|
25
|
-
exp('?') do
|
26
|
-
def value(parsing_expression)
|
27
|
-
parsing_expression.optional
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
module Treetop
|
2
|
-
class Protometagrammar
|
3
|
-
class TerminalSymbolExpressionBuilder < ParsingExpressionBuilder
|
4
|
-
module TerminalStringSyntaxNode
|
5
|
-
def prefix
|
6
|
-
elements[1].text_value
|
7
|
-
end
|
8
|
-
|
9
|
-
def value
|
10
|
-
TerminalSymbol.new(prefix)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def build
|
15
|
-
seq(choice(single_quoted_string, double_quoted_string, :character_class, :anything_symbol),
|
16
|
-
:trailing_block) do
|
17
|
-
def value(grammar = nil)
|
18
|
-
trailing_block.value(terminal.value)
|
19
|
-
end
|
20
|
-
|
21
|
-
def terminal
|
22
|
-
elements[0]
|
23
|
-
end
|
24
|
-
|
25
|
-
def trailing_block
|
26
|
-
elements[1]
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def double_quoted_string
|
32
|
-
seq('"', zero_or_more(double_quoted_string_char), '"') do
|
33
|
-
include TerminalStringSyntaxNode
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def double_quoted_string_char
|
38
|
-
seq(notp('"'), choice(escaped('"'), any))
|
39
|
-
end
|
40
|
-
|
41
|
-
def single_quoted_string
|
42
|
-
seq("'", zero_or_more(single_quoted_string_char), "'") do
|
43
|
-
include TerminalStringSyntaxNode
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def single_quoted_string_char
|
48
|
-
seq(notp("'"), choice(escaped("'"), any))
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
module Treetop
|
2
|
-
class Protometagrammar
|
3
|
-
class TrailingBlockExpressionBuilder < ParsingExpressionBuilder
|
4
|
-
def build
|
5
|
-
choice(trailing_block, nothing)
|
6
|
-
end
|
7
|
-
|
8
|
-
def trailing_block
|
9
|
-
seq(:space, :block) do
|
10
|
-
def value(parsing_expression)
|
11
|
-
parsing_expression.node_class_eval(block.value)
|
12
|
-
return parsing_expression
|
13
|
-
end
|
14
|
-
|
15
|
-
def block
|
16
|
-
elements[1]
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def nothing
|
22
|
-
exp('') do
|
23
|
-
def value(parsing_expression)
|
24
|
-
parsing_expression
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|