Skip to content

shirakawayohane/picktok

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PickTok

A parser combinator like nom but specialized in parsing &[Token].

It has similar combinators as nom, but also provides convenient parser generator macro for each Token variants.

If your parser system has tokenize or lex stage, then it will be happy to code with picktok to make your Syntax Tree.

Example

Here is an example of parsing integer list from Token with variant of LParen, RParent, Integer.

// mod token

mod token {
    use token_combinator::TokenParser;

    #[derive(Clone, TokenParser)]
    pub enum Token {
        LParen,       // (
        RParen,       // )
        Integer(i64), // 10, 0xFF, 0b01, 0o70...
    }
}

mod ast {
    pub enum AST {
        IntegerLiteral,
        List(Vec<AST>),
    }
}

use token::parser::*;

pub fn parse_list(tokens: &[token::Token]) -> ast::AST {
    map(
        delimited(
            l_paren,
            many0(map(integer, |i| AST::IntegerLiteral(i))),
            r_paren,
        ),
        |integers| AST::List(integers),
    )(tokens)
}
// mod parser
use token::parser::*

fn parse_list(tokens: &[Token]) -> AST {
  
}

About

A parser combinator for parsing &[Token].

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages