concepts.dm.crow.parsers.cdl_parser.CDLParser#

class CDLParser[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:

CrowDomain

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

Parse a PDSketch v3 domain string.

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

  • domain (CrowDomain | 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 (CrowDomain) – the domain to use.

  • state (CrowState | 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 (CrowDomain | None) – the domain to use. If not provided, the domain will be parsed from the problem file.

Returns:

the parsed problem.

Return type:

CrowProblem

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

Parse a PDSketch v3 problem string.

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

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

Returns:

the parsed problem.

Return type:

CrowProblem

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 (CrowDomain | None) – the domain to use. If not provided, a new domain will be created.

Returns:

the parsed domain.

Return type:

CrowDomain

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 (CrowDomain) – the domain to use.

  • state (CrowState | 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 (CrowDomain | None) – the domain to use. If not provided, the domain will be parsed from the problem file.

Returns:

the parsed problem.

Return type:

CrowProblem

grammar_file = '/Users/jiayuanm/Projects/Concepts/concepts/dm/crow/parsers/cdl.grammar'#

The grammar definition v3 for PDSketch.