chrome/
lib.rs

1use nom::{
2    branch::alt,
3    bytes::complete::tag,
4    character::complete::{alpha1, alphanumeric1},
5    combinator::recognize,
6    multi::many0,
7    sequence::pair,
8    IResult,
9};
10
11fn identifier(input: &str) -> IResult<&str, &str> {
12    recognize(pair(
13        alt((alpha1, tag("_"))),
14        many0(alt((alphanumeric1, tag("_")))),
15    ))(input)
16}
17
18fn function(input: &str) -> IResult<&str, &str> {
19    recognize(pair(tag("fn"), identifier))(input)
20}
21
22pub fn parse(input: &str) -> IResult<&str, &str> {
23    function(input)
24}