Example #1
0
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Import from the Standard Library
from unittest import TestCase, main

# Import from itools
from itools.abnf import build_grammar, get_parser, BaseContext

###########################################################################
# Grammar / LR(1)
###########################################################################
lr1_grammar = build_grammar('S = A\r\n'
                            'S = "xb"\r\n'
                            'A = "a" A "b"\r\n'
                            'A = B\r\n'
                            'B = "x"\r\n')

lr1_parser = get_parser(lr1_grammar, 'S')

###########################################################################
# Grammar / Expressions
###########################################################################
expression_grammar = ('E = I\r\n'
                      'E = E "+" E\r\n'
                      'E = E "*" E\r\n'
                      'I = 1*DIGIT\r\n')


class ExpressionContext(BaseContext):
Example #2
0
        query = query and query[0] or ''
        fragment = fragment and fragment[0] or ''
        return scheme, hier_part[0], hier_part[1], query, fragment


    def relative_ref(self, start, end, relative_part, query, fragment):
        query = query and query[0] or ''
        fragment = fragment and fragment[0] or ''
        return ('', relative_part[0], relative_part[1], query, fragment)


    def URI_reference(self, start, end, uri):
        return uri


uri_grammar = build_grammar(uri_grammar, URIContext)
uri_parser = get_parser(uri_grammar, 'URI-reference')


def parse_uri(data):
    context = URIContext(data)
    return uri_parser.run(data, context)



class GenericDataType2(object):

    @staticmethod
    def decode(data):
        if isinstance(data, Path):
            return Reference('', '', data, {}, None)
Example #3
0
    def URI(self, start, end, scheme, hier_part, query, fragment):
        query = query and query[0] or ''
        fragment = fragment and fragment[0] or ''
        return scheme, hier_part[0], hier_part[1], query, fragment

    def relative_ref(self, start, end, relative_part, query, fragment):
        query = query and query[0] or ''
        fragment = fragment and fragment[0] or ''
        return ('', relative_part[0], relative_part[1], query, fragment)

    def URI_reference(self, start, end, uri):
        return uri


uri_grammar = build_grammar(uri_grammar, URIContext)
uri_parser = get_parser(uri_grammar, 'URI-reference')


def parse_uri(data):
    context = URIContext(data)
    return uri_parser.run(data, context)


class GenericDataType2(object):
    @staticmethod
    def decode(data):
        if isinstance(data, Path):
            return Reference('', '', data, {}, None)

        if not isinstance(data, (str, unicode)):
Example #4
0
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Import from the Standard Library
from unittest import TestCase, main

# Import from itools
from itools.abnf import build_grammar, get_parser, BaseContext


###########################################################################
# Grammar / LR(1)
###########################################################################
lr1_grammar = build_grammar(
    'S = A\r\n'
    'S = "xb"\r\n'
    'A = "a" A "b"\r\n'
    'A = B\r\n'
    'B = "x"\r\n')

lr1_parser = get_parser(lr1_grammar, 'S')


###########################################################################
# Grammar / Expressions
###########################################################################
expression_grammar = (
    'E = I\r\n'
    'E = E "+" E\r\n'
    'E = E "*" E\r\n'
    'I = 1*DIGIT\r\n')