From d9dad4dd8833e8d4d78d9b279bc190bba9790a36 Mon Sep 17 00:00:00 2001 From: Douglas Clowes Date: Mon, 14 Apr 2014 09:33:33 +1000 Subject: [PATCH] Allow single and double quotes, expressions for values, @@NOSEND@@ --- site_ansto/instrument/util/gen_sct.py | 49 +++++++++++++++++---------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/site_ansto/instrument/util/gen_sct.py b/site_ansto/instrument/util/gen_sct.py index 0c841d48..b4199ab4 100755 --- a/site_ansto/instrument/util/gen_sct.py +++ b/site_ansto/instrument/util/gen_sct.py @@ -142,7 +142,8 @@ tokens = [ 'INTEGER', 'FLOATER', 'CODE_STRING', - 'TEXT_STRING', + 'TEXT_STRING1', + 'TEXT_STRING2', 'EQUALS', 'ID', ] + list(reserved.values()) @@ -156,11 +157,16 @@ t_LBRACE = r'{' t_RBRACE = r'}' t_SLASH = r'/' -def t_TEXT_STRING(t): +def t_TEXT_STRING1(t): r'\'[^\']+\'' t.value = t.value[1:-1] return t +def t_TEXT_STRING2(t): + r"\"[^\"]+\"" + t.value = t.value[1:-1] + return t + def t_CODE_STRING(t): r'\@.*' t.value = t.value[1:] @@ -266,9 +272,9 @@ def p_driver_assignment(p): | PROTOCOL EQUALS id_or_str | CLASS EQUALS id_or_str | SIMULATION_GROUP EQUALS id_or_str - | ADD_ARGS EQUALS TEXT_STRING - | MAKE_ARGS EQUALS TEXT_STRING - | PROTOCOL_ARGS EQUALS TEXT_STRING + | ADD_ARGS EQUALS text_string + | MAKE_ARGS EQUALS text_string + | PROTOCOL_ARGS EQUALS text_string ''' p[0] = { p[1] : p[3] } @@ -345,10 +351,10 @@ def p_var_typ_ass(p): ''' var_typ_ass : READABLE EQUALS INTEGER | WRITEABLE EQUALS INTEGER - | READ_COMMAND EQUALS TEXT_STRING + | READ_COMMAND EQUALS text_string | READ_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 | CHECK_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): ''' var_val_ass : VALUE EQUALS FLOATER - | VALUE EQUALS TEXT_STRING + | VALUE EQUALS text_string | VALUE EQUALS INTEGER - | ALLOWED EQUALS TEXT_STRING - | UNITS EQUALS TEXT_STRING - | LOWERLIMIT EQUALS number - | UPPERLIMIT EQUALS number - | TOLERANCE EQUALS number + | ALLOWED EQUALS text_string + | UNITS EQUALS text_string + | LOWERLIMIT EQUALS value + | UPPERLIMIT EQUALS value + | TOLERANCE EQUALS value | DRIVEABLE EQUALS var_path ''' p[0] = { p[1] : p[3] } @@ -484,7 +490,14 @@ def p_code_block(p): def p_id_or_str(p): ''' 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] @@ -745,7 +758,7 @@ def emit(txt): def put_preamble(MyDriver): txt = [] 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 += ['namespace eval %s {' % MyDriver['namespace']] @@ -839,7 +852,9 @@ def put_fetch_function(MyDriver, func): else: txt += ['# hook code goes here'] 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 += [' } catch_message ]'] txt += [' handle_exception ${catch_status} ${catch_message}'] @@ -1153,7 +1168,7 @@ def put_group(MyDriver, MyGroup): if len(path) > 0: path = path.replace('/', '_') + '_' path += MyVar['name'] - print "Path: %s" % MyVar['path'] + #print "Path: %s" % MyVar['path'] nxalias = '${name}_' + path txt += [' hsetprop ${scobj_hpath}/%s nxalias "%s"' % (nodename, nxalias)] if not MyGroup['name']: