-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reimplemented parser with parser combinator
- Loading branch information
Showing
14 changed files
with
783 additions
and
1,339 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
pub struct Loc { | ||
row : Int | ||
col : Int | ||
index : Int | ||
} derive(Show) | ||
|
||
pub enum LexError_ { | ||
UnexpectedChar(Char, Loc) | ||
} derive(Show) | ||
|
||
pub type! LexError LexError_ | ||
|
||
fn new_loc() -> Loc { | ||
{ row: 1, col: 1, index: 0 } | ||
} | ||
|
||
fn advance(self : Loc, c : Char) -> Loc { | ||
if c == '\n' { | ||
self.advance_line() | ||
} else { | ||
{ ..self, col: self.col + 1, index: self.index + 1 } | ||
} | ||
} | ||
|
||
fn advance_line(self : Loc) -> Loc { | ||
{ row: self.row + 1, col: 1, index: self.index + 1 } | ||
} | ||
|
||
pub enum Token { | ||
ID(String) | ||
COLON | ||
ASSIGN | ||
SEMICOL | ||
FN | ||
LPAREN | ||
RPAREN | ||
ARROW | ||
COMMA | ||
LBRACE | ||
RBRACE | ||
EQ | ||
LE | ||
ADD | ||
SUB | ||
MUL | ||
DIV | ||
IF | ||
ELSE | ||
LBKT | ||
RBKT | ||
BOOL(Bool) | ||
DOT | ||
ARRAY | ||
UNIT_T | ||
BOOL_T | ||
DOUBLE_T | ||
I32(Int) | ||
F64(Double) | ||
NOT | ||
INT_T | ||
LET | ||
EOF | ||
} derive(Show, Eq) | ||
|
||
typealias Lexeme = (Token, Loc, Loc) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
typealias S = @types.Syntax | ||
|
||
typealias PS = Parser[S] | ||
|
||
typealias T = @types.Type | ||
|
||
typealias PT = Parser[T] | ||
|
||
typealias B = @types.Op | ||
|
||
typealias PB = Parser[B] |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.