solidity_parser.ast.parsers.common

Classes

Functions

get_grammar_children(rule)

Gets the children of the given rule that are grammar rules and not tokens

is_grammar_rule(rule)

Predicate for whether the given rule is a user written rule in the language grammar.

map_helper(func, xs)

get_all_subparsers(module)

Gets all the valid subparser methods from the given module

get_subparsers_from_methods(*methods)

Gets the valid subparser methods from the list of given methods

check_subparser_method(name, method)

Checks whether the given name and method match the form of valid subparsers in the context

Module Contents

class solidity_parser.ast.parsers.common.ParserBase(subparsers, token_stream)
subparsers
token_stream
make(rule: antlr4.ParserRuleContext, default=None)
make_first(rule: antlr4.ParserRuleContext)

Finds the first subrule of the given rule and returns the result of running the appropriate subparser :param rule: :return:

make_all(rule: antlr4.ParserRuleContext)

Takes all the subrules of the given rule and returns a list of the result of running their subparsers :param rule: :return:

make_all_rules(rules)
copy_source_data(decorated_node, node_to_decorate)
wrap_node(rule, node, add_comments=False)
solidity_parser.ast.parsers.common.get_grammar_children(rule: antlr4.ParserRuleContext)

Gets the children of the given rule that are grammar rules and not tokens :param rule: :return:

solidity_parser.ast.parsers.common.is_grammar_rule(rule)

Predicate for whether the given rule is a user written rule in the language grammar. e.g. StatementContext would be a grammar rule, whereas the literal ‘for’ or lexer token ‘For’ would not be

Parameters:

rule

Returns:

solidity_parser.ast.parsers.common.map_helper(func, xs)
solidity_parser.ast.parsers.common.get_all_subparsers(module)

Gets all the valid subparser methods from the given module :param module: :return:

solidity_parser.ast.parsers.common.get_subparsers_from_methods(*methods)

Gets the valid subparser methods from the list of given methods :param methods: :return:

solidity_parser.ast.parsers.common.check_subparser_method(name, method)

Checks whether the given name and method match the form of valid subparsers in the context of this parsing framework. Subparsers are methods with the form _f(parser, rule: ‘RuleType’) where parser is the parent parser that provides a context to the subparser and method is a python method reference. The parser parameter must be named ‘parser’ but the ‘rule’ parameter can be named anything. The ‘RuleType’ must be a string(not a python class type) matching the name of the generated antlr grammar rule, e.g. StatementContext

Parameters:
  • name – Name of the given parser or None if no check is required on this parameter

  • method – The subparser method to check

Returns:

A tuple of (RuleType, method)