Allow single and double quotes, expressions for values, @@NOSEND@@

This commit is contained in:
Douglas Clowes
2014-04-14 09:33:33 +10:00
parent 1692e0d4d4
commit d9dad4dd88

View File

@ -142,7 +142,8 @@ tokens = [
'INTEGER', 'INTEGER',
'FLOATER', 'FLOATER',
'CODE_STRING', 'CODE_STRING',
'TEXT_STRING', 'TEXT_STRING1',
'TEXT_STRING2',
'EQUALS', 'EQUALS',
'ID', 'ID',
] + list(reserved.values()) ] + list(reserved.values())
@ -156,11 +157,16 @@ t_LBRACE = r'{'
t_RBRACE = r'}' t_RBRACE = r'}'
t_SLASH = r'/' t_SLASH = r'/'
def t_TEXT_STRING(t): def t_TEXT_STRING1(t):
r'\'[^\']+\'' r'\'[^\']+\''
t.value = t.value[1:-1] t.value = t.value[1:-1]
return t return t
def t_TEXT_STRING2(t):
r"\"[^\"]+\""
t.value = t.value[1:-1]
return t
def t_CODE_STRING(t): def t_CODE_STRING(t):
r'\@.*' r'\@.*'
t.value = t.value[1:] t.value = t.value[1:]
@ -266,9 +272,9 @@ def p_driver_assignment(p):
| PROTOCOL EQUALS id_or_str | PROTOCOL EQUALS id_or_str
| CLASS EQUALS id_or_str | CLASS EQUALS id_or_str
| SIMULATION_GROUP EQUALS id_or_str | SIMULATION_GROUP EQUALS id_or_str
| ADD_ARGS EQUALS TEXT_STRING | ADD_ARGS EQUALS text_string
| MAKE_ARGS EQUALS TEXT_STRING | MAKE_ARGS EQUALS text_string
| PROTOCOL_ARGS EQUALS TEXT_STRING | PROTOCOL_ARGS EQUALS text_string
''' '''
p[0] = { p[1] : p[3] } p[0] = { p[1] : p[3] }
@ -345,10 +351,10 @@ def p_var_typ_ass(p):
''' '''
var_typ_ass : READABLE EQUALS INTEGER var_typ_ass : READABLE EQUALS INTEGER
| WRITEABLE EQUALS INTEGER | WRITEABLE EQUALS INTEGER
| READ_COMMAND EQUALS TEXT_STRING | READ_COMMAND EQUALS text_string
| READ_FUNCTION EQUALS id_or_str | READ_FUNCTION EQUALS id_or_str
| FETCH_FUNCTION EQUALS id_or_str | FETCH_FUNCTION EQUALS id_or_str
| WRITE_COMMAND EQUALS TEXT_STRING | WRITE_COMMAND EQUALS text_string
| WRITE_FUNCTION EQUALS id_or_str | WRITE_FUNCTION EQUALS id_or_str
| CHECK_FUNCTION EQUALS id_or_str | CHECK_FUNCTION EQUALS id_or_str
| PID_FUNCTION EQUALS id_or_str | PID_FUNCTION EQUALS id_or_str
@ -378,13 +384,13 @@ def p_var_path(p):
def p_var_val_ass(p): def p_var_val_ass(p):
''' '''
var_val_ass : VALUE EQUALS FLOATER var_val_ass : VALUE EQUALS FLOATER
| VALUE EQUALS TEXT_STRING | VALUE EQUALS text_string
| VALUE EQUALS INTEGER | VALUE EQUALS INTEGER
| ALLOWED EQUALS TEXT_STRING | ALLOWED EQUALS text_string
| UNITS EQUALS TEXT_STRING | UNITS EQUALS text_string
| LOWERLIMIT EQUALS number | LOWERLIMIT EQUALS value
| UPPERLIMIT EQUALS number | UPPERLIMIT EQUALS value
| TOLERANCE EQUALS number | TOLERANCE EQUALS value
| DRIVEABLE EQUALS var_path | DRIVEABLE EQUALS var_path
''' '''
p[0] = { p[1] : p[3] } p[0] = { p[1] : p[3] }
@ -484,7 +490,14 @@ def p_code_block(p):
def p_id_or_str(p): def p_id_or_str(p):
''' '''
id_or_str : ID id_or_str : ID
| TEXT_STRING | text_string
'''
p[0] = p[1]
def p_text_string(p):
'''
text_string : TEXT_STRING1
| TEXT_STRING2
''' '''
p[0] = p[1] p[0] = p[1]
@ -745,7 +758,7 @@ def emit(txt):
def put_preamble(MyDriver): def put_preamble(MyDriver):
txt = [] txt = []
txt += ['# Generated driver for %s' % MyDriver['name']] txt += ['# Generated driver for %s' % MyDriver['name']]
txt += ['# vim: tabstop=8 softtabstop=2 shiftwidth=2 nocindent smartindent'] txt += ['# vim: ft=tcl tabstop=8 softtabstop=2 shiftwidth=2 nocindent smartindent']
txt += ['#'] txt += ['#']
txt += [''] txt += ['']
txt += ['namespace eval %s {' % MyDriver['namespace']] txt += ['namespace eval %s {' % MyDriver['namespace']]
@ -839,7 +852,9 @@ def put_fetch_function(MyDriver, func):
else: else:
txt += ['# hook code goes here'] txt += ['# hook code goes here']
txt += [' debug_log 1 "%s sct send ${cmd}"' % func] txt += [' debug_log 1 "%s sct send ${cmd}"' % func]
txt += [' sct send "${cmd}"'] txt += [' if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} {']
txt += [' sct send "${cmd}"']
txt += [' }']
txt += [' return ${nextState}'] txt += [' return ${nextState}']
txt += [' } catch_message ]'] txt += [' } catch_message ]']
txt += [' handle_exception ${catch_status} ${catch_message}'] txt += [' handle_exception ${catch_status} ${catch_message}']
@ -1153,7 +1168,7 @@ def put_group(MyDriver, MyGroup):
if len(path) > 0: if len(path) > 0:
path = path.replace('/', '_') + '_' path = path.replace('/', '_') + '_'
path += MyVar['name'] path += MyVar['name']
print "Path: %s" % MyVar['path'] #print "Path: %s" % MyVar['path']
nxalias = '${name}_' + path nxalias = '${name}_' + path
txt += [' hsetprop ${scobj_hpath}/%s nxalias "%s"' % (nodename, nxalias)] txt += [' hsetprop ${scobj_hpath}/%s nxalias "%s"' % (nodename, nxalias)]
if not MyGroup['name']: if not MyGroup['name']: