Changeset 455
- Timestamp:
- 08/22/07 06:58:21 (1 year ago)
- Files:
-
- cly/trunk/cly/builder.py (modified) (4 diffs)
- cly/trunk/cly/console.py (modified) (2 diffs)
- cly/trunk/cly/extra.py (modified) (1 diff)
- cly/trunk/cly/interactive.py (modified) (3 diffs)
- cly/trunk/doc/developers-guide.rst (modified) (2 diffs)
- cly/trunk/setup.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
cly/trunk/cly/builder.py
r437 r455 139 139 for this node. See __init__ for more information on attributes. 140 140 141 As a special case, if a positional argument is a `Grammar` object, its 142 *children* will be merged. 143 141 144 >>> top = Node('Top', name='top') 142 145 >>> top(subnode=Node('Subnode')) … … 146 149 """ 147 150 for node in anonymous: 151 if isinstance(node, Grammar): 152 children = dict([(n.name, n) for n in node]) 153 self(**children) 154 continue 148 155 if not isinstance(node, Node): 149 156 raise InvalidAnonymousNode('Anonymous node is not a Node object') … … 237 244 def children(self, context, follow=False): 238 245 """Iterate over child nodes, optionally follow()ing branches. 246 239 247 >>> from cly.parser import Context 240 248 >>> tree = Node('One')(two=Node('Two', three=Node('Three'), … … 398 406 pattern = '' 399 407 400 def __init__(self, group ):401 Node.__init__(self, object.__repr__(self) )408 def __init__(self, group, *args, **kwargs): 409 Node.__init__(self, object.__repr__(self), *args, **kwargs) 402 410 self.group = group 403 411 cly/trunk/cly/console.py
r435 r455 245 245 246 246 247 def error(*args):247 def cerror(*args): 248 248 """Print a message in red to stderr.""" 249 249 cprint(sys.stderr, "^1^B" + ' '.join(map(str, args)) + '^N') 250 250 251 251 252 def fatal(*args):252 def cfatal(*args): 253 253 """Print a message in red to stderr then exit with status -1.""" 254 254 cprint(sys.stderr, "^1^B" + ' '.join(map(str, args)) + '^N') … … 256 256 257 257 258 def warning(*args):258 def cwarning(*args): 259 259 """Print a yellow warning message to stderr.""" 260 260 cprint(sys.stderr, "^3^B" + ' '.join(map(str, args)) + '^N') 261 261 262 262 263 def info(*args):263 def cinfo(*args): 264 264 """Print a green notice.""" 265 265 cprint("^2" + ' '.join(map(str, args)) + '^N') cly/trunk/cly/extra.py
r434 r455 10 10 11 11 12 __all__ = [' static_candidates']12 __all__ = ['cull_candidates', 'static_candidates'] 13 13 __docformat__ = 'restructuredtext en' 14 15 16 def cull_candidates(candidates, text): 17 """Cull candidates that do not start with ``text``.""" 18 return filter(None, [c + ' ' for c in candidates if c.startswith(text)]) 14 19 15 20 cly/trunk/cly/interactive.py
r438 r455 170 170 if with_backtrace: 171 171 import traceback 172 console. error(traceback.format_exc())172 console.cerror(traceback.format_exc()) 173 173 else: 174 console. error('error: %s' % e)174 console.cerror('error: %s' % e) 175 175 else: 176 176 raise … … 196 196 + len(Interact.prompt)) 197 197 if len(indent + text) > term_width: 198 console. error(indent + '^')199 console. error(text)198 console.cerror(indent + '^') 199 console.cerror(text) 200 200 else: 201 console. error(indent + '^ ' + text)201 console.cerror(indent + '^ ' + text) 202 202 203 203 def write_history(self): … … 254 254 (' ' * (context.cursor + len(Interact.prompt)), 255 255 ', '.join(candidates)) 256 console. error(text)256 console.cerror(text) 257 257 cly.rlext.force_redisplay() 258 258 return cly/trunk/doc/developers-guide.rst
r441 r455 8 8 9 9 CLY allows developers to quickly and easily add interactive shell environments 10 to their applications, whether existing or new. 11 12 It offers a simple syntax for defining grammars and a powerful interactive 13 shell based on readline, all with automatic full tab completion and contextual 14 help. 10 to their applications. 11 12 It offers a simple syntax and a powerful interactive shell based on readline, 13 all with automatic full tab completion and contextual help. Applications that 14 don't wish to (or can't) utilise the readline integration may still find the 15 CLY parser useful: it powers the readline shell and offers the same completion 16 and contextual help, through an API. 15 17 16 18 Constructing a Grammar 17 19 ---------------------- 20 21 The syntax of a shell is defined as a tree of ``Node`` objects. 22 23 A node matches a token of user input. 24 25 .. code-block:: python 26 27 one=Node('One') 28 29 30 , but may additionally have other behaviour such as 31 storing the token for later use. The children of each node define the next set 32 of valid tokens. 18 33 19 34 The developer defines their syntax using a hierarchy of objects. Syntactically, … … 31 46 32 47 grammar = Grammar( 33 one=Node('Command 1')( 34 one_one=Node('Command 1.1'), 35 one_two=Node('Command 1.2'), 36 ), 37 two=Node('Command 2')( 48 one=Node('1')( 49 one_one=Node('1.1')( 50 Action(one_one), 51 ), 52 one_two=Node('1.2')( 53 Action(one_two), 54 ), 55 ), 56 two=Node('2')( 57 Action(two), 38 58 ), 39 59 ) cly/trunk/setup.py
r436 r455 9 9 author='Alec Thomas', 10 10 author_email='alec@swapoff.org', 11 version='0.9alpha 1',11 version='0.9alpha2', 12 12 description='"cmd" on steroids', 13 13 long_description=\
