| Home | Trees | Index | Help |
|---|
| Package tp :: Package client :: Package pyscheme :: Module parser |
|
parser.py --- A small scheme parser.
Danny Yoo (dyoo@hkn.eecs.berkeley.edu)
This parser might be useful if we wanted to grab information from the
user using Schemeish lists. It might also be nice if one is planning
to write a Scheme interpreter in Python. *cough*
The main functions to use in this module are
tokenize(): makes a list of tokens out of a string
parse(s): parse string s, and return a either an atomic value
(symbol or number) or a pair.
If anything bad happens during the parsing, we'll raise a ParserError.
Some special notes: this module should behave well even under unusual
input: there should be no possibility of hitting the recursion limit,
since we are using trampolined style.
| Classes | |
|---|---|
ParserTests |
|
| Exceptions | |
|---|---|
ParserError |
Our personalized exception class. |
| Function Summary | |
|---|---|
Digest the first token in our tokens list, making sure that we're biting on the right tokenType of thing. | |
identity_cont(val)
| |
Parse a single string. | |
Returns an Atom, given a sequence of tokens. | |
Returns an Expression, given a sequence of tokens. | |
Tries to eat as many expressions as it can see. | |
Parses a parenthesized list expression. | |
Returns a single Expression, given a sequence of tokens. | |
Take a quick glance at the first token in our tokens list. | |
Given a string 's', return a list of its tokens. | |
Tries to convert string 's' into a number. | |
| Variable Summary | |
|---|---|
str |
__license__ = 'MIT License'
|
tuple |
EOF_TOKEN = (None, None)
|
list |
PATTERNS = [('whitespace', <_sre.SRE_Pattern object at 0...
|
| Function Details |
|---|
eat(tokens, tokenType)Digest the first token in our tokens list, making sure that we're biting on the right tokenType of thing. |
parse(s)Parse a single string. This is just a convenience function. |
parseAtom(tokens, cont)Returns an Atom, given a sequence of tokens. An atom is either a number, a symbol, or a string. |
parseExpression(tokens, cont=<function identity_cont at 0xb7a0741c>)
Returns an Expression, given a sequence of tokens.
An expression is made up of one of the following things:
o A quoted expression
o An atom (like a number or symbol or string)
o A list.
This procedure tries to take care of all these potentials.
|
parseExpressionStar(tokens, cont)Tries to eat as many expressions as it can see. |
parseList(tokens, cont)Parses a parenthesized list expression. |
parseSingleExpression(tokens, cont=<function identity_cont at 0xb7a0741c>)Returns a single Expression, given a sequence of tokens. Raises a ParserException if our tokens haven't been exhausted. |
peek(tokens)Take a quick glance at the first token in our tokens list. |
tokenize(s)Given a string 's', return a list of its tokens. A token can be one of the following types listed in the PATTERNS above, and each token is a 2-tuple: (type, content). |
toNumber(s)Tries to convert string 's' into a number. |
| Variable Details |
|---|
__license__
|
EOF_TOKEN
|
| Home | Trees | Index | Help |
|---|
| Generated by Epydoc 2.1 on Fri Jan 1 08:00:26 2010 | http://epydoc.sf.net |