treetop 1.1.2 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +6 -6
- data/doc/images/bottom_background.png +0 -0
- data/doc/images/middle_backgound.png +0 -0
- data/doc/images/middle_background.png +0 -0
- data/doc/images/top_background.png +0 -0
- data/doc/index.markdown +13 -8
- data/doc/screen.css +52 -0
- data/doc/site.html +34 -0
- data/doc/site.rb +41 -0
- data/examples/lambda_calculus/lambda_calculus.rb +2 -2
- data/lib/treetop/bootstrap_gen_1_metagrammar.rb +37 -0
- data/lib/treetop/compiler/metagrammar. +0 -0
- data/lib/treetop/compiler/metagrammar.rb +20 -9
- data/lib/treetop/compiler/metagrammar.treetop +1 -1
- data/lib/treetop/compiler/node_classes/declaration_sequence.rb +1 -7
- data/lib/treetop/compiler/node_classes/grammar.rb +2 -2
- data/lib/treetop/runtime/compiled_parser.rb +15 -2
- metadata +12 -74
- data/test/compilation_target/target.rb +0 -143
- data/test/compilation_target/target.treetop +0 -15
- data/test/compilation_target/target_test.rb +0 -56
- data/test/compiler/and_predicate_test.rb +0 -33
- data/test/compiler/anything_symbol_test.rb +0 -24
- data/test/compiler/character_class_test.rb +0 -45
- data/test/compiler/choice_test.rb +0 -74
- data/test/compiler/circular_compilation_test.rb +0 -20
- data/test/compiler/failure_propagation_functional_test.rb +0 -20
- data/test/compiler/grammar_compiler_test.rb +0 -58
- data/test/compiler/grammar_test.rb +0 -37
- data/test/compiler/nonterminal_symbol_test.rb +0 -38
- data/test/compiler/not_predicate_test.rb +0 -35
- data/test/compiler/one_or_more_test.rb +0 -30
- data/test/compiler/optional_test.rb +0 -32
- data/test/compiler/parenthesized_expression_test.rb +0 -17
- data/test/compiler/parsing_rule_test.rb +0 -30
- data/test/compiler/sequence_test.rb +0 -68
- data/test/compiler/terminal_symbol_test.rb +0 -35
- data/test/compiler/test_grammar.treetop +0 -7
- data/test/compiler/zero_or_more_test.rb +0 -51
- data/test/composition/a.treetop +0 -11
- data/test/composition/b.treetop +0 -11
- data/test/composition/c.treetop +0 -10
- data/test/composition/d.treetop +0 -10
- data/test/composition/grammar_composition_test.rb +0 -23
- data/test/parser/syntax_node_test.rb +0 -53
- data/test/parser/terminal_parse_failure_test.rb +0 -22
- data/test/ruby_extensions/string_test.rb +0 -33
- data/test/screw/Rakefile +0 -16
- data/test/screw/unit.rb +0 -37
- data/test/screw/unit/assertion_failed_error.rb +0 -14
- data/test/screw/unit/assertions.rb +0 -615
- data/test/screw/unit/auto_runner.rb +0 -227
- data/test/screw/unit/collector.rb +0 -45
- data/test/screw/unit/collector/dir.rb +0 -107
- data/test/screw/unit/collector/objectspace.rb +0 -28
- data/test/screw/unit/error.rb +0 -48
- data/test/screw/unit/failure.rb +0 -45
- data/test/screw/unit/sugar.rb +0 -25
- data/test/screw/unit/test_case.rb +0 -176
- data/test/screw/unit/test_result.rb +0 -73
- data/test/screw/unit/test_suite.rb +0 -70
- data/test/screw/unit/ui.rb +0 -4
- data/test/screw/unit/ui/console/test_runner.rb +0 -118
- data/test/screw/unit/ui/fox/test_runner.rb +0 -268
- data/test/screw/unit/ui/gtk/test_runner.rb +0 -416
- data/test/screw/unit/ui/gtk2/testrunner.rb +0 -465
- data/test/screw/unit/ui/test_runner_mediator.rb +0 -58
- data/test/screw/unit/ui/test_runner_utilities.rb +0 -46
- data/test/screw/unit/ui/tk/test_runner.rb +0 -260
- data/test/screw/unit/util.rb +0 -4
- data/test/screw/unit/util/backtrace_filter.rb +0 -40
- data/test/screw/unit/util/observable.rb +0 -82
- data/test/screw/unit/util/proc_wrapper.rb +0 -48
- data/test/test_helper.rb +0 -90
@@ -1,48 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
#
|
3
|
-
# Author:: Nathaniel Talbott.
|
4
|
-
# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
|
5
|
-
# License:: Ruby license.
|
6
|
-
|
7
|
-
module Screw
|
8
|
-
module Unit
|
9
|
-
module Util
|
10
|
-
|
11
|
-
# Allows the storage of a Proc passed through '&' in a
|
12
|
-
# hash.
|
13
|
-
#
|
14
|
-
# Note: this may be inefficient, since the hash being
|
15
|
-
# used is not necessarily very good. In Observable,
|
16
|
-
# efficiency is not too important, since the hash is
|
17
|
-
# only accessed when adding and removing listeners,
|
18
|
-
# not when notifying.
|
19
|
-
|
20
|
-
class ProcWrapper
|
21
|
-
|
22
|
-
# Creates a new wrapper for a_proc.
|
23
|
-
def initialize(a_proc)
|
24
|
-
@a_proc = a_proc
|
25
|
-
@hash = a_proc.inspect.sub(/^(#<#{a_proc.class}:)/){''}.sub(/(>)$/){''}.hex
|
26
|
-
end
|
27
|
-
|
28
|
-
def hash
|
29
|
-
return @hash
|
30
|
-
end
|
31
|
-
|
32
|
-
def ==(other)
|
33
|
-
case(other)
|
34
|
-
when ProcWrapper
|
35
|
-
return @a_proc == other.to_proc
|
36
|
-
else
|
37
|
-
return super
|
38
|
-
end
|
39
|
-
end
|
40
|
-
alias :eql? :==
|
41
|
-
|
42
|
-
def to_proc
|
43
|
-
return @a_proc
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
data/test/test_helper.rb
DELETED
@@ -1,90 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
dir = File.dirname(__FILE__)
|
3
|
-
$:.unshift(File.expand_path(File.join(dir, '..', 'lib')))
|
4
|
-
require File.expand_path(File.join(dir, 'screw', 'unit'))
|
5
|
-
gem_original_require 'treetop'
|
6
|
-
|
7
|
-
include Treetop
|
8
|
-
|
9
|
-
unless Object.const_defined?(:METAGRAMMAR_PATH)
|
10
|
-
METAGRAMMAR_PATH = File.join(TREETOP_ROOT, 'compiler', 'metagrammar.treetop')
|
11
|
-
fresh_metagrammar_source = Compiler::GrammarCompiler.new.ruby_source(METAGRAMMAR_PATH)
|
12
|
-
Compiler.send(:remove_const, :Metagrammar)
|
13
|
-
Object.class_eval(fresh_metagrammar_source)
|
14
|
-
end
|
15
|
-
|
16
|
-
class CompilerTestCase < Screw::Unit::TestCase
|
17
|
-
class << self
|
18
|
-
attr_accessor :parser_class_under_test
|
19
|
-
|
20
|
-
def testing_expression(expression_to_test)
|
21
|
-
rule_node = parse_with_metagrammar_2("rule test_expression\n" + expression_to_test + "\nend", :parsing_rule)
|
22
|
-
test_parser_code = generate_test_parser_for_expression(rule_node)
|
23
|
-
#puts test_parser_code
|
24
|
-
class_eval(test_parser_code)
|
25
|
-
self.parser_class_under_test = const_get(:TestParser)
|
26
|
-
end
|
27
|
-
|
28
|
-
def testing_grammar(grammar_to_test)
|
29
|
-
grammar_node = parse_with_metagrammar_2(grammar_to_test.strip, :grammar)
|
30
|
-
test_parser_code = grammar_node.compile
|
31
|
-
# puts test_parser_code
|
32
|
-
class_eval(test_parser_code)
|
33
|
-
self.parser_class_under_test = const_get(grammar_node.parser_name.to_sym)
|
34
|
-
end
|
35
|
-
|
36
|
-
def generate_test_parser_for_expression(expression_node)
|
37
|
-
builder = Compiler::RubyBuilder.new
|
38
|
-
address = builder.next_address
|
39
|
-
expression_node.compile(builder)
|
40
|
-
%{
|
41
|
-
class TestParser < Treetop::Runtime::CompiledParser
|
42
|
-
include Treetop::Runtime
|
43
|
-
|
44
|
-
attr_accessor :test_index
|
45
|
-
|
46
|
-
def root
|
47
|
-
_nt_test_expression
|
48
|
-
end
|
49
|
-
|
50
|
-
def reset_index
|
51
|
-
@index = @test_index || 0
|
52
|
-
end
|
53
|
-
|
54
|
-
#{builder.ruby.tabrestto(10)}
|
55
|
-
end
|
56
|
-
}.tabto(0)
|
57
|
-
end
|
58
|
-
|
59
|
-
def parse_with_metagrammar_2(input, root)
|
60
|
-
parser = Treetop::Compiler::MetagrammarParser.new
|
61
|
-
parser.send(:prepare_to_parse, input)
|
62
|
-
node = parser.send("_nt_#{root}".to_sym)
|
63
|
-
raise "#{input} cannot be parsed by the metagrammar: #{node.nested_failures.map {|f| f.to_s}.join("\n")}" if node.failure?
|
64
|
-
node
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
68
|
-
|
69
|
-
def parse_with_metagrammar_2(input, root)
|
70
|
-
self.class.parse_with_metagrammar_2(input, root)
|
71
|
-
end
|
72
|
-
|
73
|
-
def parser_class_under_test
|
74
|
-
self.class.parser_class_under_test
|
75
|
-
end
|
76
|
-
|
77
|
-
def parse(input, options = {})
|
78
|
-
test_parser = parser_class_under_test.new
|
79
|
-
test_parser.test_index = options[:at_index] if options[:at_index]
|
80
|
-
result = test_parser.parse(input)
|
81
|
-
yield result if block_given?
|
82
|
-
result
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
class String
|
87
|
-
def tabrestto(n)
|
88
|
-
self.gsub(/\n^/, "\n" + ' ' * n)
|
89
|
-
end
|
90
|
-
end
|