def build(s_exp): ''' Build Domain AST from the given S-expression ''' assert_node(s_exp, s_expression.List) assert_child(s_exp, 0, s_expression.Symbol, lex_token.DOMAIN) name_expr = assert_child(s_exp, 1, s_expression.Symbol) domain = node_type.Domain() domain.name = lex_token.fixup_name(name_expr.text) for child_expr in s_exp.children[2:]: assert_node(child_expr, s_expression.List) symbol = assert_child(child_expr, 0, s_expression.Symbol) if symbol.text == lex_token.METHOD: method = build_method(child_expr) domain.children.append(method) domain.method_map[method.name] = method if symbol.text == lex_token.MODULE: module_name = assert_child(child_expr, 1, s_expression.Symbol).text if len(child_expr.children) == 3: symbol_name = assert_child(child_expr, 2, s_expression.Symbol).text else: symbol_name = None domain.modules.append((module_name, symbol_name)) if lex_token.is_constant(symbol.text): rhs_expr = assert_child(child_expr, 1, [s_expression.List, s_expression.Symbol, s_expression.Number]) domain.constants[symbol.text] = term.build(rhs_expr) return domain
def build_permute_atom(s_expr): node = node_type.Atom() node.name = assert_child(s_expr, 0, s_expression.Symbol).text for child_expr in s_expr.children[1:]: child_node = term.build(child_expr) node.children.append(child_node) return node
def _build_atom(s_expr): node = node_type.Atom() symbol = assert_child(s_expr, 0, s_expression.Symbol) node.name = symbol.text for arg_expr in s_expr.children[1:]: term_node = term.build(arg_expr) node.children.append(term_node) return node
def _build_recursive(s_expr): assert_node(s_expr, s_expression.List) symbol = assert_child(s_expr, 0, s_expression.Symbol) if token_to_op.has_key(symbol.text): return _build_logical_op(s_expr) if symbol.text == lex_token.CALL: return term.build(s_expr) return _build_atom(s_expr)
def build_task_list(s_expr): task_list = [] for child_expr in s_expr.children: assert_node(child_expr, s_expression.List) task_node = node_type.Atom() symbol = assert_child(child_expr, 0, s_expression.Symbol) task_node.name = lex_token.fixup_name(symbol.text) for arg_expr in child_expr.children[1:]: term_node = term.build(arg_expr) task_node.children.append(term_node) task_list.append(task_node) return task_list
def build(s_exp): ''' Build Domain AST from the given S-expression ''' assert_node(s_exp, s_expression.List) assert_child(s_exp, 0, s_expression.Symbol, lex_token.DOMAIN) name_expr = assert_child(s_exp, 1, s_expression.Symbol) domain = node_type.Domain() domain.name = lex_token.fixup_name(name_expr.text) for child_expr in s_exp.children[2:]: assert_node(child_expr, s_expression.List) symbol = assert_child(child_expr, 0, s_expression.Symbol) if symbol.text == lex_token.METHOD: method = build_method(child_expr) domain.children.append(method) domain.method_map[method.name] = method if symbol.text == lex_token.MODULE: module_name = assert_child(child_expr, 1, s_expression.Symbol).text if len(child_expr.children) == 3: symbol_name = assert_child(child_expr, 2, s_expression.Symbol).text else: symbol_name = None domain.modules.append((module_name, symbol_name)) if lex_token.is_constant(symbol.text): rhs_expr = assert_child( child_expr, 1, [s_expression.List, s_expression.Symbol, s_expression.Number]) domain.constants[symbol.text] = term.build(rhs_expr) return domain