Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- from __future__ import print_function
- from __future__ import unicode_literals, print_function
- try:
- text=unicode
- except:
- text=str
- from arpeggio import Optional, ZeroOrMore, OneOrMore, EOF, \
- ParserPython, PTNodeVisitor, visit_parse_tree
- from arpeggio import RegExMatch as _
- def authority():
- return Optional(userinfo, '@'), host, Optional(':', port)
- def userinfo():
- return ZeroOrMore([ unreserved, pct_encoded, sub_delims, ':'])
- def host():
- return [ ip_literal, ipv4address, reg_name ]
- def port():
- return _('\d*')
- def ip_literal():
- return '[', [ ipv6address, ipvfuture ], ']'
- def ipvfuture():
- return 'v', OneOrMore(hexdig), '.', OneOrMore((unreserved, sub_delims, ':'))
- def ipv6address():
- return [ (h16, ':', h16, ':', h16, ':', h16, ':', h16, ':', h16, ':', ls32),
- ('::', h16, ':', h16, ':', h16, ':', h16, ':', h16, ':', ls32),
- (Optional(h16), '::', h16, ':', h16, ':', h16, ':', h16, ':', ls32) ]
- def ipv4address():
- return dec_octect, '.', dec_octect, '.', dec_octect, '.', dec_octect
- def ls32():
- return [ (h16, ':', h16), ipv4address ]
- def h16():
- return [ (hexdig,) * i for i in range(1, 5) ]
- def dec_octect():
- return [ _('25[0-5]'),
- _('2[0-4]\d'),
- _('1\d\d'),
- _('[1-9]\d'),
- _('\d') ]
- def reg_name():
- return ZeroOrMore([ unreserved, pct_encoded, sub_delims])
- def hexdig():
- return _('[0-9a-fA-F]')
- def pchar():
- return [ unreserved, pct_encoded, sub_delims, ':', '@' ]
- def unreserved():
- # return [ alpha, digit, '-', '.', '_', '~' ]
- return _('[A-Za-z0-9._~-]')
- def pct_encoded():
- # return '%', hexdig, hexdig
- return _('%[0-9A-Fa-f][0-9A-Fa-f]')
- def sub_delims():
- # return [ '!', '$', '&', "'", '(', ')', '*', '+', ',', ';', '=' ]
- return _('[!$&\'()*+,;=]')
- def alpha():
- return _('[A-Za-z]')
- def digit():
- return _('\d')
- parser = ParserPython(authority)
- parser.parse('//') # it does not match authority rule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement