skip to navigation
skip to content

Not Logged In

scum 0.5.1

scum is a simple but powerful Python library to tokenize, parse and evaluate character input streams

scum - powerful and easy tokenization
-------------------------------------

Scum is a simple but powerful Python library to tokenize,
parse and evaluate character input streams. It is Python 2 and
Python 3 compatible since version 0.5.1.

## Usage

There is a full fledged example for parsing math expressions under
`examples/math.py`. Here's an excerpt of the declaration of the lexer.

```python
def parse(expr):
r""" Parses a math expression and returns a callable object
that accepts a dictionary and returns the result of the
expression. """

lexer = scum.Lexer()
lexer.declare_token('op', Keyword('**'), priority=600)
lexer.declare_token('op', Keyword('*'), priority=400)
lexer.declare_token('op', Keyword('/'), priority=400)
lexer.declare_token('op', Keyword('+'), priority=200)
lexer.declare_token('op', Keyword('-'), priority=200)
lexer.declare_token('op', Keyword('%'), priority=100)
lexer.declare_token('po', Keyword('('))
lexer.declare_token('pc', Keyword(')'))
lexer.declare_token('dg', Gather(digits))
lexer.declare_token('vr', Gather(id_start, id_continue))
lexer.declare_token(None, Gather(whitespace))

lexer.set_source(scum.Scanner.from_string(expr))
lexer.next()

return parse_maths(lexer)
```

## License

*scum* is licensed under the MIT License.

* __Author__: Niklas Rosenstein
* __Email__: rosensteinniklas@gmail.com
* __License__: MIT  
File Type Py Version Uploaded on Size
scum-0.5.1.tar.gz (md5) Source 2014-04-20 13KB
  • Downloads (All Versions):
  • 9 downloads in the last day
  • 48 downloads in the last week
  • 197 downloads in the last month