/usr/share/doc/python-pyparsing-doc/examples/list1.py is in python-pyparsing-doc 2.2.0+dfsg1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | #
# list1.py
#
# an example of using parse actions to convert type of parsed data.
#
# Copyright (c) 2006-2016, Paul McGuire
#
from pyparsing import *
# first pass
lbrack = Literal("[")
rbrack = Literal("]")
integer = Word(nums).setName("integer")
real = Combine(Optional(oneOf("+ -")) + Word(nums) + "." +
Optional(Word(nums))).setName("real")
listItem = real | integer | quotedString
listStr = lbrack + delimitedList(listItem) + rbrack
test = "['a', 100, 3.14]"
print(listStr.parseString(test))
# second pass, cleanup and add converters
lbrack = Literal("[").suppress()
rbrack = Literal("]").suppress()
cvtInt = lambda s,l,toks: int(toks[0])
cvtReal = lambda s,l,toks: float(toks[0])
integer = Word(nums).setName("integer").setParseAction( cvtInt )
real = Combine(Optional(oneOf("+ -")) + Word(nums) + "." +
Optional(Word(nums))).setName("real").setParseAction( cvtReal )
listItem = real | integer | quotedString.setParseAction( removeQuotes )
listStr = lbrack + delimitedList(listItem) + rbrack
test = "['a', 100, 3.14]"
print(listStr.parseString(test))
# third pass, add nested list support
lbrack, rbrack = map(Suppress, "[]")
cvtInt = tokenMap(int)
cvtReal = tokenMap(float)
integer = Word(nums).setName("integer").setParseAction( cvtInt )
real = Regex(r"[+-]?\d+\.\d*").setName("real").setParseAction( cvtReal )
listStr = Forward()
listItem = real | integer | quotedString.setParseAction(removeQuotes) | Group(listStr)
listStr << lbrack + delimitedList(listItem) + rbrack
test = "['a', 100, 3.14, [ +2.718, 'xyzzy', -1.414] ]"
print(listStr.parseString(test))
|