Skip to content
Go back

Building Markdown Parser Using Rust - Introduction

Edit page

So, today we are going to build a markdown parser using Rust programming language. Our goal is to build a markdown parser to learn about parsing concepts and not to build a production grade markdown parser. We are also going to learn rust from beginning while building this project so you don’t need to have any experience in rust programming language.

Prerequisites

Setup

Lets start by setting up the project with rust.

The cargo init command in the terminal. After running the command you’ll see there are some new files and folders created. Let’s look at each of them and understand what are they.

The output of the cargo run command. You can see that it is first compiling the project, then created a development build (not a release build or optimised build) and then started running the project from the target folder. Finally it prints out Hello World.

[!Note] Target Directory In a rust project that uses cargo to manage its dependencies, you’ll always get a target directory where it’ll keep its dev and prod builds. When you execute the command cargo run it’ll create a dev or debug build and run that. If you want to have a production or release build then you can run cargo build.

Let’s now experiment with the main.rs code and instead of printing Hello World!, lets try to print something else like our project title.

Modifying main.rs to print project title

fn main() {
    println!("Starting our Markdown Parser project!");
    println!("This is going to be awesome!");
}

Let’s understand what is happening in this code.

[!Note] If you are coming from python In rust we end each statement with a semicolon and that is required otherwise it’ll throw a compilation error. In rust we use curly brace { } to start and end a function body instead of relying on indentation.

Now you might be wondering what is a macro? It seems like a function and works like a print function. For now, lets not get into that, I’ll explain that later as it might get complicated if you are new to rust. For now, just think of them as function but as we will continue to work more and more on this project, I’ll explain what macro exactly is and how we can create our own macros.

Conclusion

I hope you are excited as I’m for this series and you’ll continue to show up for the rest of the series and build your own markdown parser and most importantly learn something new and exciting. In the next post, we will start working on our markdown parser. See you soon.

This post is part of the "Building Markdown Parser using Rust" series. View all posts in this series


Edit page
Share this post on:

Previous Post
Build Your Own Markdown Parser:Part 2 - Reading File from Command Line