beef331 / website

Code for the official Nim programming language website
https://nim-lang.org
19 stars 1 forks source link

Ferus #80

Closed xTrayambak closed 1 year ago

xTrayambak commented 1 year ago

Name: Ferus + FerusHTML

Author: xTrayambak

Posting: Ferus is a web engine/browser written in Nim. It aims to be fast, compliant and secure. It doesn't do much yet, it simply does HTML/CSS parsing, it also has an IPC layer written using reliable UDP (netty), a sandboxed rendering model (rendering is not done on the main process), an incomplete DOM implementation and an experimental layout engine is being worked on. All of this is done within 2.1k lines of code. My future plans include:

Now, let us talk about Ferus' other component: ferushtml FerusHTML is a safe, fast and (somewhat) compliant HTML parser that is still being worked on. It uses a finite-state-motion based parser but we intend to add a consume based parser soon. It is somewhat fast, it can parse a simple HTML document within 0.1415580014387766 ms, and it also has a utility for dumping a HTMLElement to show it's children in a neatly organized manner. It doesn't support attributes yet, but that is the top priority as of right now.

Here is the basic API:

import ferushtml

let mySource = """
<html>
    <head>
        <title>Hello ferushtml!</title>
    </head>
    <body>
        <p1>This is rather plain.</p1>
    </body>
</html>
"""

# Create a parser
var myParser = newHTMLParser()

# Parse the HTML source
var res = myParser.parse(mySource)

# Dump the source to stdout in a neat tree like manner
echo res.dump()

Compile the code with --threads:on, and we get this: image

You can now time how fast the executable is, or you can check out the benchmark test inside ferushtml tests!

If you are interested in this project, I would appreciate some help at https://github.com/xTrayambak/ferus or https://github.com/xTrayambak/ferushtml.