def p_error(self, p): if p: msg = "Syntax error at '%s' (%d, %d)" % (p.value, p.lineno, p.lexpos) else: msg = "Syntax error at EOF" raise CannotParse(None, msg)
def parse(self, s): """Parses the input string, and returns a reference to the created AST's root""" with self.lock: try: return self.parser.parse(s, lexer=self.lexer) except InvalidIEMLObjectArgument as e: raise CannotParse(s, str(e)) except CannotParse as e: e.s = s raise e
def parse(self, s): if not isinstance(s, str): s = str(s) with self.lock: try: return self.parser.parse(s, lexer=self.lexer) except ValueError as e: raise CannotParse(s, str(e)) except CannotParse as e: e.s = s raise e
def p_lexeme_path(self, p): """lexeme_path : LEXEME_POSITION | LEXEME_POSITION SEPARATOR polymorpheme_path | LEXEME_POSITION SEPARATOR flexion_path """ lex_index = LexemeIndex[p[1].upper()] if len(p) == 2: p[0] = LexemePath(lex_index) else: child = p[3] if lex_index == LexemeIndex.CONTENT and not isinstance( child, PolymorphemePath): raise CannotParse( None, "Invalid child of lexeme path in content position, expected a PolymorphemePath, not a " + child.__class__.__name__) if lex_index == LexemeIndex.FLEXION and not isinstance( child, FlexionPath): raise CannotParse( None, "Invalid child of lexeme path in flexion position, expected a FlexionPath, not a " + child.__class__.__name__) p[0] = LexemePath(lex_index, child=child)
def p_word(self, p): """word : TERM | LBRACKET TERM RBRACKET | LBRACKET TERM RBRACKET literal_list""" try: term = script(p[1 if len(p) == 2 else 2]) except TermNotFoundInDictionary as e: raise CannotParse(self._ieml, str(e)) if len(p) == 5: logging.error( "Literals not supported on script for the moments, and are ignored." ) p[0] = term else: p[0] = term
def parse(self, s, factorize_script=False): """Parses the input string, and returns a reference to the created AST's root""" if s == '': return NullScript(0) if isinstance(s, (USL, Script)): s = str(s) with self.lock: self.factorize_script = factorize_script try: return self.parser.parse(s, lexer=self.lexer) except ValueError as e: raise CannotParse(s, str(e)) except CannotParse as e: e.s = s raise e
def t_parse(self, s): with self.lock: try: return self.parser.parse(s, lexer=self.lexer) except InvalidScript as e: raise CannotParse(s, str(e))