Lines Matching refs:self
15 def __init__(self):
16 self.symbol_table = {}
17 self._reset()
19 def _reset(self, filename=None):
20 self.filename = filename
22 self.line_no = 1
23 self.line_cont = ''
25 def _error(self, msg):
26 raise RuntimeError('%s:%d: %s' % (self.filename, self.line_no, msg))
28 def _next_dereference(self, val, cur):
34 self._error('non-variable dereference')
38 self._error('unterminated variable dereference')
42 def _expand_value(self, val):
47 deref_pos, deref_end = self._next_dereference(val, cur)
53 expanded += val[cur:deref_pos] + self.symbol_table[sym]
58 def _parse_definition(self, line):
63 self._error('not a variable definition')
69 self._error('only =, :=, and += are supported')
74 val = self._expand_value(line[op_end:].lstrip())
77 self.symbol_table[sym] = val
79 self.symbol_table[sym] += ' ' + val
81 if sym not in self.symbol_table:
82 self.symbol_table[sym] = val
84 def _parse_line(self, line):
89 if self.line_cont:
90 self.line_cont += line[:-1].strip() + ' '
92 self.line_cont = line[:-1].rstrip() + ' '
96 if self.line_cont:
97 line = self.line_cont + line.lstrip()
98 self.line_cont = ''
106 self._error('recipe line not supported')
108 self._parse_definition(line)
112 def parse(self, filename):
114 if self.filename != filename:
120 self._reset(filename)
122 self.line_no += self._parse_line(line)
124 self._reset()
127 return self.symbol_table
129 def add_symbol(self, name, value):
130 self.symbol_table[name] = value