concepts.pdsketch.parsers.pdsketch_v3_parser.PDSketchV3Parser#

class PDSketchV3Parser[source]#

Bases: object

The parser for PDSketch v3.

Methods

parse(filename)

Parse a PDSketch v3 file.

parse_domain(filename)

Parse a PDSketch v3 domain file.

parse_domain_str(s[, domain])

Parse a PDSketch v3 domain string.

parse_expression(s, domain[, state, ...])

Parse a PDSketch v3 expression string.

parse_problem(filename[, domain])

Parse a PDSketch v3 problem file.

parse_problem_str(s[, domain])

Parse a PDSketch v3 problem string.

parse_str(s)

Parse a PDSketch v3 string.

transform_domain(tree[, domain])

Transform a parse tree into a domain.

transform_expression(tree, domain[, state, ...])

Transform a parse tree into an expression.

transform_problem(tree[, domain])

Transform a parse tree into a problem.

Attributes

grammar_file

The grammar definition v3 for PDSketch.

__init__()[source]#

Initialize the parser.

__new__(**kwargs)#
parse(filename)[source]#

Parse a PDSketch v3 file.

Parameters:

filename (str) – the filename to parse.

Returns:

the parse tree. It is a lark.Tree object.

Return type:

Tree

parse_domain(filename)[source]#

Parse a PDSketch v3 domain file.

Parameters:

filename (str) – the filename to parse.

Returns:

the parsed domain.

Return type:

Domain

parse_domain_str(s, domain=None)[source]#

Parse a PDSketch v3 domain string.

Parameters:
  • s (str) – the string to parse.

  • domain (Domain | None) – the domain to use. If not provided, a new domain will be created.

Returns:

the parsed domain.

Return type:

Any

parse_expression(s, domain, state=None, variables=None, auto_constant_guess=True)[source]#

Parse a PDSketch v3 expression string.

Parameters:
  • s (str) – the string to parse.

  • domain (Domain) – the domain to use.

  • state (State | None) – the current state, containing objects.

  • variables (Sequence[Variable] | None) – variables from the outer scope.

  • auto_constant_guess (bool) – whether to automatically guess whether a variable is a constant.

Returns:

the parsed expression.

Return type:

Expression

parse_problem(filename, domain=None)[source]#

Parse a PDSketch v3 problem file.

Parameters:
  • filename (str) – the filename to parse.

  • domain (Domain | None) – the domain to use. If not provided, the domain will be parsed from the problem file.

Returns:

the parsed problem.

Return type:

Problem3

parse_problem_str(s, domain=None)[source]#

Parse a PDSketch v3 problem string.

Parameters:
  • s (str) – the string to parse.

  • domain (Domain | None) – the domain to use. If not provided, the domain will be parsed from the problem file.

Returns:

the parsed problem.

Return type:

Problem3

parse_str(s)[source]#

Parse a PDSketch v3 string.

Parameters:

s (str) – the string to parse.

Returns:

the parse tree. It is a lark.Tree object.

Return type:

Tree

static transform_domain(tree, domain=None)[source]#

Transform a parse tree into a domain.

Parameters:
  • tree (Tree) – the parse tree.

  • domain (Domain | None) – the domain to use. If not provided, a new domain will be created.

Returns:

the parsed domain.

Return type:

Domain

static transform_expression(tree, domain, state=None, variables=None, auto_constant_guess=True)[source]#

Transform a parse tree into an expression.

Parameters:
  • tree (Tree) – the parse tree.

  • domain (Domain) – the domain to use.

  • state (State | None) – the current state, containing objects.

  • variables (Sequence[Variable] | None) – variables from the outer scope.

  • auto_constant_guess (bool) – whether to automatically guess whether a variable is a constant.

Returns:

the parsed expression.

Return type:

Expression

static transform_problem(tree, domain=None)[source]#

Transform a parse tree into a problem.

Parameters:
  • tree (Tree) – the parse tree.

  • domain (Domain | None) – the domain to use. If not provided, the domain will be parsed from the problem file.

Returns:

the parsed problem.

Return type:

Problem3

grammar_file = '/Users/jiayuanm/Projects/Concepts/concepts/pdsketch/parsers/pdsketch-v3.grammar'#

The grammar definition v3 for PDSketch.