Skip to main content

Advanced Lexer

Project description

<h1 align="center">
<br>
<a href="https://github.com/aabbfive/PPark">
<img src="PPark.svg" alt="PPark" width="200">
</a>
<br>
PPark
<br>
<br>
</h1>

<h4 align="center">The best lexing library available any python version confused (2.x, 3.x, PyPy...)</h4>

## &#x1F4BE; Install

Download the latest version of PPark from
the [GitHub releases](https://github.com/aabbfive/PPark/releases) page.


## &#x1F4AC; How to Contribute

### Get the code

```
$ git clone https://github.com/aabbfive/PPark.git
$ cd PPark
```

### Install the library

```
$ pip install PPark
```

#### Or

```
$ pip install git+https://github.com/aabbfive/PPark
```

### Examples

```
from PPark import Lexer
from PPark.constant import Keyword, Keywords

lexer = Lexer()
lexer.addRule('INTEGER', r'([0-9]+)')
lexer.addRule('OP', Keywords([
Keyword('}'),
Keyword('{'),
Keyword('^'),
Keyword(']'),
Keyword('['),
Keyword('>'),
Keyword('<'),
Keyword('='),
Keyword('.'),
Keyword('-'),
Keyword(','),
Keyword('+'),
Keyword('**'),
Keyword('*'),
Keyword('/'),
Keyword('//'),
Keyword('%'),
Keyword(')'),
Keyword('(')
]))
@lexer.on_match(r'"([^"\n]|(\\"))*"')
def STRING(token):
token.value = token.value[1:][:-1]
@lexer.on_match(r'[a-zA-Z_$]\w*')
def IDENTIFIER(token):
if keywords.contains(token.value):
token.type = token.value.upper()
return token
lexer.input("""
t = 12*2
""")
for token in lexer:
print(token)
```

## &#x00A9;&#xFE0F; License

MIT. Copyright (c) [Aabbfive](https://github.com/aabbfive).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PPark-1.0.1.tar.gz (3.3 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page