goffrie / plex

a parser and lexer generator as a Rust procedural macro
Apache License 2.0
410 stars 28 forks source link

[HELP] Function argument parser #48

Closed Totobird-Creations closed 2 years ago

Totobird-Creations commented 2 years ago

Hello. I would like to create a parser that can find LPAREN (IDENTIFIER COLON TYPE (COMMA IDENTIFIER COLON TYPE)*)? RPAREN. How can I repeatedly find a specific pattern?

pub enum DeclarationContent {
    Function {
        name : String,
        argTypes : HashMap<String, Types>, // <- I would like to find multiple of these
        returnTypes : Types,
        body : FunctionBody
    }
}

pub struct FunctionBody {
    expressions : Vec<Expression> // and multiple of these.
}

pub enum Types {
    Void,
    Integer,
    FloatingPoint,
    String,
    Character,
    Boolean,
    Array {
        length : i32,
        types  : Box<Types>
    },
    UnsizedArray {
        types : Box<Types>
    },
    Tuple {
        types : Box<Vec<Types>>
    },
    Dictionary {
        keyTypes   : Box<Types>,
        valueTypes : Box<Types>
    },
    Function {
        argsTypes   : Box<Vec<Types>>,
        returnTypes : Box<Types>
    },
    Other {
        name : String
    }
}
Totobird-Creations commented 2 years ago

I figured out a way.