Skip to content

How to ignore some nodes? #120

Answered by numToStr
numToStr asked this question in Q&A
Apr 15, 2022 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

It seems I was on the right path and just missing the .flatten() combinator at the end. I am not sure whether this is correct or not, but I got the result that I wanted. Here is the new code

use chumsky::{
    prelude::{any, choice, filter, just, take_until, Simple},
    text::{self, newline, TextParser},
    Parser,
};

#[derive(Debug)]
pub struct Lua;

impl Lua {
    pub fn parse(src: &str) -> Result<Vec<String>, Vec<Simple<char>>> {
        let node = choice((
            just("---")
                .then(filter(|c| *c != '\n').repeated().collect::<String>())
                .map(|(s, x)| format!("{s}{x}")),
            text::keyword("function")
                .ignore_then(filter(|x| *x…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@zesterer
Comment options

Answer selected by numToStr
# for free to join this conversation on GitHub. Already have an account? # to comment
Category
Q&A
Labels
None yet
2 participants