Starting to parse formal params
This commit is contained in:
parent
3220f0aec7
commit
34b569eb5f
@ -375,9 +375,16 @@ pub enum Statement {
|
|||||||
Declaration(Declaration),
|
Declaration(Declaration),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ParamName = Rc<String>;
|
||||||
|
type TypeName = Rc<String>;
|
||||||
|
type FormalParamList = Vec<(ParamName, Option<TypeName>)>;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum Declaration {
|
pub enum Declaration {
|
||||||
FuncDecl,
|
FuncDecl {
|
||||||
|
name: Rc<String>,
|
||||||
|
params: FormalParamList,
|
||||||
|
},
|
||||||
TypeDecl(Rc<String>, TypeBody),
|
TypeDecl(Rc<String>, TypeBody),
|
||||||
TypeAlias(Rc<String>, Rc<String>)
|
TypeAlias(Rc<String>, Rc<String>)
|
||||||
}
|
}
|
||||||
@ -475,12 +482,16 @@ impl Parser {
|
|||||||
expect!(self, Keyword(Func), "Expected 'fn'");
|
expect!(self, Keyword(Func), "Expected 'fn'");
|
||||||
let name = self.identifier()?;
|
let name = self.identifier()?;
|
||||||
expect!(self, LParen, "Expected '('");
|
expect!(self, LParen, "Expected '('");
|
||||||
let params = self.param_list();
|
let params = self.param_list()?;
|
||||||
expect!(self, RParen, "Expected ')'");
|
expect!(self, RParen, "Expected ')'");
|
||||||
Ok(Declaration::FuncDecl)
|
let decl = Declaration::FuncDecl {
|
||||||
|
name: name,
|
||||||
|
params: params
|
||||||
|
};
|
||||||
|
Ok(decl)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn param_list(&mut self) -> ParseResult<Vec<Rc<String>>> {
|
fn param_list(&mut self) -> ParseResult<FormalParamList> {
|
||||||
Ok(vec!())
|
Ok(vec!())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user