|
10 | 10 | Author: Duy Nguyen Ta, Fan Jiang, Matthew Sklar, Varun Agrawal, and Frank Dellaert |
11 | 11 | """ |
12 | 12 |
|
13 | | -from pyparsing import (Keyword, Literal, Or, QuotedString, Suppress, Word, |
14 | | - alphanums, alphas, delimitedList, nums, |
15 | | - pyparsing_common) |
| 13 | +from pyparsing import (Keyword, Literal, OneOrMore, Or, QuotedString, Suppress, |
| 14 | + Word, alphanums, alphas, nestedExpr, nums, |
| 15 | + originalTextFor, printables) |
16 | 16 |
|
17 | 17 | # rule for identifiers (e.g. variable names) |
18 | 18 | IDENT = Word(alphas + '_', alphanums + '_') ^ Word(nums) |
|
22 | 22 | LPAREN, RPAREN, LBRACE, RBRACE, COLON, SEMI_COLON = map(Suppress, "(){}:;") |
23 | 23 | LOPBRACK, ROPBRACK, COMMA, EQUAL = map(Suppress, "<>,=") |
24 | 24 |
|
25 | | -# Encapsulating type for numbers, and single and double quoted strings. |
26 | | -# The pyparsing_common utilities ensure correct coversion to the corresponding type. |
27 | | -# E.g. pyparsing_common.number will convert 3.1415 to a float type. |
28 | | -NUMBER_OR_STRING = (pyparsing_common.number ^ QuotedString('"') ^ QuotedString("'")) |
29 | | - |
30 | | -# A python tuple, e.g. (1, 9, "random", 3.1415) |
31 | | -TUPLE = (LPAREN + delimitedList(NUMBER_OR_STRING) + RPAREN) |
32 | | - |
33 | 25 | # Default argument passed to functions/methods. |
34 | | -DEFAULT_ARG = (NUMBER_OR_STRING ^ pyparsing_common.identifier ^ TUPLE) |
| 26 | +# Allow anything up to ',' or ';' except when they |
| 27 | +# appear inside matched expressions such as |
| 28 | +# (a, b) {c, b} "hello, world", templates, initializer lists, etc. |
| 29 | +DEFAULT_ARG = originalTextFor( |
| 30 | + OneOrMore( |
| 31 | + QuotedString('"') ^ # parse double quoted strings |
| 32 | + QuotedString("'") ^ # parse single quoted strings |
| 33 | + Word(printables, excludeChars="(){}[]<>,;") ^ # parse arbitrary words |
| 34 | + nestedExpr(opener='(', closer=')') ^ # parse expression in parentheses |
| 35 | + nestedExpr(opener='[', closer=']') ^ # parse expression in brackets |
| 36 | + nestedExpr(opener='{', closer='}') ^ # parse expression in braces |
| 37 | + nestedExpr(opener='<', closer='>') # parse template expressions |
| 38 | + )) |
35 | 39 |
|
36 | 40 | CONST, VIRTUAL, CLASS, STATIC, PAIR, TEMPLATE, TYPEDEF, INCLUDE = map( |
37 | 41 | Keyword, |
|
0 commit comments