Changeset 455

Show
Ignore:
Timestamp:
08/22/07 06:58:21 (1 year ago)
Author:
athomas
Message:

cly: Update version.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • cly/trunk/cly/builder.py

    r437 r455  
    139139        for this node. See __init__ for more information on attributes. 
    140140 
     141        As a special case, if a positional argument is a `Grammar` object, its 
     142        *children* will be merged. 
     143 
    141144        >>> top = Node('Top', name='top') 
    142145        >>> top(subnode=Node('Subnode')) 
     
    146149        """ 
    147150        for node in anonymous: 
     151            if isinstance(node, Grammar): 
     152                children = dict([(n.name, n) for n in node]) 
     153                self(**children) 
     154                continue 
    148155            if not isinstance(node, Node): 
    149156                raise InvalidAnonymousNode('Anonymous node is not a Node object') 
     
    237244    def children(self, context, follow=False): 
    238245        """Iterate over child nodes, optionally follow()ing branches. 
     246 
    239247        >>> from cly.parser import Context 
    240248        >>> tree = Node('One')(two=Node('Two', three=Node('Three'), 
     
    398406    pattern = '' 
    399407 
    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
    402410        self.group = group 
    403411 
  • cly/trunk/cly/console.py

    r435 r455  
    245245 
    246246 
    247 def error(*args): 
     247def cerror(*args): 
    248248    """Print a message in red to stderr.""" 
    249249    cprint(sys.stderr, "^1^B" + ' '.join(map(str, args)) + '^N') 
    250250 
    251251 
    252 def fatal(*args): 
     252def cfatal(*args): 
    253253    """Print a message in red to stderr then exit with status -1.""" 
    254254    cprint(sys.stderr, "^1^B" + ' '.join(map(str, args)) + '^N') 
     
    256256 
    257257 
    258 def warning(*args): 
     258def cwarning(*args): 
    259259    """Print a yellow warning message to stderr.""" 
    260260    cprint(sys.stderr, "^3^B" + ' '.join(map(str, args)) + '^N') 
    261261 
    262262 
    263 def info(*args): 
     263def cinfo(*args): 
    264264    """Print a green notice.""" 
    265265    cprint("^2" + ' '.join(map(str, args)) + '^N') 
  • cly/trunk/cly/extra.py

    r434 r455  
    1010 
    1111 
    12 __all__ = ['static_candidates'] 
     12__all__ = ['cull_candidates', 'static_candidates'] 
    1313__docformat__ = 'restructuredtext en' 
     14 
     15 
     16def 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)]) 
    1419 
    1520 
  • cly/trunk/cly/interactive.py

    r438 r455  
    170170                        if with_backtrace: 
    171171                            import traceback 
    172                             console.error(traceback.format_exc()) 
     172                            console.cerror(traceback.format_exc()) 
    173173                        else: 
    174                             console.error('error: %s' % e) 
     174                            console.cerror('error: %s' % e) 
    175175                    else: 
    176176                        raise 
     
    196196                        + len(Interact.prompt)) 
    197197        if len(indent + text) > term_width: 
    198             console.error(indent + '^') 
    199             console.error(text) 
     198            console.cerror(indent + '^') 
     199            console.cerror(text) 
    200200        else: 
    201             console.error(indent + '^ ' + text) 
     201            console.cerror(indent + '^ ' + text) 
    202202 
    203203    def write_history(self): 
     
    254254                       (' ' * (context.cursor + len(Interact.prompt)), 
    255255                        ', '.join(candidates)) 
    256                 console.error(text) 
     256                console.cerror(text) 
    257257                cly.rlext.force_redisplay() 
    258258                return 
  • cly/trunk/doc/developers-guide.rst

    r441 r455  
    88 
    99CLY 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. 
     10to their applications. 
     11 
     12It offers a simple syntax and a powerful interactive shell based on readline, 
     13all with automatic full tab completion and contextual help. Applications that 
     14don't wish to (or can't) utilise the readline integration may still find the 
     15CLY parser useful: it powers the readline shell and offers the same completion 
     16and contextual help, through an API. 
    1517 
    1618Constructing a Grammar 
    1719---------------------- 
     20 
     21The syntax of a shell is defined as a tree of ``Node`` objects. 
     22 
     23A 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 
     31storing the token for later use. The children of each node define the next set 
     32of valid tokens. 
    1833 
    1934The developer defines their syntax using a hierarchy of objects. Syntactically, 
     
    3146 
    3247  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), 
    3858      ), 
    3959  ) 
  • cly/trunk/setup.py

    r436 r455  
    99      author='Alec Thomas', 
    1010      author_email='alec@swapoff.org', 
    11       version='0.9alpha1', 
     11      version='0.9alpha2', 
    1212      description='"cmd" on steroids', 
    1313      long_description=\