class Arborist::Grammar::GrammarParserBuilder

Included Modules

Defined in:

grammar_semantics.cr

Instance Method Summary

Instance methods inherited from module Arborist::DSL

alt(strings : Array(String)) : Expr
alt(alts : Array(String | Expr)) : Expr
alt(strings : Set(String)) : Expr
alt(*alternatives : String | Expr) : Expr
alt
, apply(rule_name : String) : Expr apply, choice(alternatives : Array(Expr)) : Expr
choice(*alternatives) : Expr
choice
, dot : Expr dot, label(label : String, expr : Expr) : Expr label, neg(expr : Expr) : Expr neg, opt(expr : Expr) : Expr opt, plus(expr : Expr) : Expr plus, pos(expr : Expr) : Expr pos, range(chars : Range(Char, Char)) : Expr range, seq(exprs : Array(Expr)) : Expr
seq(*exprs) : Expr
seq
, star(expr : Expr) : Expr star, term(string : String) : Expr term

Instance Method Detail

def add_to_mutex_alt_set(strings_or_dot : Set(String) | Dot, new_strings : Set(String)) : Set(String) | Dot #

def add_to_mutex_alt_set(strings_or_dot : Set(String) | Dot, new_string : String) : Set(String) | Dot

if !strings.empty?

existing_string = strings.first

raise MutexAltBuildFailure.new("Alternatives not all same string length.") unless existing_string.size == new_string.size

end

if strings_or_dot.is_a?(Set(String)) strings_or_dot << new_string end strings_or_dot end


[View source]
def build_grammar_parser(grammar_parse_tree : ApplyTree) : Matcher #

takes a parse tree for an Arborist grammar definition and returns a Matcher that can build parse trees for that grammar definition


[View source]
def build_mutex_alt_for_rule_parse_tree(rule_name : String, parse_tree : ParseTree, rule_name_to_parse_tree_map : Hash(String, ParseTree)) : MutexAlt | Dot | Nil #

returns a MutexAlt if the rule can be represented as a MutexAlt, or a Dot if the rule represents any character; nil otherwise rule_name is the name of the rule that, as a result of being evaluated, yielded the parse_tree node. In other words, rule_name was the name of the rule that was actively being matched and produced a parse tree that included the parse tree node represented by parse_tree. parse_tree is the first (and only) child of an ApplyTree node. Returns a MutexAlt if the parse tree can be represented as a MutexAlt; nil otherwise


[View source]
def build_mutex_alt_string_set_for_rule_parse_tree(rule_name : String, parse_tree : ParseTree, rule_name_to_parse_tree_map : Hash(String, ParseTree), visited_nodes : Set(ParseTree), string_set_union : Set(String) | Dot) : Set(String) | Dot #

parse_tree is the first (and only) child of an ApplyTree node - it is the root tree node of a rule definition


[View source]
def build_mutex_alt_string_set_for_rule_parse_tree(apply_tree : ApplyTree, rule_name_to_parse_tree_map : Hash(String, ParseTree), visited_nodes : Set(ParseTree), string_set_union : Set(String) | Dot) : Set(String) | Dot #

[View source]
def build_parser_for_grammar(parse_tree) : Matcher #

returns a Matcher that knows how to parse the grammar represented by parse_tree parse_tree is a ParseTree produced by Arborist::Grammar::Rules::GrammarParser


[View source]
def build_rule_name_to_parse_tree_map(parse_tree) : Hash(String, ParseTree) #

takes a grammar parse tree and returns a Hash(String, ParseTree) representing the rules as a map of rule-name -> rule-body-parse-tree pairs


[View source]
def build_string_set_from_range_rule_application_parse_tree(range_rule_body : ParseTree) : Set(String) #

[View source]
def build_string_set_from_terminal(terminal_rule_body : ParseTree) : Set(String) #

[View source]
def escape_char_to_string(parse_tree : ParseTree) : String #

[View source]
def is_mutex_alt_string_set_valid?(strings : Set(String)) : Bool #

[View source]
def terminal_char_to_string(terminal_char : ParseTree) : String #

[View source]
def top_level_alternative_label(parse_tree : ParseTree) : String #

[View source]