diff options
Diffstat (limited to 'oryxc/src/parser.rs')
| -rw-r--r-- | oryxc/src/parser.rs | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/oryxc/src/parser.rs b/oryxc/src/parser.rs index 89e2769..629b290 100644 --- a/oryxc/src/parser.rs +++ b/oryxc/src/parser.rs @@ -44,6 +44,12 @@ pub struct AstNode { pub sub: SubNodes, } +#[derive(Debug)] +pub struct Ast { + pub nodes: Soa<AstNode>, + pub extra: Vec<u32>, +} + struct Parser<'a> { ast: Soa<AstNode>, extra_data: Vec<u32>, @@ -536,6 +542,15 @@ impl<'a> Parser<'a> { self.next(); /* Consume ‘(’ */ return self.scratch_guard(|p| { let lhs = p.parse_decl_list()?; + if let Some(&ty) = p.scratch[lhs..].last() { + if ty == u32::MAX { + let i = p.scratch.len() as u32 - 2; + return Err(OryxError::new( + p.get_view_at(i), + "function parameter has no declared type", + )); + } + } if p.get_n_move() != TokenType::ParenR { /* TODO: Highlight the entire argument list */ @@ -568,7 +583,7 @@ impl<'a> Parser<'a> { _ => p.scratch.len(), }; - let nargs = rhs - lhs; + let nargs = (rhs - lhs) / 2; let nrets = p.scratch.len() - rhs; let argbeg = p.extra_data.len(); let retbeg = argbeg + nargs * 2 + 1; @@ -686,6 +701,7 @@ impl<'a> Parser<'a> { | TokenType::Asterisk | TokenType::Percent | TokenType::Percent2 + | TokenType::SlashPercent | TokenType::Slash => 5, TokenType::Bar | TokenType::Minus @@ -817,6 +833,7 @@ impl<'a> Parser<'a> { | TokenType::Percent2 | TokenType::Plus | TokenType::Slash + | TokenType::SlashPercent | TokenType::Tilde => { let i = self.cursor; self.next(); @@ -883,9 +900,7 @@ impl<'a> Parser<'a> { } } -pub fn parse( - tokens: &Soa<Token>, -) -> Result<(Soa<AstNode>, Vec<u32>), Vec<OryxError>> { +pub fn parse(tokens: &Soa<Token>) -> Result<Ast, Vec<OryxError>> { let mut p = Parser::new(tokens); while p.get() != TokenType::Eof { p.parse_toplevel(); @@ -902,5 +917,8 @@ pub fn parse( tok: 0, sub: SubNodes(stmtsbeg as u32, nstmts as u32), }); - return Ok((p.ast, p.extra_data)); + return Ok(Ast { + nodes: p.ast, + extra: p.extra_data, + }); } |