# Path: symtable.py
# class SymbolTable(object):
# 	def __init__(self):
# 		self.symbols = {}
# 
# 	def add(self, name, value):
# 		logger.debug("%s store \"%s\"=\"%s\"", self, name, value)
# 
# 		# an attempt to store empty string is a bug
# 		assert len(name)
# 
# 		self.symbols[name] = value
# 
# 	def fetch(self, s):
# 		# now try a var lookup 
# 		# Will always return an empty string on any sort of failure. 
# 		logger.debug("fetch sym=\"%s\"", s)
# 		if not len(s):
# 			return ""
# 		try:
# 			return self.symbols[s]
# 		except KeyError:
# 			logger.debug("sym=%s not in symbol table", s)
# 			# try environment
# 			value = os.getenv(s)
# 			if value is None:
# 				return ""
# 			logger.debug("sym=%s found in environ", s)
# 			return value


import logging
from symbol import *
from symtable import SymbolTable
	s = e.eval(symbol_table)
	assert s=="", s
	
	# manually insert 'a' into symbol table
	# then look up
	# a=10
	e = VarRef([Literal("a")])
	symbol_table["a"] = "10"
	s = e.eval(symbol_table)
	assert s=="10", s

	# b not in symbol table so should just return "b="
	# $(info b=$(b))
	binfo = Expression([Literal(""),
					VarRef([
						Literal("info b="),
						VarRef([
							Literal("b")
						]),
						Literal("")
					])
				   ])
	s = binfo.eval(symbol_table)
	logger.info("s=%s",s)
	assert s=="b=", s

	# b = 10
	assign = AssignmentExpression([Expression([Literal("b")]),
								   AssignOp("="),
								   Expression([Literal("10")])

# Path: symtable.py
# class SymbolTable(object):
# 	def __init__(self):
# 		self.symbols = {}
# 
# 	def add(self, name, value):
# 		logger.debug("%s store \"%s\"=\"%s\"", self, name, value)
# 
# 		# an attempt to store empty string is a bug
# 		assert len(name)
# 
# 		self.symbols[name] = value
# 
# 	def fetch(self, s):
# 		# now try a var lookup 
# 		# Will always return an empty string on any sort of failure. 
# 		logger.debug("fetch sym=\"%s\"", s)
# 		if not len(s):
# 			return ""
# 		try:
# 			return self.symbols[s]
# 		except KeyError:
# 			logger.debug("sym=%s not in symbol table", s)
# 			# try environment
# 			value = os.getenv(s)
# 			if value is None:
# 				return ""
# 			logger.debug("sym=%s found in environ", s)
# 			return value


# Path: test_evaluate.py
import logging
from symbol import *
from symtable import SymbolTable

	s = e.eval(symbol_table)
	assert s=="", s
	
	# manually insert 'a' into symbol table
	# then look up
	# a=10
	e = VarRef([Literal("a")])
	symbol_table["a"] = "10"
	s = e.eval(symbol_table)
	assert s=="10", s

	# b not in symbol table so should just return "b="
	# $(info b=$(b))
	binfo = Expression([Literal(""),
					VarRef([
						Literal("info b="),
						VarRef([
							Literal("b")
						]),
						Literal("")
					])
				   ])
	s = binfo.eval(symbol_table)
	logger.info("s=%s",s)
	assert s=="b=", s

	# b = 10
	assign = AssignmentExpression([Expression([Literal("b")]),
								   AssignOp("="),
								   Expression([Literal("10")])

								  ])