[fine] starting to work on methods
This commit is contained in:
parent
fde5579479
commit
0d48bfb113
4 changed files with 22 additions and 8 deletions
|
|
@ -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");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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"),
|
||||
|
|
|
|||
|
|
@ -1,14 +1,23 @@
|
|||
class Point {
|
||||
x: f64;
|
||||
y: f64;
|
||||
|
||||
fun something_static() -> f64 {
|
||||
12
|
||||
}
|
||||
|
||||
fun square_length(self) -> f64 {
|
||||
self.x * self.x + self.y * self.y
|
||||
}
|
||||
}
|
||||
|
||||
fun test() -> f64 {
|
||||
let pt = new Point { x: 7, y: 23 };
|
||||
let z = pt.x;
|
||||
let z = pt.x + pt.square_length() + Point::something_static();
|
||||
z
|
||||
}
|
||||
|
||||
// @ignore WIP: Methods
|
||||
// @no-errors
|
||||
// @eval: Float(7.0)
|
||||
// @compiles-to:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue