Module: Rattler::Compiler::ParserGenerator

Included in:
Optimizer::JoinMatchCapturingSequence
Defined in:
lib/rattler/compiler/parser_generator.rb,
lib/rattler/compiler/parser_generator/nested.rb,
lib/rattler/compiler/parser_generator/top_level.rb,
lib/rattler/compiler/parser_generator/group_match.rb,
lib/rattler/compiler/parser_generator/eof_generator.rb,
lib/rattler/compiler/parser_generator/expr_generator.rb,
lib/rattler/compiler/parser_generator/fail_generator.rb,
lib/rattler/compiler/parser_generator/list_generator.rb,
lib/rattler/compiler/parser_generator/rule_generator.rb,
lib/rattler/compiler/parser_generator/skip_generator.rb,
lib/rattler/compiler/parser_generator/sub_generating.rb,
lib/rattler/compiler/parser_generator/apply_generator.rb,
lib/rattler/compiler/parser_generator/label_generator.rb,
lib/rattler/compiler/parser_generator/match_generator.rb,
lib/rattler/compiler/parser_generator/super_generator.rb,
lib/rattler/compiler/parser_generator/token_generator.rb,
lib/rattler/compiler/parser_generator/assert_generator.rb,
lib/rattler/compiler/parser_generator/choice_generator.rb,
lib/rattler/compiler/parser_generator/gen_method_names.rb,
lib/rattler/compiler/parser_generator/list0_generating.rb,
lib/rattler/compiler/parser_generator/list1_generating.rb,
lib/rattler/compiler/parser_generator/repeat_generator.rb,
lib/rattler/compiler/parser_generator/skip_propogating.rb,
lib/rattler/compiler/parser_generator/grammar_generator.rb,
lib/rattler/compiler/parser_generator/token_propogating.rb,
lib/rattler/compiler/parser_generator/disallow_generator.rb,
lib/rattler/compiler/parser_generator/e_symbol_generator.rb,
lib/rattler/compiler/parser_generator/rule_set_generator.rb,
lib/rattler/compiler/parser_generator/sequence_generator.rb,
lib/rattler/compiler/parser_generator/optional_generating.rb,
lib/rattler/compiler/parser_generator/sequence_generating.rb,
lib/rattler/compiler/parser_generator/delegating_generator.rb,
lib/rattler/compiler/parser_generator/group_match_generator.rb,
lib/rattler/compiler/parser_generator/node_action_generator.rb,
lib/rattler/compiler/parser_generator/predicate_propogating.rb,
lib/rattler/compiler/parser_generator/general_list_generator.rb,
lib/rattler/compiler/parser_generator/one_or_more_generating.rb,
lib/rattler/compiler/parser_generator/zero_or_more_generating.rb,
lib/rattler/compiler/parser_generator/back_reference_generator.rb,
lib/rattler/compiler/parser_generator/general_repeat_generator.rb,
lib/rattler/compiler/parser_generator/semantic_action_generator.rb,
lib/rattler/compiler/parser_generator/attributed_sequence_generator.rb

Overview

A ParserGenerator generates ruby parsing code from parser models.

Defined Under Namespace

Modules: List0Generating, List1Generating, Nested, NestedSubGenerating, OneOrMoreGenerating, OptionalGenerating, PredicatePropogating, SequenceGenerating, SkipPropogating, SubGenerating, TokenPropogating, TopLevel, TopLevelSubGenerating, ZeroOrMoreGenerating Classes: ApplyGenerator, AssertGenerator, AttributedSequenceGenerator, BackReferenceGenerator, ChoiceGenerator, DelegatingGenerator, DisallowGenerator, ESymbolGenerator, EofGenerator, ExprGenerator, FailGenerator, GeneralListGenerator, GeneralRepeatGenerator, GrammarGenerator, GroupMatch, GroupMatchGenerator, LabelGenerator, ListGenerator, MatchGenerator, NestedApplyGenerator, NestedAssertGenerator, NestedAttributedSequenceGenerator, NestedBackReferenceGenerator, NestedChoiceGenerator, NestedDisallowGenerator, NestedESymbolGenerator, NestedEofGenerator, NestedExprGenerator, NestedFailGenerator, NestedGeneralListGenerator, NestedGeneralRepeatGenerator, NestedGroupMatchGenerator, NestedLabelGenerator, NestedListGenerator, NestedMatchGenerator, NestedNodeActionGenerator, NestedRepeatGenerator, NestedSemanticActionGenerator, NestedSequenceGenerator, NestedSkipGenerator, NestedSuperGenerator, NestedTokenGenerator, NodeActionGenerator, RepeatGenerator, RuleGenerator, RuleSetGenerator, SemanticActionGenerator, SequenceGenerator, SkipGenerator, SuperGenerator, TokenGenerator, TopLevelApplyGenerator, TopLevelAssertGenerator, TopLevelAttributedSequenceGenerator, TopLevelBackReferenceGenerator, TopLevelChoiceGenerator, TopLevelDisallowGenerator, TopLevelESymbolGenerator, TopLevelEofGenerator, TopLevelFailGenerator, TopLevelGeneralListGenerator, TopLevelGeneralRepeatGenerator, TopLevelGroupMatchGenerator, TopLevelLabelGenerator, TopLevelListGenerator, TopLevelMatchGenerator, TopLevelNodeActionGenerator, TopLevelRepeatGenerator, TopLevelSemanticActionGenerator, TopLevelSequenceGenerator, TopLevelSkipGenerator, TopLevelSuperGenerator, TopLevelTokenGenerator

Constant Summary collapse

GEN_METHOD_TYPES =
%w{
  basic
  assert
  disallow
  token
  skip
  intermediate
  intermediate_assert
  intermediate_disallow
  intermediate_skip
}
GEN_METHOD_NAMES =
GEN_METHOD_TYPES.map {|_| :"gen_#{_}" }

Class Method Summary collapse

Class Method Details

.code_for(grammar, opts) ⇒ String .code_for(rules, opts) ⇒ String .code_for(rule, opts) ⇒ String .code_for(parser, opts) ⇒ String

Generate parsing code for parser using a new RubyGenerator with the given options and return the generated code.

Overloads:

  • .code_for(grammar, opts) ⇒ String

    Returns the generated code.

    Parameters:

    Returns:

    • (String)

      the generated code

  • .code_for(rules, opts) ⇒ String

    Returns the generated code.

    Parameters:

    • rules (Rules)

      the parse rules

    Returns:

    • (String)

      the generated code

  • .code_for(rule, opts) ⇒ String

    Returns the generated code.

    Parameters:

    • rule (Rule)

      the parse rule

    Returns:

    • (String)

      the generated code

  • .code_for(parser, opts) ⇒ String

    Returns the generated code.

    Parameters:

    • parser (Parser)

      the parser model

    Returns:

    • (String)

      the generated code



103
104
105
# File 'lib/rattler/compiler/parser_generator.rb', line 103

def self.code_for(parser, opts={})
  ::Rattler::Compiler::RubyGenerator.code(opts) {|g| generate g, parser, opts }
end

.generate(g, grammar) ⇒ Object .generate(g, rules) ⇒ Object .generate(g, rule) ⇒ Object .generate(g, parser) ⇒ Object

Generate parsing code for a parser model using a ruby generator g.

Overloads:

  • .generate(g, grammar) ⇒ Object

    Returns g.

    Parameters:

    Returns:

    • g

  • .generate(g, rules) ⇒ Object

    Returns g.

    Parameters:

    • g (RubyGenerator)

      the ruby generator to use

    • rules (Rules)

      the parse rules

    Returns:

    • g

  • .generate(g, rule) ⇒ Object

    Returns g.

    Parameters:

    Returns:

    • g

  • .generate(g, parser) ⇒ Object

    Returns g.

    Parameters:

    Returns:

    • g



76
77
78
79
80
81
82
# File 'lib/rattler/compiler/parser_generator.rb', line 76

def self.generate(g, parser, opts={})
  unless opts[:no_optimize]
    parser = ::Rattler::Compiler::Optimizer.optimize(parser, opts)
  end
  GrammarGenerator.new(g).generate(parser, opts)
  g
end