Skip to content

Commit e01b70e

Browse files
authored
[OMTypedParser] fix PyparsingDeprecationWarning(s) + reorder imports (#413)
1 parent 44aff0d commit e01b70e

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

OMPython/OMTypedParser.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,23 @@
3434
from typing import Any
3535

3636
from pyparsing import (
37+
alphanums,
38+
alphas,
3739
Combine,
40+
DelimitedList,
3841
Dict,
42+
infix_notation,
3943
Forward,
4044
Group,
4145
Keyword,
46+
nums,
47+
opAssoc,
4248
Optional,
4349
QuotedString,
50+
replace_with,
4451
StringEnd,
4552
Suppress,
4653
Word,
47-
alphanums,
48-
alphas,
49-
delimitedList,
50-
nums,
51-
replaceWith,
52-
infixNotation,
53-
opAssoc,
5454
)
5555

5656

@@ -97,7 +97,7 @@ def evaluate_expression(s, loc, toks):
9797

9898

9999
# Number parsing (supports arithmetic expressions in dimensions) (e.g., {1 + 1, 1})
100-
arrayDimension = infixNotation(
100+
arrayDimension = infix_notation(
101101
Word(alphas + "_", alphanums + "_") | Word(nums),
102102
[
103103
(Word("+-", exact=1), 1, opAssoc.RIGHT),
@@ -109,28 +109,28 @@ def evaluate_expression(s, loc, toks):
109109
omcRecord = Forward()
110110
omcValue = Forward()
111111

112-
# pyparsing's replace_with (and thus replaceWith) has incorrect type
112+
# pyparsing's replace_with (and thus replace_with) has incorrect type
113113
# annotation: https://github.com/pyparsing/pyparsing/issues/602
114-
TRUE = Keyword("true").set_parse_action(replaceWith(True)) # type: ignore
115-
FALSE = Keyword("false").set_parse_action(replaceWith(False)) # type: ignore
116-
NONE = (Keyword("NONE") + Suppress("(") + Suppress(")")).set_parse_action(replaceWith(None)) # type: ignore
114+
TRUE = Keyword("true").set_parse_action(replace_with(True)) # type: ignore
115+
FALSE = Keyword("false").set_parse_action(replace_with(False)) # type: ignore
116+
NONE = (Keyword("NONE") + Suppress("(") + Suppress(")")).set_parse_action(replace_with(None)) # type: ignore
117117
SOME = (Suppress(Keyword("SOME")) + Suppress("(") + omcValue + Suppress(")"))
118118

119-
omcString = QuotedString(quoteChar='"', escChar='\\', multiline=True).set_parse_action(convert_string)
119+
omcString = QuotedString(quote_char='"', esc_char='\\', multiline=True).set_parse_action(convert_string)
120120
omcNumber = Combine(Optional('-') + ('0' | Word('123456789', nums)) +
121121
Optional('.' + Word(nums)) +
122122
Optional(Word('eE', exact=1) + Word(nums + '+-', nums)))
123123

124124
# ident = Word(alphas + "_", alphanums + "_") | Combine("'" + Word(alphanums + "!#$%&()*+,-./:;<>=?@[]^{}|~ ") + "'")
125125
ident = (Word(alphas + "_", alphanums + "_")
126-
| QuotedString(quoteChar='\'', escChar='\\').set_parse_action(convert_string2))
126+
| QuotedString(quote_char='\'', esc_char='\\').set_parse_action(convert_string2))
127127
fqident = Forward()
128128
fqident << ((ident + "." + fqident) | ident)
129-
omcValues = delimitedList(omcValue)
129+
omcValues = DelimitedList(omcValue)
130130
omcTuple = Group(Suppress('(') + Optional(omcValues) + Suppress(')')).set_parse_action(convert_tuple)
131131
omcArray = Group(Suppress('{') + Optional(omcValues) + Suppress('}')).set_parse_action(convert_tuple)
132132
omcArraySpecialTypes = Group(Suppress('{')
133-
+ delimitedList(arrayDimension)
133+
+ DelimitedList(arrayDimension)
134134
+ Suppress('}')).set_parse_action(convert_tuple)
135135
omcValue << (omcString
136136
| omcNumber
@@ -143,7 +143,7 @@ def evaluate_expression(s, loc, toks):
143143
| FALSE
144144
| NONE
145145
| Combine(fqident))
146-
recordMember = delimitedList(Group(ident + Suppress('=') + omcValue))
146+
recordMember = DelimitedList(Group(ident + Suppress('=') + omcValue))
147147
omcRecord << Group(Suppress('record')
148148
+ Suppress(fqident)
149149
+ Dict(recordMember)

0 commit comments

Comments
 (0)