blob: de1614ae9e480e117130520cfcee767210066369 (
plain)
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
|
#!/bin/sh
[ "$1" = python3-pyparsing ] || exit 0
python3 - << 'EOF'
import pyparsing as pp
# Basic word and integer parsing
word = pp.Word(pp.alphas)
integer = pp.Word(pp.nums)
result = word.parse_string("hello")
assert result[0] == "hello"
result = integer.parse_string("42")
assert result[0] == "42"
# Combined expression
greeting = word + pp.Literal(",") + word
result = greeting.parse_string("Hello, World")
assert result[0] == "Hello"
assert result[2] == "World"
# OneOf
colors = pp.one_of("red green blue")
result = colors.parse_string("green")
assert result[0] == "green"
EOF
|