from pyparsing import (Word, White, Literal, Regex,
LineEnd, SkipTo,
ZeroOrMore, OneOrMore, Combine, Optional, Suppress,
+ Group,
stringEnd, pythonStyleComment)
EOL = LineEnd().suppress()
subclass_line = TAB + NUM2('subclass') + text_eol('text')
protocol_line = TAB + TAB + NUM2('protocol') + text_eol('name')
subclass = (subclass_line('SUBCLASS') -
- ZeroOrMore(protocol_line('PROTOCOLS*')
+ ZeroOrMore(Group(protocol_line)('PROTOCOLS*')
^ COMMENTLINE.suppress()))
klass = (klass_line('KLASS') -
- ZeroOrMore(subclass('SUBCLASSES*')
+ ZeroOrMore(Group(subclass)('SUBCLASSES*')
^ COMMENTLINE.suppress()))
return klass
vendor_line = NUM4('vendor') + text_eol('text')
device_line = TAB + NUM4('device') + text_eol('text')
vendor = (vendor_line('VENDOR') +
- ZeroOrMore(device_line('VENDOR_DEV*') ^ COMMENTLINE.suppress()))
+ ZeroOrMore(Group(device_line)('VENDOR_DEV*') ^ COMMENTLINE.suppress()))
klass = klass_grammar()
other_group = (other_line - ZeroOrMore(TAB + text_eol('text')))
commentgroup = OneOrMore(COMMENTLINE).suppress() ^ EMPTYLINE.suppress()
- grammar = OneOrMore(vendor('VENDORS*') ^ klass('CLASSES*')
+ grammar = OneOrMore(Group(vendor)('VENDORS*')
+ ^ Group(klass)('CLASSES*')
^ other_group.suppress() ^ commentgroup) + stringEnd()
grammar.parseWithTabs()
subvendor_line = TAB + TAB + NUM4('a') + White(' ') + NUM4('b') + text_eol('name')
device = (device_line('DEVICE') +
- ZeroOrMore(subvendor_line('SUBVENDORS*') ^ COMMENTLINE.suppress()))
+ ZeroOrMore(Group(subvendor_line)('SUBVENDORS*') ^ COMMENTLINE.suppress()))
vendor = (vendor_line('VENDOR') +
- ZeroOrMore(device('DEVICES*') ^ COMMENTLINE.suppress()))
+ ZeroOrMore(Group(device)('DEVICES*') ^ COMMENTLINE.suppress()))
klass = klass_grammar()
commentgroup = OneOrMore(COMMENTLINE).suppress() ^ EMPTYLINE.suppress()
- grammar = OneOrMore(vendor('VENDORS*') ^ klass('CLASSES*')
+ grammar = OneOrMore(Group(vendor)('VENDORS*')
+ ^ Group(klass)('CLASSES*')
^ commentgroup) + stringEnd()
grammar.parseWithTabs()
vendor_line = NUM4('vendor') + text_eol('text')
device_line = TAB + NUM4('device') + text_eol('text')
vendor = (vendor_line('VENDOR') +
- ZeroOrMore(device_line('DEVICES*') ^ COMMENTLINE.suppress()))
+ ZeroOrMore(Group(device_line)('DEVICES*') ^ COMMENTLINE.suppress()))
klass = klass_grammar()
commentgroup = OneOrMore(COMMENTLINE).suppress() ^ EMPTYLINE.suppress()
- grammar = OneOrMore(vendor('VENDORS*') ^ klass('CLASSES*') ^ commentgroup) + stringEnd()
+ grammar = OneOrMore(Group(vendor)('VENDORS*')
+ ^ Group(klass)('CLASSES*')
+ ^ commentgroup) + stringEnd()
grammar.parseWithTabs()
return grammar
grammar = (Literal('OUI') + text_eol('header')
+ text_eol('header') + text_eol('header') + EMPTYLINE
- + OneOrMore(vendor('VENDORS*')) + stringEnd())
+ + OneOrMore(Group(vendor)('VENDORS*')) + stringEnd())
grammar.parseWithTabs()
return grammar
items = {}
for vendor_group in p.VENDORS:
- vendor = vendor_group.VENDOR.vendor.upper()
- text = vendor_group.VENDOR.text.strip()
+ vendor = vendor_group.vendor.upper()
+ text = vendor_group.text.strip()
add_item(items, (vendor,), text)
for vendor_dev in vendor_group.VENDOR_DEV:
items = {}
for klass_group in p.CLASSES:
- klass = klass_group.KLASS.klass.upper()
- text = klass_group.KLASS.text.strip()
+ klass = klass_group.klass.upper()
+ text = klass_group.text.strip()
if klass != '00' and not re.match(r'(\?|None|Unused)\s*$', text):
add_item(items, (klass,), text)
items = {}
for vendor_group in p.VENDORS:
- vendor = vendor_group.VENDOR.vendor.upper()
- text = vendor_group.VENDOR.text.strip()
+ vendor = vendor_group.vendor.upper()
+ text = vendor_group.text.strip()
add_item(items, (vendor,), text)
for device_group in vendor_group.DEVICES:
items = {}
for klass_group in p.CLASSES:
- klass = klass_group.KLASS.klass.upper()
- text = klass_group.KLASS.text.strip()
+ klass = klass_group.klass.upper()
+ text = klass_group.text.strip()
add_item(items, (klass,), text)
for subclass_group in klass_group.SUBCLASSES:
items = {}
for vendor_group in p.VENDORS:
- vendor = vendor_group.VENDOR.vendor.upper()
- text = vendor_group.VENDOR.text.strip()
+ vendor = vendor_group.vendor.upper()
+ text = vendor_group.text.strip()
add_item(items, (vendor,), text)
for device_group in vendor_group.DEVICES:
items = {}
for klass_group in p.CLASSES:
- klass = klass_group.KLASS.klass.upper()
- text = klass_group.KLASS.text.strip()
+ klass = klass_group.klass.upper()
+ text = klass_group.text.strip()
add_item(items, klass, text)
with open('20-sdio-classes.hwdb', 'wt') as out: