Added NAMESPACE capabilities.
1 parent 16ff22d commit 11a5979732eb2dfa814829ea93d88b39afa7f7b0
@tundra tundra authored on 24 Mar 2004
Showing 1 changed file
View
74
tconfpy.py
 
# 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
 
DOLLAR = r'$'
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
 
ENDIF = CONDINTRO + "endif"
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"]
 
 
# Regular Expressions
else:
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)
 
DebugMsg("dLINEIGNORE", (cfgfile, linenum, orig, dNOTINCLUDE))
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
if ref_ok:
# 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
# default to be this first value assigned and
d.Value = r
SymTable[l] = d
 
# Otherwise, update an existing entry
 
SymTable[l].Value = r
else:
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
#####