concepts.dsl.parsers.function_expression_parser.FunctionExpressionParser#

class FunctionExpressionParser[source]#

Bases: ParserBase

The simple function expression parser.

This parser works for simple function expressions, for example: f(x, y).

Each function name is a string composed of letters, digits, and _, and each argument is an expression or a string. When escape_string is set to True, the string should be escaped with double quotes.

>>> from concepts.dsl.function_domain import FunctionDomain
>>> from concepts.dsl.parsers.function_expression_parser import FunctionExpressionParser
>>> domain = FunctionDomain()
>>> parser = FunctionExpressionParser(domain)
>>> parser.parse_expression('f(g(), "string")')

Methods

parse_domain_file(path)

Parse a domain from a file.

parse_domain_string(string)

Parse a domain from a string.

parse_expression(string)

Parse an expression from a string.

Attributes

GRAMMAR

__init__(domain, allow_variable=False, escape_string=True)[source]#

Initialize the parser.

Parameters:
  • domain (FunctionDomain) – the domain to use.

  • allow_variable (bool) – whether to allow variable.

  • escape_string (bool) – whether to escape the string.

__new__(**kwargs)#
parse_domain_file(path)#

Parse a domain from a file.

Parameters:

path (str) – the path to the file.

Returns:

the parsed domain.

Return type:

DSLDomainBase

parse_domain_string(string)#

Parse a domain from a string.

Parameters:

string (str) – the string to parse.

Returns:

the parsed domain.

Return type:

DSLDomainBase

parse_expression(string)[source]#

Parse an expression from a string.

Parameters:

string (str) – The string to parse.

Returns:

The parsed expression.

Return type:

Expression

GRAMMAR = '\nstart: function_application\nfunction_application: function_name "(" (argument ("," argument)*)? ")"\nfunction_name: STRING\n\n%import common.WS\n%ignore WS\n\n%import common.LETTER\n%import common.DIGIT\nSTRING: LETTER ("_"|"-"|LETTER|DIGIT)*\n\n%import common.ESCAPED_STRING\n'#