restructure + delete dead code + export api
This commit is contained in:
parent
619c2c6524
commit
7438b1712b
2 changed files with 5 additions and 35 deletions
|
|
@ -0,0 +1,4 @@
|
||||||
|
from stl.stl import time_lens, set_time, walk, tree
|
||||||
|
from stl.stl import dt_sym, t_sym
|
||||||
|
from stl.stl import LinEq, Var, Interval, NaryOpSTL, Or, And, F, G, ModalOp, Neg
|
||||||
|
from stl.parser import parse
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# TODO: consider using sympy to interpret stuff
|
|
||||||
# TODO: break out into seperate library
|
# TODO: break out into seperate library
|
||||||
# TODO: allow multiplication to be distributive
|
# TODO: allow multiplication to be distributive
|
||||||
# TODO: support reference specific time points
|
# TODO: support reference specific time points
|
||||||
|
|
@ -60,16 +59,6 @@ __ = ~r"\s"*
|
||||||
EOL = "\\n"
|
EOL = "\\n"
|
||||||
''')
|
''')
|
||||||
|
|
||||||
MATRIX_GRAMMAR = Grammar(r'''
|
|
||||||
matrix = "[" __ row+ __ "]"
|
|
||||||
row = consts ";"? __
|
|
||||||
consts = (const _ consts) / const
|
|
||||||
|
|
||||||
const = ~r"[\+\-]?\d+(\.\d+)?"
|
|
||||||
_ = ~r"\s"+
|
|
||||||
__ = ~r"\s"*
|
|
||||||
''')
|
|
||||||
|
|
||||||
|
|
||||||
class STLVisitor(NodeVisitor):
|
class STLVisitor(NodeVisitor):
|
||||||
def generic_visit(self, _, children):
|
def generic_visit(self, _, children):
|
||||||
|
|
@ -156,28 +145,5 @@ class STLVisitor(NodeVisitor):
|
||||||
return 1 if node.text == "+" else -1
|
return 1 if node.text == "+" else -1
|
||||||
|
|
||||||
|
|
||||||
class MatrixVisitor(NodeVisitor):
|
def parse(stl_str:str, rule:str="phi") -> "STL":
|
||||||
def generic_visit(self, _, children):
|
|
||||||
return children
|
|
||||||
|
|
||||||
def visit_matrix(self, _, children):
|
|
||||||
_, _, rows, _, _ = children
|
|
||||||
return rows
|
|
||||||
|
|
||||||
def visit_row(self, _, children):
|
|
||||||
consts, _, _ = children
|
|
||||||
return consts
|
|
||||||
|
|
||||||
def visit_const(self, node, _):
|
|
||||||
return float(node.text)
|
|
||||||
|
|
||||||
def visit_consts(self, _, children):
|
|
||||||
return list(flatten(children))
|
|
||||||
|
|
||||||
|
|
||||||
def parse_stl(stl_str:str, rule:str="phi") -> "STL":
|
|
||||||
return STLVisitor().visit(STL_GRAMMAR[rule].parse(stl_str))
|
return STLVisitor().visit(STL_GRAMMAR[rule].parse(stl_str))
|
||||||
|
|
||||||
|
|
||||||
def parse_matrix(mat_str:str) -> np.array:
|
|
||||||
return np.array(MatrixVisitor().visit(MATRIX_GRAMMAR.parse(mat_str)))
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue