[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() {
|
while !p.at(TokenKind::RightBrace) && !p.eof() {
|
||||||
if p.at(TokenKind::Identifier) {
|
if p.at(TokenKind::Identifier) {
|
||||||
field_decl(p);
|
field_decl(p);
|
||||||
|
} else if p.at(TokenKind::Fun) {
|
||||||
|
function(p);
|
||||||
} else {
|
} else {
|
||||||
p.advance_with_error("expected a field declaration");
|
p.advance_with_error("expected a field declaration");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -412,7 +412,10 @@ impl<'a> Semantics<'a> {
|
||||||
|
|
||||||
pub fn snapshot_errors(&self) -> Vec<Error> {
|
pub fn snapshot_errors(&self) -> Vec<Error> {
|
||||||
let mut result = (*self.errors.borrow()).clone();
|
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
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ pub enum TokenKind {
|
||||||
Or,
|
Or,
|
||||||
Return,
|
Return,
|
||||||
Select,
|
Select,
|
||||||
This,
|
Selff,
|
||||||
True,
|
True,
|
||||||
While,
|
While,
|
||||||
Yield,
|
Yield,
|
||||||
|
|
@ -322,11 +322,11 @@ impl<'a> Tokens<'a> {
|
||||||
if ident == "select" {
|
if ident == "select" {
|
||||||
return TokenKind::Select;
|
return TokenKind::Select;
|
||||||
}
|
}
|
||||||
|
if ident == "self" {
|
||||||
|
return TokenKind::Selff;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
't' => {
|
't' => {
|
||||||
if ident == "this" {
|
|
||||||
return TokenKind::This;
|
|
||||||
}
|
|
||||||
if ident == "true" {
|
if ident == "true" {
|
||||||
return TokenKind::True;
|
return TokenKind::True;
|
||||||
}
|
}
|
||||||
|
|
@ -579,14 +579,14 @@ mod tests {
|
||||||
|
|
||||||
test_tokens!(
|
test_tokens!(
|
||||||
more_keywords,
|
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"),
|
(0, Fun, "fun"),
|
||||||
(4, If, "if"),
|
(4, If, "if"),
|
||||||
(7, Import, "import"),
|
(7, Import, "import"),
|
||||||
(14, Let, "let"),
|
(14, Let, "let"),
|
||||||
(18, Return, "return"),
|
(18, Return, "return"),
|
||||||
(25, Select, "select"),
|
(25, Select, "select"),
|
||||||
(32, This, "this"),
|
(32, Selff, "self"),
|
||||||
(37, True, "true"),
|
(37, True, "true"),
|
||||||
(42, While, "while"),
|
(42, While, "while"),
|
||||||
(48, Identifier, "truewhile"),
|
(48, Identifier, "truewhile"),
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,23 @@
|
||||||
class Point {
|
class Point {
|
||||||
x: f64;
|
x: f64;
|
||||||
y: f64;
|
y: f64;
|
||||||
|
|
||||||
|
fun something_static() -> f64 {
|
||||||
|
12
|
||||||
|
}
|
||||||
|
|
||||||
|
fun square_length(self) -> f64 {
|
||||||
|
self.x * self.x + self.y * self.y
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun test() -> f64 {
|
fun test() -> f64 {
|
||||||
let pt = new Point { x: 7, y: 23 };
|
let pt = new Point { x: 7, y: 23 };
|
||||||
let z = pt.x;
|
let z = pt.x + pt.square_length() + Point::something_static();
|
||||||
z
|
z
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @ignore WIP: Methods
|
||||||
// @no-errors
|
// @no-errors
|
||||||
// @eval: Float(7.0)
|
// @eval: Float(7.0)
|
||||||
// @compiles-to:
|
// @compiles-to:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue