Package nltk :: Package draw :: Module cfg :: Class CFGEditor
[hide private]
[frames] | no frames]

Class CFGEditor

source code

object --+
         |
        CFGEditor

A dialog window for creating and editing context free grammars. CFGEditor places the following restrictions on what CFGs can be edited:

Instance Methods [hide private]
 
__init__(self, parent, cfg=None, set_cfg_callback=None)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
source code
 
_init_startframe(self) source code
 
_init_buttons(self) source code
 
_init_bindings(self) source code
 
_init_prodframe(self) source code
 
_clear_tags(self, linenum)
Remove all tags (except arrow and sel) from the given line of the text widget used for editing the productions.
source code
 
_check_analyze(self, *e)
Check if we've moved to a new line.
source code
 
_replace_arrows(self, *e)
Replace any '->' text strings with arrows (char \256, in symbol font).
source code
 
_analyze_token(self, match, linenum)
Given a line number and a regexp match for a token on that line, colorize the token.
source code
 
_init_nonterminal_tag(self, tag, foreground='blue') source code
 
_analyze_line(self, linenum)
Colorize a given line.
source code
 
_mark_error(self, linenum, line)
Mark the location of an error in a line.
source code
 
_analyze(self, *e)
Replace -> with arrows, and colorize the entire buffer.
source code
 
_parse_productions(self)
Parse the current contents of the textwidget buffer, to create a list of productions.
source code
 
_destroy(self, *e) source code
 
_ok(self, *e) source code
 
_apply(self, *e) source code
 
_reset(self, *e) source code
 
_cancel(self, *e) source code
 
_help(self, *e) source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Class Variables [hide private]
  ARROW = '\xde'
  _LHS_RE = re.compile(r'(^\s*\w+\s*)(->|(\xde))')
  _ARROW_RE = re.compile(r'\s*(->|(\xde))\s*')
  _PRODUCTION_RE = re.compile(r'(^\s*\w+\s*)(->|(\xde))\s*((\w+|...
  _TOKEN_RE = re.compile(r'\w+|->|\'[\w ]+\'|"[\w ]+"|(\xde)')
  _BOLD = ('helvetica', -12, 'bold')
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, parent, cfg=None, set_cfg_callback=None)
(Constructor)

source code 

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

Overrides: object.__init__
(inherited documentation)

_check_analyze(self, *e)

source code 

Check if we've moved to a new line. If we have, then remove all colorization from the line we moved to, and re-colorize the line that we moved from.

_replace_arrows(self, *e)

source code 

Replace any '->' text strings with arrows (char \256, in symbol font). This searches the whole buffer, but is fast enough to be done anytime they press '>'.

_analyze_token(self, match, linenum)

source code 

Given a line number and a regexp match for a token on that line, colorize the token. Note that the regexp match gives us the token's text, start index (on the line), and end index (on the line).


Class Variable Details [hide private]

_PRODUCTION_RE

Value:
re.compile(r'(^\s*\w+\s*)(->|(\xde))\s*((\w+|\'[\w ]*\'|"[\w ]*"|\|)\s\
*)*$')