hsh :: command :: Token :: Class Token
[hide private]
[frames] | no frames]

Class Token

object --+
         |
        Token
Known Subclasses:

Part of a command representing a syntactic token.

The top of the token class hierarchy. Subclasses need to implement methods defined here.

Additionally, subclasses may wish to override these class variables:

commencer_ch = None # Character indicating the start of the token dquotable = False # True to permit the token within double quotes.

Instance Methods [hide private]
 
__init__(self)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
 
__str__(self)
Return the raw text entered by the user.
 
__len__(self)
There is no default implementation of this method.
 
modify(self, txt='', begin=0, end=None)
Modify this token by replacing the text between begin and end with the given text.
 
expand(self)
Return the expanded version of this token.
 
completions(self, cloc)
Return a list of completions for this token from the specified cursor location.
 
expand_directives(self)
Return the list of directives which are expanded from this token.
 
commences(self, txt)
Return True if the beginning of the provided text can validly start this token.
 
terminates(self, txt)
Return a pair of strings if the first character of the provided text would terminate this token.
 
terminated(self)
Return True if this token will not accept any more characters at the end because it has terminated.
 
dump(self)
Return a representation of the token tree as a list of strings.

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __subclasshook__

Class Variables [hide private]
  commencer_ch = None
hash(x)
  dquotable = False
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self)
(Constructor)

 

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Overrides: object.__init__
(inherited documentation)

__str__(self)
(Informal representation operator)

 

Return the raw text entered by the user. There is no default implementation of this method.

Overrides: object.__str__

modify(self, txt='', begin=0, end=None)

 

Modify this token by replacing the text between begin and end with the given text. begin defaults to the beginning of the token, end to the end, and txt to the empty string.

Returns a 3-tuple:

  1. string: text which wasn't used by this token and spills over to the next token.
  2. boolean: True means that this token may absorb some characters from the next token. Spill over is not possible in this case.
  3. boolean: True means that this token needs to be deleted. May include spillover.

The default implementation checks the insertion range, raising an exception in case of error, but does not perform the actual modify.

expand(self)

 

Return the expanded version of this token. Return value is a list of strings in which any special shell syntax is replaced with its expanded value, appropriate for passing as an arg in a process invocation.

Arg tokens will perform glob expansion on the results of this value, so other tokens should protect their response using escape_glob_chars() if appropriate.

The default implementation returns an array with one element containing the raw token.

completions(self, cloc)

 

Return a list of completions for this token from the specified cursor location. If no possible completions exist, [] is returned. If possible completions exist, a list of strings is returned. The first item is the root of the completions, the rest are possible extensions of the root. Most tokens will return None if the cursor is not at the end. The default implementation returns nothing.

expand_directives(self)

 

Return the list of directives which are expanded from this token. The HashDirective token will return something here, but most other tokens use the default implementation which returns an empty list.

commences(self, txt)

 

Return True if the beginning of the provided text can validly start this token.

The default implementation returns True iff txt matches the regexp self.commencer. The default value of self.commencer is \S to match non-whitespace.

terminates(self, txt)

 

Return a pair of strings if the first character of the provided text would terminate this token. The first string are the characters to be included in the token, the second are the characters which spill over to the next token. Return None if the text would not terminate the token.

The token mustn't end in an escape character (\) because that would make the test incorrect.

The default implementation matches txt against the regexp self.terminator. On a match it returns match groups 1 and 2, otherwise it returns None. The default value of self.terminator is ()(\s) to terminate on whitespace, but not accept it.

terminated(self)

 

Return True if this token will not accept any more characters at the end because it has terminated. The default implementation returns False.

dump(self)

 

Return a representation of the token tree as a list of strings. The default implementation returns an empty list.