PHP 8.2.30
Preview: plyparser.py Size: 1.56 KB
/lib/python3.6/site-packages/pycparser/plyparser.py

#-----------------------------------------------------------------
# plyparser.py
#
# PLYParser class and other utilites for simplifying programming
# parsers with PLY
#
# Copyright (C) 2008-2015, Eli Bendersky
# License: BSD
#-----------------------------------------------------------------


class Coord(object):
    """ Coordinates of a syntactic element. Consists of:
            - File name
            - Line number
            - (optional) column number, for the Lexer
    """
    __slots__ = ('file', 'line', 'column', '__weakref__')
    def __init__(self, file, line, column=None):
        self.file = file
        self.line = line
        self.column = column

    def __str__(self):
        str = "%s:%s" % (self.file, self.line)
        if self.column: str += ":%s" % self.column
        return str


class ParseError(Exception): pass


class PLYParser(object):
    def _create_opt_rule(self, rulename):
        """ Given a rule name, creates an optional ply.yacc rule
            for it. The name of the optional rule is
            <rulename>_opt
        """
        optname = rulename + '_opt'

        def optrule(self, p):
            p[0] = p[1]

        optrule.__doc__ = '%s : empty\n| %s' % (optname, rulename)
        optrule.__name__ = 'p_%s' % optname
        setattr(self.__class__, optrule.__name__, optrule)

    def _coord(self, lineno, column=None):
        return Coord(
                file=self.clex.filename,
                line=lineno,
                column=column)

    def _parse_error(self, msg, coord):
        raise ParseError("%s: %s" % (coord, msg))

Directory Contents

Dirs: 1 × Files: 12

Name Size Perms Modified Actions
- drwxr-xr-x 2024-03-03 19:12:32
Edit Download
3.48 KB lrw-r--r-- 2015-06-10 03:00:55
Edit Download
22.79 KB lrw-r--r-- 2019-11-13 14:57:08
Edit Download
13.25 KB lrw-r--r-- 2015-06-10 03:00:55
Edit Download
14.11 KB lrw-r--r-- 2019-11-13 14:57:05
Edit Download
60.75 KB lrw-r--r-- 2019-11-13 14:57:05
Edit Download
7.08 KB lrw-r--r-- 2019-11-13 14:57:07
Edit Download
1.56 KB lrw-r--r-- 2015-06-10 03:00:55
Edit Download
123.33 KB lrw-r--r-- 2019-11-13 14:57:08
Edit Download
8.46 KB lrw-r--r-- 2015-06-10 03:00:55
Edit Download
851 B lrw-r--r-- 2015-06-10 03:00:55
Edit Download
4.08 KB lrw-r--r-- 2015-06-10 03:00:55
Edit Download
2.83 KB lrw-r--r-- 2015-06-10 03:00:55
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).