Package tp :: Package client :: Package pyscheme :: Module parser
[show private | hide private]
[frames | no frames]

Module tp.client.pyscheme.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
  eat(tokens, tokenType)
Digest the first token in our tokens list, making sure that we're biting on the right tokenType of thing.
  identity_cont(val)
  parse(s)
Parse a single string.
  parseAtom(tokens, cont)
Returns an Atom, given a sequence of tokens.
  parseExpression(tokens, cont)
Returns an Expression, given a sequence of tokens.
  parseExpressionStar(tokens, cont)
Tries to eat as many expressions as it can see.
  parseList(tokens, cont)
Parses a parenthesized list expression.
  parseSingleExpression(tokens, cont)
Returns a single Expression, given a sequence of tokens.
  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.
  toNumber(s)
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__

Type:
str
Value:
'MIT License'                                                          

EOF_TOKEN

Type:
tuple
Value:
(None, None)                                                           

PATTERNS

Type:
list
Value:
[('whitespace', <_sre.SRE_Pattern object at 0xb7aa1920>),
 ('comment', <_sre.SRE_Pattern object at 0xb7a08928>),
 ('(', <_sre.SRE_Pattern object at 0xb79f3020>),
 (')', <_sre.SRE_Pattern object at 0xb79f3250>),
 ('number', <_sre.SRE_Pattern object at 0x818f410>),
 ('symbol', <_sre.SRE_Pattern object at 0x825eea8>),
 ('string', <_sre.SRE_Pattern object at 0xb7ad9ab0>),
 ("'", <_sre.SRE_Pattern object at 0xb79f3410>),
...                                                                    

Generated by Epydoc 2.1 on Fri Jan 1 08:00:26 2010 http://epydoc.sf.net