diff --git a/tconfpy.py b/tconfpy.py index 5171239..2fe034c 100755 --- a/tconfpy.py +++ b/tconfpy.py @@ -6,7 +6,7 @@ # Program Information PROGNAME = "tconfpy" -RCSID = "$Id: tconfpy.py,v 1.134 2004/03/24 10:08:33 tundra Exp $" +RCSID = "$Id: tconfpy.py,v 1.135 2004/03/24 11:09:07 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -68,6 +68,8 @@ ENVIRO = DOLLAR # Used to note environment variable EQUAL = r'=' # Used in vbl definition EQUIV = r"==" # Used in conditional tests +NAMESPACE = "NAMESPACE" # Key used to get current namespace +NSSEP = '.' # Namespace separator character NOTEQUIV = r"!=" # Used in conditional tests # Control and conditional symbols @@ -82,7 +84,7 @@ LITERAL = CONDINTRO + "literal" ENDLITERAL = CONDINTRO + "endliteral" -Reserved = ["HASH", "DELIML", "DELIMR", "DOLLAR", "EQUAL", "EQUIV", "NOTEQUIV", +Reserved = ["HASH", "DELIML", "DELIMR", "DOLLAR", "EQUAL", "EQUIV", "NOTEQUIV", "NSSEP", "INCLUDE", "IF", "IFALL", "IFANY", "IFNONE", "ENDIF", "LITERAL", "ENDLITERAL"] @@ -371,6 +373,14 @@ ErrorMsg("eDESCRIPTBAD", sym) return (SymTable, ErrMsgs, WarnMsgs, DebugMsgs, LiteralLines) + # Make sure the symbol table has a valid namespace + + if NAMESPACE not in SymTable: + SymTable[NAMESPACE] = VarDescriptor() + SymTable[NAMESPACE].Value = "" + SymTable[NAMESPACE].LegalVals = [""] + + # Parse the file ParseFile(cfgfile, eSTARTUP, 0) @@ -580,10 +590,20 @@ return ##### + # Namespace Processing + ##### + + if len(VarRef.findall(line)) == 1 and line[0] == DELIML and line[-1] == DELIMR: + ns = line[1:-1] + SymTable[NAMESPACE].Value = ns + SymTable[NAMESPACE].LegalVals.append(ns) + + + ##### # INCLUDE Processing ##### - if FIRSTTOK == INCLUDE: + elif FIRSTTOK == INCLUDE: line, ref_ok = DerefVar(line.split(INCLUDE)[1].strip(), cfgfile, linenum) # Only attempt the include if all the variable dereferencing was successful @@ -763,7 +783,22 @@ # Load variable into the symbol table else: + # Munge the variable name to incoroprate + # the current namespace + # Handle absolute variable references + if l[0] == NSSEP: + l = l[1:] + + # The NAMESPACE variable is special - leave it alone + elif l == NAMESPACE: + pass + + # Prepend current namespace + else: + ns = SymTable[NAMESPACE].Value + l = "%s%s%s" % (ns, NSSEP, l) + d = VarDescriptor() # If this is a newly defined variable, set its @@ -776,8 +811,14 @@ SymTable[l] = d # Otherwise, update an existing entry + else: + SymTable[l].Value = r - SymTable[l].Value = r + # And keep track of any namespace changes + + ns = SymTable[NAMESPACE].Value + if ns not in SymTable[l].LegalVals: + SymTable[l].LegalVals.append(ns) ##### # Line Format Is Not In One Of The Recognized Forms - Syntax Error