Changeset 403
- Timestamp:
- 04/11/07 08:09:49 (2 years ago)
- Files:
-
- cly/trunk/cly/__init__.py (modified) (8 diffs)
- cly/trunk/cly/rlext.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
cly/trunk/cly/__init__.py
r356 r403 191 191 return [] 192 192 193 def chosen(self, context, match):194 """ This node was chosenby the parser. """193 def selected(self, context, match): 194 """ This node was selected by the parser. """ 195 195 context.traverse(self) 196 196 … … 199 199 for child in self.children(context, follow=True): 200 200 yield child 201 201 202 202 def match(self, context): 203 203 """ Does this node match the current token? 204 204 205 205 Must return a regex match object or None for no match. If 206 206 `match_candidates` is true the token must also match one of the values 207 207 returned by `candidates()`. 208 208 209 209 Must include separator in determining whether a match was 210 210 successful. """ … … 232 232 233 233 def terminal(self, context): 234 """ This node was chosenas a terminal. """234 """ This node was selected as a terminal. """ 235 235 raise UnexpectedEOL(context) 236 236 237 237 def depth(self): 238 238 """ The depth of this node in the grammar. 239 239 240 240 >>> grammar = Grammar(one=Node('One'), two=Node('Two')) 241 241 >>> grammar.depth() … … 344 344 callable. If `with_context` is true, the context object will be passed as 345 345 the first argument. 346 346 347 347 >>> def write_text(): 348 348 ... print "some text" … … 383 383 raise UnexpectedEOL(None) 384 384 385 def chosen(self, context, match):385 def selected(self, context, match): 386 386 # We don't "traverse" Action nodes, because they are always terminal, 387 387 # and if we do they get excluded from help. … … 390 390 391 391 class Validator(Node): 392 """ Validate and record the users input in a variable in the context. The 393 Node name is used as the variable name. If `accumulate` is True, the 394 resultant variable will be a list. """ 392 """Validate and record the users input in the `vars` member of the context. 393 The Node name is used as the variable name. If `accumulate` is True, the 394 resultant variable will be a list.""" 395 395 396 pattern = r'\w+' 396 397 accumulate = False 397 398 398 399 def valid(self, context): 399 if not self.accumulate and self.name in context.vars: 400 return False 401 if self.accumulate and isinstance(self.accumulate, int) and \ 402 len(context.vars.get(self.name, [])) >= self.accumulate: 403 return False 404 return Node.valid(self, context) 405 406 def chosen(self, context, match): 400 if self.accumulate is True or \ 401 (self.accumulate is False and self.name not in context.vars) or \ 402 len(context.vars.get(self.name, [])) < self.accumulate: 403 return Node.valid(self, context) 404 return False 405 406 def selected(self, context, match): 407 407 try: 408 408 value = self.validator(match) 409 except Exception, e:409 except InvalidMatch, e: 410 410 raise ValidationError(context, token=match.group(), 411 411 exception=unicode(e)) … … 416 416 417 417 def validator(self, match): 418 """Validate the regex match object provided and return the matched 419 value. Must throw a ValidationError if the input is invalid. Alternate 420 validators should override this method.""" 418 421 return match.group() 419 422 … … 628 631 if match is not None: 629 632 node.advance(context) 630 node. chosen(context, match)633 node.selected(context, match) 631 634 632 635 for subnode in node.next(context): cly/trunk/cly/rlext.c
r337 r403 92 92 {"force_redisplay", force_redisplay, METH_NOARGS, doc_force_redisplay}, 93 93 {"cursor", cursor, METH_VARARGS, doc_cursor}, 94 {NULL, NULL, 0, NULL}, 94 95 }; 95 96
