Parser - Read superclass name
This commit is contained in:
parent
164e7952bd
commit
33c28db780
1 changed files with 6 additions and 1 deletions
|
@ -225,6 +225,11 @@ impl Parser {
|
||||||
/// ```
|
/// ```
|
||||||
fn parse_class(&mut self) -> SloxResult<StmtNode> {
|
fn parse_class(&mut self) -> SloxResult<StmtNode> {
|
||||||
let name = self.consume_identifier("expected class name")?;
|
let name = self.consume_identifier("expected class name")?;
|
||||||
|
let superclass = match self.expect(&[TokenType::Less]) {
|
||||||
|
None => None,
|
||||||
|
Some(_) => Some(self.consume_identifier("expected superclass name")?),
|
||||||
|
};
|
||||||
|
|
||||||
self.consume(&TokenType::LeftBrace, "'{' expected")?;
|
self.consume(&TokenType::LeftBrace, "'{' expected")?;
|
||||||
let mut members = Vec::new();
|
let mut members = Vec::new();
|
||||||
while !self.check(&TokenType::RightBrace) && !self.is_at_end() {
|
while !self.check(&TokenType::RightBrace) && !self.is_at_end() {
|
||||||
|
@ -259,7 +264,7 @@ impl Parser {
|
||||||
|
|
||||||
Ok(StmtNode::ClassDecl(ClassDecl {
|
Ok(StmtNode::ClassDecl(ClassDecl {
|
||||||
name,
|
name,
|
||||||
superclass: None,
|
superclass,
|
||||||
members,
|
members,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue