Skip to content

Commit f73d689

Browse files
committed
hwdb: fix parser to work with newer pyparsing
The handling of whitespace in pyparsing is a bother. There's some global state, and per-element state, and it's hard to get a handle on things. With python3-pyparsing-2.4.7-10.fc36.noarch the grammar would not match. After handling of tabs was fixed to not accept duplicate tabs, the grammar passes. It seems that the entry for usb:v8087p8087* was generated incorrectly because we treated the interface line (with two TABs) as a device line (with one TAB).
1 parent 88a65c9 commit f73d689

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

hwdb.d/20-usb-vendor-model.hwdb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69815,9 +69815,6 @@ usb:v8087p8008*
6981569815
usb:v8087p800A*
6981669816
ID_MODEL_FROM_DATABASE=Hub
6981769817

69818-
usb:v8087p8087*
69819-
ID_MODEL_FROM_DATABASE=07da Centrino Advanced-N 6235
69820-
6982169818
usb:v80EE*
6982269819
ID_VENDOR_FROM_DATABASE=VirtualBox
6982369820

hwdb.d/ids_parser.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from pyparsing import (Word, White, Literal, Regex,
77
LineEnd, SkipTo,
88
ZeroOrMore, OneOrMore, Combine, Optional, Suppress,
9-
Group,
9+
Group, ParserElement,
1010
stringEnd, pythonStyleComment)
1111

1212
EOL = LineEnd().suppress()
@@ -20,6 +20,8 @@
2020
EMPTYLINE = LineEnd()
2121
text_eol = lambda name: Regex(r'[^\n]+')(name) + EOL
2222

23+
ParserElement.set_default_whitespace_chars(' \n')
24+
2325
def klass_grammar():
2426
klass_line = Literal('C ').suppress() + NUM2('klass') + text_eol('text')
2527
subclass_line = TAB + NUM2('subclass') + text_eol('text')
@@ -35,8 +37,12 @@ def klass_grammar():
3537
def usb_ids_grammar():
3638
vendor_line = NUM4('vendor') + text_eol('text')
3739
device_line = TAB + NUM4('device') + text_eol('text')
40+
interface_line = TAB + TAB + NUM4('interface') + NUM4('interface2') + text_eol('text')
41+
device = (device_line +
42+
ZeroOrMore(Group(interface_line)
43+
^ COMMENTLINE.suppress()))
3844
vendor = (vendor_line('VENDOR') +
39-
ZeroOrMore(Group(device_line)('VENDOR_DEV*') ^ COMMENTLINE.suppress()))
45+
ZeroOrMore(Group(device)('VENDOR_DEV*') ^ COMMENTLINE.suppress()))
4046

4147
klass = klass_grammar()
4248

0 commit comments

Comments
 (0)