Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Nom for Rust #314

Open
DagBjorndal opened this issue Jul 11, 2024 · 0 comments
Open

Add Nom for Rust #314

DagBjorndal opened this issue Jul 11, 2024 · 0 comments

Comments

@DagBjorndal
Copy link

Please complete the following information about the package:

Package name: Nom
Language name: Rust
Website: https://github.com/rust-bakery/nom

Following are optional, but will help us consider adding:

Why is this useful?
When it comes to parsing in Rust; nom is virtually as popular as regex. Arguably, nom is the most rust idiomatic.

Example Code:
The currency in nom is parsers. Parser are built on top of other parsers and then combined in different ways. In the Assembler interpreter (part II), a top level parser to select between different assembly instructions could look something like this:

pub fn tokenize_other(input: &str) -> IResult<&str, Token> {
alt((movri, movrr, addri, addrr, subri, subrr, mulri, mulrr, divri, divrr, cmpri, cmprr, incr, decr,
alt((end, ret, call, jmp, je, jne, jle, jl, jg, jge, label))
))(input)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant