Changeset 2310


Ignore:
Timestamp:
Feb 11, 2010 12:38:44 AM (9 years ago)
Author:
wehart
Message:

Generalizing parsing behavior for set strings.

Location:
coopr.pyomo/trunk/coopr/pyomo
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • coopr.pyomo/trunk/coopr/pyomo/data/parse_datacmds.py

    r2307 r2310  
    5353#    "RANGE",
    5454    "WORD",
     55    "WORDWITHINDEX",
    5556    "STRING",
    5657    "QUOTEDSTRING",
     
    8687    #_comment_list.append(t.value)
    8788
     89def t_WORDWITHINDEX(t):
     90    r'[a-zA-Z_0-9][a-zA-Z_0-9\.\-]*\[[a-zA-Z_0-9\.\-,\*]*\]'
     91    t.type = reserved.get(t.value,'WORDWITHINDEX')    # Check for reserved words
     92    return t
     93
    8894def t_WORD(t):
    89     r'[a-zA-Z_0-9][a-zA-Z_0-9\.]*'
     95    r'[a-zA-Z_0-9][a-zA-Z_0-9\.\-]*'
    9096    t.type = reserved.get(t.value,'WORD')    # Check for reserved words
    9197    return t
     
    133139                 | SET WORD COLON items COLONEQ setdecl SEMICOLON
    134140                 | SET WORD COLON items COLONEQ SEMICOLON
    135                  | SET indexed_word COLONEQ setdecl SEMICOLON
    136                  | SET indexed_word COLONEQ SEMICOLON
     141                 | SET WORDWITHINDEX COLONEQ setdecl SEMICOLON
     142                 | SET WORDWITHINDEX COLONEQ SEMICOLON
    137143                 | PARAM items COLONEQ paramdecl SEMICOLON
    138144                 | IMPORT importdecl SEMICOLON
     
    253259        p[0] = [p[2]]
    254260
    255 def p_indexed_word(p):
    256     '''indexed_word : WORD LBRACKET WORD index_list RBRACKET
    257                     | WORD LBRACKET ASTERISK index_list RBRACKET
    258                     | WORD LBRACKET WORD RBRACKET
    259                     | WORD LBRACKET ASTERISK RBRACKET
    260     '''
    261     if len(p) == 6:
    262         p[0] = p[1]+p[2]+",".join([p[3]]+p[4])+p[5]
    263     else:
    264         p[0] = p[1]+p[2]+p[3]+p[4]
    265 
    266261def p_template(p):
    267262    '''template : LPAREN WORD index_list RPAREN
     
    285280def p_item(p):
    286281    '''item : WORD
     282            | WORDWITHINDEX
    287283            | NONWORD
    288284            | STRING
     
    295291            | LPAREN
    296292            | RPAREN
    297             | indexed_word
     293            | ASTERISK
    298294            | template
    299295    '''
  • coopr.pyomo/trunk/coopr/pyomo/tests/unit/data8.dat

    r2309 r2310  
    11param A := False;
    22param B := True;
    3 #set Z := foo[*] bar [ * ] bar[1,*,a,*] foo-bar hello-goodbye ;
     3set Z := foo[*] bar [ * ] bar[1,*,a,*] foo-bar hello-goodbye ;
     4set Z[A] := foo[*] bar [ * ] bar[1,*,a,*] foo-bar hello-goodbye ;
Note: See TracChangeset for help on using the changeset viewer.