Skip to content

crazycodestar/toy-html-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Browser Engine (Rust)

A tiny experimental browser engine implemented in Rust. It parses a hard-coded HTML string into a DOM and "renders" it by pretty-printing the node tree to the terminal. This is mainly for learning and experimentation with parsing, DOM construction, and rendering logic.

Requirements

  • Rust toolchain (recommended: install via rustup)
    • cargo available on your PATH
  • Supported platforms: Developed and tested on macOS, but it should work anywhere Rust does.

Getting Started

  1. Clone the repository
git clone <your-repo-url> browser_engine
cd browser_engine
  1. Verify Rust is installed
rustc --version
cargo --version

If these commands fail, install Rust from https://rustup.rs.

Building the Project

From the project root:

cargo build

This will compile the browser_engine binary into the target/debug directory.

Running the Browser Engine

From the project root:

cargo run

This will:

  • Parse the hard-coded HTML string defined in src/main.rs
  • Build a DOM tree via the html and dom modules
  • Render/pretty-print the resulting node tree to the terminal via the draw module

You can change the HTML input by editing the string in src/main.rs (look for the html variable inside the main function).

Project Structure

  • Cargo.toml – Rust package manifest and metadata
  • src/main.rs – Binary entrypoint wiring together parsing and drawing
  • src/html.rs – HTML parser and related logic
  • src/dom.rs – DOM node definitions and tree representation
  • src/draw.rs – Rendering/pretty-printing of the DOM tree to the terminal

Development Tips

  • Format the code
cargo fmt
  • Run with debug output
    You can add println! calls inside html, dom, or draw modules to inspect intermediate structures while learning how the engine works.

Troubleshooting

  • Build fails:

    • Ensure you are using a recent Rust toolchain (rustc --version) compatible with the 2024 edition.
    • Run cargo clean && cargo build to force a fresh build.
  • Binary not found:

    • Always run from the project root with cargo run. Cargo will handle building and running the browser_engine binary for you.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages