Module: Treetop

Defined in:
lib/treetop/version.rb,
lib/treetop.rb,
lib/treetop/runtime/syntax_node.rb,
lib/treetop/compiler/metagrammar.rb,
lib/treetop/compiler/ruby_builder.rb,
lib/treetop/runtime/compiled_parser.rb,
lib/treetop/compiler/grammar_compiler.rb,
lib/treetop/compiler/node_classes/regex.rb,
lib/treetop/compiler/node_classes/choice.rb,
lib/treetop/runtime/terminal_syntax_node.rb,
lib/treetop/compiler/node_classes/grammar.rb,
lib/treetop/compiler/lexical_address_space.rb,
lib/treetop/compiler/node_classes/optional.rb,
lib/treetop/compiler/node_classes/sequence.rb,
lib/treetop/compiler/node_classes/terminal.rb,
lib/treetop/runtime/terminal_parse_failure.rb,
lib/treetop/compiler/node_classes/predicate.rb,
lib/treetop/compiler/node_classes/repetition.rb,
lib/treetop/compiler/node_classes/nonterminal.rb,
lib/treetop/compiler/node_classes/parsing_rule.rb,
lib/treetop/compiler/node_classes/treetop_file.rb,
lib/treetop/compiler/node_classes/inline_module.rb,
lib/treetop/compiler/node_classes/anything_symbol.rb,
lib/treetop/compiler/node_classes/character_class.rb,
lib/treetop/compiler/node_classes/predicate_block.rb,
lib/treetop/compiler/node_classes/transient_prefix.rb,
lib/treetop/compiler/node_classes/atomic_expression.rb,
lib/treetop/compiler/node_classes/parsing_expression.rb,
lib/treetop/compiler/node_classes/declaration_sequence.rb,
lib/treetop/compiler/node_classes/parenthesized_expression.rb

Overview

:nodoc:

Defined Under Namespace

Modules: Compiler, Runtime, VERSION

Constant Summary collapse

VALID_GRAMMAR_EXT =
['treetop', 'tt']
VALID_GRAMMAR_EXT_REGEXP =
/\.(#{VALID_GRAMMAR_EXT.join('|')})\Z/o

Class Method Summary collapse

Class Method Details

.load(path) ⇒ Object

compile a treetop source file and load it



30
31
32
33
34
35
36
37
# File 'lib/treetop/compiler/grammar_compiler.rb', line 30

def self.load(path)
  adjusted_path = path =~ /\.(treetop|tt)\Z/ ? path : path + '.treetop'
  File.open(adjusted_path) do |source_file|
    source = source_file.read
    source.gsub!(/\b__FILE__\b/, %Q{"#{adjusted_path}"})
    load_from_string(source)
  end
end

.load_from_string(s) ⇒ Object

compile a treetop source string and load it



40
41
42
43
# File 'lib/treetop/compiler/grammar_compiler.rb', line 40

def self.load_from_string(s)
  compiler = Treetop::Compiler::GrammarCompiler.new
  Object.class_eval(compiler.ruby_source_from_string(s))
end