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>
## 💾 Install
Download the latest version of PPark from
the [GitHub releases](https://github.com/aabbfive/PPark/releases) page.
## 💬 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)
```
## ©️ License
MIT. Copyright (c) [Aabbfive](https://github.com/aabbfive).
<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>
## 💾 Install
Download the latest version of PPark from
the [GitHub releases](https://github.com/aabbfive/PPark/releases) page.
## 💬 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)
```
## ©️ License
MIT. Copyright (c) [Aabbfive](https://github.com/aabbfive).
Project details
Release history Release notifications | RSS feed
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 details)
File details
Details for the file PPark-1.0.1.tar.gz
.
File metadata
- Download URL: PPark-1.0.1.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 445744646f67593a67148465f2fa55ea3982aed91b6423e126fba20b6da56142 |
|
MD5 | 2fa3f32de99dfb551d456394f8915ce3 |
|
BLAKE2b-256 | eaded7367a328247aa26e6649138950657062484d205f6b83a5003be9a383c07 |