| Home | Trees | Indices | Help |
|---|
|
|
Parser Base.
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
Reads one section from the given text. section -> block | assignment | line >>> read_section = Parser().read_section >>> read_section('foo\nbar\n') (<line: [t'foo\n']>, 'bar\n') >>> read_section('$ a = b + 1\nfoo\n') (<assignment: 'a = b + 1'>, 'foo\n') read_section('$for in range(10):\n hello $i\nfoo) |
Reads a var statement. >>> read_var = Parser().read_var >>> read_var('var x=10\nfoo') (<var: x = 10>, 'foo') >>> read_var('var x: hello $name\nfoo') (<var: x = join_(u'hello ', escape_(name, True))>, 'foo') |
Reads section by section till end of text. >>> read_suite = Parser().read_suite >>> read_suite('hello $name\nfoo\n') [<line: [t'hello ', $name, t'\n']>, <line: [t'foo\n']>] |
Reads one line from the text. Newline is supressed if the line ends with \. >>> readline = Parser().readline >>> readline('hello $name!\nbye!') (<line: [t'hello ', $name, t'!\n']>, 'bye!') >>> readline('hello $name!\\\nbye!') (<line: [t'hello ', $name, t'!']>, 'bye!') >>> readline('$f()\n\n') (<line: [$f(), t'\n']>, '\n') |
Reads a node from the given text and returns the node and remaining text. >>> read_node = Parser().read_node >>> read_node('hello $name') (t'hello ', '$name') >>> read_node('$name') ($name, '') |
Reads a text node from the given text. >>> read_text = Parser().read_text >>> read_text('hello $name') (t'hello ', '$name') |
Reads a python expression from the text and returns the expression and remaining text. expr -> simple_expr | paren_expr simple_expr -> id extended_expr extended_expr -> attr_access | paren_expr extended_expr | '' attr_access -> dot id extended_expr paren_expr -> [ tokens ] | ( tokens ) | { tokens } >>> read_expr = Parser().read_expr >>> read_expr("name") ($name, '') >>> read_expr("a.b and c") ($a.b, ' and c') >>> read_expr("a. b") ($a, '. b') >>> read_expr("name</h1>") ($name, '</h1>') >>> read_expr("(limit)ing") ($(limit), 'ing') >>> read_expr('a[1, 2][:3].f(1+2, "weird string[).", 3 + 4) done.') ($a[1, 2][:3].f(1+2, "weird string[).", 3 + 4), ' done.') |
Reads assignment statement from text. >>> read_assignment = Parser().read_assignment >>> read_assignment('a = b + 1\nfoo') (<assignment: 'a = b + 1'>, 'foo') |
Returns the first python token from the given text. >>> python_lookahead = Parser().python_lookahead >>> python_lookahead('for i in range(10):') 'for' >>> python_lookahead('else:') 'else' >>> python_lookahead(' x = 1') ' ' |
Read a block of text. A block is what typically follows a for or it statement. It can be in the same line as that of the statement or an indented block. >>> read_indented_block = Parser().read_indented_block >>> read_indented_block(' a\n b\nc', ' ') ('a\nb\n', 'c') >>> read_indented_block(' a\n b\n c\nd', ' ') ('a\n b\nc\n', 'd') >>> read_indented_block(' a\n\n b\nc', ' ') ('a\n\n b\n', 'c') |
Reads a python statement. >>> read_statement = Parser().read_statement >>> read_statement('for i in range(10): hello $name') ('for i in range(10):', ' hello $name') |
| Home | Trees | Indices | Help |
|---|
| Generated by Epydoc 3.0.1 on Wed Aug 4 09:57:30 2010 | http://epydoc.sourceforge.net |