예제 #1
0
    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)
예제 #2
0
 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
예제 #3
0
파일: parser.py 프로젝트: baajur/ieml
    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
예제 #4
0
파일: parser.py 프로젝트: baajur/ieml
    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)
예제 #5
0
    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
예제 #6
0
    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
예제 #7
0
 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))