[fine] starting to work on methods

This commit is contained in:
John Doty 2024-01-22 06:04:13 -08:00
parent fde5579479
commit 0d48bfb113
4 changed files with 22 additions and 8 deletions

View file

@ -570,6 +570,8 @@ fn class(p: &mut CParser) {
while !p.at(TokenKind::RightBrace) && !p.eof() {
if p.at(TokenKind::Identifier) {
field_decl(p);
} else if p.at(TokenKind::Fun) {
function(p);
} else {
p.advance_with_error("expected a field declaration");
}

View file

@ -412,7 +412,10 @@ impl<'a> Semantics<'a> {
pub fn snapshot_errors(&self) -> Vec<Error> {
let mut result = (*self.errors.borrow()).clone();
result.sort_by(|a, b| a.start.0.cmp(&b.start.0));
result.sort_by(|a, b| match a.start.0.cmp(&b.start.0) {
std::cmp::Ordering::Equal => a.start.1.cmp(&b.start.1),
o => o,
});
result
}

View file

@ -53,7 +53,7 @@ pub enum TokenKind {
Or,
Return,
Select,
This,
Selff,
True,
While,
Yield,
@ -322,11 +322,11 @@ impl<'a> Tokens<'a> {
if ident == "select" {
return TokenKind::Select;
}
if ident == "self" {
return TokenKind::Selff;
}
}
't' => {
if ident == "this" {
return TokenKind::This;
}
if ident == "true" {
return TokenKind::True;
}
@ -579,14 +579,14 @@ mod tests {
test_tokens!(
more_keywords,
"fun if import let return select this true while truewhile new",
"fun if import let return select self true while truewhile new",
(0, Fun, "fun"),
(4, If, "if"),
(7, Import, "import"),
(14, Let, "let"),
(18, Return, "return"),
(25, Select, "select"),
(32, This, "this"),
(32, Selff, "self"),
(37, True, "true"),
(42, While, "while"),
(48, Identifier, "truewhile"),