How to use makeState0 method in avocado

Best Python code snippet using avocado_python

spark.py

Source:spark.py Github

copy

Full Screen

...72 self.new2old = {}73 self.makeNewRules()74 self.ruleschanged = 075 self.edges, self.cores = {}, {}76 self.states = { 0: self.makeState0() }77 self.makeState(0, self._BOF)78 #79 # XXX - should find a better way to do this..80 #81 changes = 182 while changes:83 changes = 084 for k, v in self.edges.items():85 if v is None:86 state, sym = k87 if self.states.has_key(state):88 self.goto(state, sym)89 changes = 190 rv = self.__dict__.copy()91 for s in self.states.values():92 del s.items93 del rv['rule2func']94 del rv['nullable']95 del rv['cores']96 return rv97 def __setstate__(self, D):98 self.rules = {}99 self.rule2func = {}100 self.rule2name = {}101 self.collectRules()102 start = D['rules'][self._START][0][1][1] # Blech.103 self.augment(start)104 D['rule2func'] = self.rule2func105 D['makeSet'] = self.makeSet_fast106 self.__dict__ = D107 #108 # A hook for GenericASTBuilder and GenericASTMatcher. Mess109 # thee not with this; nor shall thee toucheth the _preprocess110 # argument to addRule.111 #112 def preprocess(self, rule, func): return rule, func113 def addRule(self, doc, func, _preprocess=1):114 fn = func115 rules = doc.split()116 index = []117 for i in xrange(len(rules)):118 if rules[i] == '::=':119 index.append(i-1)120 index.append(len(rules))121 for i in xrange(len(index)-1):122 lhs = rules[index[i]]123 rhs = rules[index[i]+2:index[i+1]]124 rule = (lhs, tuple(rhs))125 if _preprocess:126 rule, fn = self.preprocess(rule, func)127 if self.rules.has_key(lhs):128 self.rules[lhs].append(rule)129 else:130 self.rules[lhs] = [ rule ]131 self.rule2func[rule] = fn132 self.rule2name[rule] = func.__name__[2:]133 self.ruleschanged = 1134 def collectRules(self):135 for name in _namelist(self):136 if name[:2] == 'p_':137 func = getattr(self, name)138 doc = func.__doc__139 self.addRule(doc, func)140 def augment(self, start):141 rule = '%s ::= %s %s' % (self._START, self._BOF, start)142 self.addRule(rule, lambda args: args[1], 0)143 def computeNull(self):144 self.nullable = {}145 tbd = []146 for rulelist in self.rules.values():147 lhs = rulelist[0][0]148 self.nullable[lhs] = 0149 for rule in rulelist:150 rhs = rule[1]151 if len(rhs) == 0:152 self.nullable[lhs] = 1153 continue154 #155 # We only need to consider rules which156 # consist entirely of nonterminal symbols.157 # This should be a savings on typical158 # grammars.159 #160 for sym in rhs:161 if not self.rules.has_key(sym):162 break163 else:164 tbd.append(rule)165 changes = 1166 while changes:167 changes = 0168 for lhs, rhs in tbd:169 if self.nullable[lhs]:170 continue171 for sym in rhs:172 if not self.nullable[sym]:173 break174 else:175 self.nullable[lhs] = 1176 changes = 1177 def makeState0(self):178 s0 = _State(0, [])179 for rule in self.newrules[self._START]:180 s0.items.append((rule, 0))181 return s0182 def finalState(self, tokens):183 #184 # Yuck.185 #186 if len(self.newrules[self._START]) == 2 and len(tokens) == 0:187 return 1188 start = self.rules[self._START][0][1][1]189 return self.goto(1, start)190 def makeNewRules(self):191 worklist = []192 for rulelist in self.rules.values():193 for rule in rulelist:194 worklist.append((rule, 0, 1, rule))195 for rule, i, candidate, oldrule in worklist:196 lhs, rhs = rule197 n = len(rhs)198 while i < n:199 sym = rhs[i]200 if not self.rules.has_key(sym) or \201 not self.nullable[sym]:202 candidate = 0203 i = i + 1204 continue205 newrhs = list(rhs)206 newrhs[i] = self._NULLABLE+sym207 newrule = (lhs, tuple(newrhs))208 worklist.append((newrule, i+1,209 candidate, oldrule))210 candidate = 0211 i = i + 1212 else:213 if candidate:214 lhs = self._NULLABLE+lhs215 rule = (lhs, rhs)216 if self.newrules.has_key(lhs):217 self.newrules[lhs].append(rule)218 else:219 self.newrules[lhs] = [ rule ]220 self.new2old[rule] = oldrule221 def typestring(self, token):222 return None223 def error(self, token):224 print "Syntax error at or near `%s' token" % token225 raise SystemExit226 def parse(self, tokens):227 sets = [ [(1,0), (2,0)] ]228 self.links = {}229 if self.ruleschanged:230 self.computeNull()231 self.newrules = {}232 self.new2old = {}233 self.makeNewRules()234 self.ruleschanged = 0235 self.edges, self.cores = {}, {}236 self.states = { 0: self.makeState0() }237 self.makeState(0, self._BOF)238 for i in xrange(len(tokens)):239 sets.append([])240 if sets[i] == []:241 break 242 self.makeSet(tokens[i], sets, i)243 else:244 sets.append([])245 self.makeSet(None, sets, len(tokens))246 finalitem = (self.finalState(tokens), 0)247 if finalitem not in sets[-2]:248 if len(tokens) > 0:249 self.error(tokens[i-1])250 else:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful