Skip to content

Commit b6a797c

Browse files
committed
final touches and I will upload
1 parent 51a53e2 commit b6a797c

3 files changed

Lines changed: 105 additions & 9 deletions

File tree

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# compiled data
2+
__pycache__
3+
# .vscode settings
4+
.vscode
5+
# virtual enviornments like uv
6+
.venv

README.md

Lines changed: 88 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,36 @@ Links to the original library
1111
Unlike the typescript library all 3 of llparse's libraries were combined in this version of the code for the sake of portability...
1212
I ended up mentioning how I did this a while back and I also had a concept for a C parser as well but I just didn't like it and I ended up using this instead but I also learned typescript as a bonus and It was alot of fun for me. I don't plan to make this into a real pypi library yet but I also didn't want to take away from the magic of the original source code that I borrowed from...
1313

14+
# Looking back on my dead work 2 years later
15+
I had this idea lay somewhat dormant for 2 years and now seeing that I wanted to write a new socks5 server parser writing it in python
16+
just made a little bit more sense to me, this way I don't have to stress over typescript or needing to relearn things I learned over 2 years ago.
17+
I have now made this project public on pypi for anybody who wanted to dig into it and access the code
18+
or generate your own parsers for C.
19+
20+
If your better at typescript. I reccommend sticking to the typescript version, no pressure. This library aims to not compete
21+
with llparse but to act as an alternative for users who prefer python over typescript/node-js, simillar to puppeteer or pyppeteer.
22+
Personally maybe we should make a rust crate for a rust version or at least someone will do it.
23+
24+
25+
## Warnings
26+
- It should be safe enough to generate code and stress-test it but if something doesn't seem right to you, be sure to throw an issue and share a typescript version of something that works in typescript but not in python, this way something unintended by the typescript developers can be solved.
27+
- Some code may look unfinished or may need further internal refactoring/polishing and with the other things I want to go out and do
28+
such as contributions to aiohttp and it's other libraries, cyares, winloop, aiothreading, aiocallback & deprecated-params and I also have an irl Part-time Job, ideas and pull requests are welcomed without hesitation. I maintain other projects listed above to prevent myself from experiencing burnout.
29+
- Pytest testsuite has not been made yet. If this is a concern to you, please throw an issue on github. (Pytests and new workflows soon!)
30+
- Some code might be spaghetti-code (because It's been 2 years since I touched much of the code if not at all)
31+
e.g. tests module should be moved away from the library into the github repo.
32+
- There's some research portions such as tools to help generate things for cython or tools to make mirrors of llhttp's code
33+
such as it's native c code (I was looking to see if it could be theoretically autogenerated). Feel free to use them but
34+
do it at your own risk. They maybe incompleted or not throughly stress-tested.
35+
36+
## New Features
37+
- Throw me an issue if typescript llparse introduces something new that you want for me or another contributor to try and implement
38+
just seeing llparse add new features is nothing but exciting to me.
39+
40+
- If you want a feature that typescript llparse doesn't have, be sure to try making a pull request over there as well and not just here,
41+
there's a good chance they will appericate you for helping over there too and your helping make llhttp better by doing so. :)
42+
43+
1444
# Why Did I Translate llparse to python?
1545
- I wanted to work with a langauge I was more familiar with
1646
- Better educate myself and others on how these great libraries like llhttp are made
@@ -29,12 +59,61 @@ Unlike llparse in typescript, this version has more integrated and experimental
2959
I've added a few other things like the dot compiler from llparse_dot and I also made a brand new cython compiler
3060
for it making easy and simple to make pxd files to port your projects to cython
3161

32-
# TODOS
33-
- Make a script to compile projects to node-js by making a .gyp file for them...
34-
- Make a script for compiling C files to `.lib` and `.dll` extensions as well as the `.a / .so` files seen on Linux and Apple Systems...
35-
- Add in additional debuggers
36-
- Make a youtube tutorial on how to use this library on Vizonex Builds
37-
- Release pypi packages
38-
- Build an enum compiler like seen in llhttp
39-
- Implement llvm bytecode and js outputs if I have the time for it.
40-
62+
63+
64+
## How to use
65+
```python
66+
# The good old http_parser was borrowed from llparse.org to demonstrate this for you :)
67+
from llparse import LLParse
68+
69+
p = LLParse("http_parser")
70+
method = p.node("method")
71+
beforeUrl = p.node("before_url")
72+
urlSpan = p.span(p.code.span("on_url"))
73+
url = p.node("url")
74+
http = p.node("http")
75+
76+
# Add custom uint8_t property to the state
77+
p.property("i8", "method")
78+
79+
# Store method inside a custom property
80+
onMethod = p.invoke(p.code.store("method"), beforeUrl)
81+
82+
# Invoke custom C function
83+
complete = p.invoke(
84+
p.code.match("on_complete"),
85+
{
86+
# Restart
87+
0: method
88+
},
89+
p.error(4, "`on_complete` error"),
90+
)
91+
92+
method.select(
93+
{
94+
"HEAD": 0,
95+
"GET": 1,
96+
"POST": 2,
97+
"PUT": 3,
98+
"DELETE": 4,
99+
"OPTIONS": 5,
100+
"CONNECT": 6,
101+
"TRACE": 7,
102+
"PATCH": 8,
103+
},
104+
onMethod,
105+
).otherwise(p.error(5, "Expected method"))
106+
107+
beforeUrl.match(" ", beforeUrl).otherwise(urlSpan.start(url))
108+
109+
url.peek(" ", urlSpan.end(http)).skipTo(url)
110+
111+
http.match(" HTTP/1.1\r\n\r\n", complete).otherwise(
112+
p.error(6, "Expected HTTP/1.1 and two newlines")
113+
)
114+
115+
c = p.build(method)
116+
print(c.c)
117+
open("http_parser.c", "w").write(c.c)
118+
open("http_parser.h", "w").write(c.header)
119+
```

pyproject.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[project]
2+
name = "llparse"
3+
version = "0.1.0"
4+
description = "A Parody of llparse written for writing C Parsers with Python"
5+
readme = "README.md"
6+
authors = [
7+
{ name = "Vizonex", email = "VizonexBusiness@gmail.com" }
8+
]
9+
requires-python = ">=3.9"
10+
dependencies = []
11+

0 commit comments

Comments
 (0)