Skip to content

Commit b1e810f

Browse files
committed
Begin parsing expressions
Fixed README, combined parser and parsertypes, added some keywords, etc.
1 parent 314e43d commit b1e810f

5 files changed

Lines changed: 672 additions & 238 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func main: (vessel: Vessel /* Vessel holds vessel data */) -> () {
2222
if ?hi_text { // Not worth printing if its empty
2323
print(hi_text);
2424
}
25-
}
25+
};
2626
```
2727

2828
### Keywords

src/lexer.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ enum LexErrorReason {
6262
}
6363

6464
#[allow(dead_code)]
65-
#[derive(Debug)]
65+
#[derive(Clone, Debug, PartialEq)]
6666
pub enum Token {
6767
Terminator,
6868
Assign,
@@ -88,11 +88,13 @@ pub enum Token {
8888
BracesBegin,
8989
BracesEnd,
9090
Bar,
91+
Quote,
9192
Let,
9293
Mut,
9394
TypeSeperator,
9495
Type,
9596
Function,
97+
Const,
9698
OutputSpecifier,
9799
Macro,
98100
LitI16(i16),
@@ -109,19 +111,25 @@ pub enum Token {
109111
TypeBool,
110112
TypeByte,
111113
TypeStr,
114+
Array,
115+
Tuple,
112116
Struct,
113117
Enum,
114118
Dot,
115119
If,
116120
Else,
117121
Switch,
122+
Tick,
123+
Loop,
124+
Return,
125+
Break,
118126
Async,
119127
Import,
120128
Identifier(String),
121129
}
122130

123131
#[allow(dead_code)]
124-
#[derive(Debug)]
132+
#[derive(Clone, Debug)]
125133
pub struct DataToken {
126134
token: Token,
127135
pos: (usize, usize),
@@ -131,6 +139,10 @@ impl DataToken {
131139
fn new(tok: Token, pos: (usize, usize)) -> DataToken {
132140
DataToken { token: tok, pos: pos }
133141
}
142+
143+
pub fn inner(&self) -> &Token {
144+
&self.token
145+
}
134146
}
135147

136148
pub fn lex_string(inp_str: String) -> Result<Vec<DataToken>, LexError> {
@@ -168,6 +180,7 @@ pub fn lex_string(inp_str: String) -> Result<Vec<DataToken>, LexError> {
168180
'.' => tokens.push(DataToken::new(Token::Dot, pos)),
169181
'?' => tokens.push(DataToken::new(Token::Logical, pos)),
170182
':' => tokens.push(DataToken::new(Token::TypeSeperator, pos)),
183+
'$' => tokens.push(DataToken::new(Token::Quote, pos)),
171184
'=' => if chars.peek() == Some(&'=') {
172185
chars.next();
173186
tokens.push(DataToken::new(Token::Equals, pos));
@@ -442,6 +455,7 @@ pub fn lex_string(inp_str: String) -> Result<Vec<DataToken>, LexError> {
442455
"mut" => tokens.push(DataToken::new(Token::Mut, pos)),
443456
"type" => tokens.push(DataToken::new(Token::Type, pos)),
444457
"func" => tokens.push(DataToken::new(Token::Function, pos)),
458+
"const" => tokens.push(DataToken::new(Token::Const, pos)),
445459
"macro" => tokens.push(DataToken::new(Token::Macro, pos)),
446460
"true" => tokens.push(DataToken::new(Token::LitBool(true), pos)),
447461
"false" => tokens.push(DataToken::new(Token::LitBool(false), pos)),
@@ -452,11 +466,17 @@ pub fn lex_string(inp_str: String) -> Result<Vec<DataToken>, LexError> {
452466
"bool" => tokens.push(DataToken::new(Token::TypeBool, pos)),
453467
"byte" => tokens.push(DataToken::new(Token::TypeByte, pos)),
454468
"str" => tokens.push(DataToken::new(Token::TypeStr, pos)),
469+
"array" => tokens.push(DataToken::new(Token::Array, pos)),
470+
"tuple" => tokens.push(DataToken::new(Token::Tuple, pos)),
455471
"struct" => tokens.push(DataToken::new(Token::Struct, pos)),
456472
"enum" => tokens.push(DataToken::new(Token::Enum, pos)),
457473
"if" => tokens.push(DataToken::new(Token::If, pos)),
458474
"else" => tokens.push(DataToken::new(Token::Else, pos)),
459475
"switch" => tokens.push(DataToken::new(Token::Switch, pos)),
476+
"tick" => tokens.push(DataToken::new(Token::Tick, pos)),
477+
"loop" => tokens.push(DataToken::new(Token::Loop, pos)),
478+
"return" => tokens.push(DataToken::new(Token::Return, pos)),
479+
"break" => tokens.push(DataToken::new(Token::Break, pos)),
460480
"async" => tokens.push(DataToken::new(Token::Async, pos)),
461481
"import" => tokens.push(DataToken::new(Token::Import, pos)),
462482
_ => tokens.push(DataToken::new(Token::Identifier(buf), pos))

src/main.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,17 @@ struct Args {
2929
/// If not specified, will write to STDOUT.
3030
#[arg(short, long)]
3131
output: Option<PathBuf>,
32+
33+
/// Specify an error to get more information
34+
#[arg(long)]
35+
error: Option<String>,
3236
}
3337

3438
struct Log {
3539
verbosity: u8,
3640
}
3741

38-
#[allow(dead_code, unreachable_code, unused_variables)]
42+
#[allow(dead_code, unreachable_code)]
3943
impl Log {
4044
fn from_args(args: &Args) -> Log {
4145
Log {
@@ -68,6 +72,11 @@ static LOG: LazyLock<Log> = LazyLock::new(|| Log::from_args(&*ARGS));
6872
fn main() {
6973
LOG.debug(&format!("{:?}\n", *ARGS));
7074

75+
if let Some(ec) = &ARGS.error {
76+
println!("{}", explanation(ec));
77+
std::process::exit(0);
78+
}
79+
7180
let inp_string = if let Some(fp) = &ARGS.path {
7281
fs::read_to_string(fp).expect("Please provide a valid file path")
7382
} else {
@@ -89,8 +98,6 @@ fn main() {
8998

9099
LOG.debug(&format!("Lexed:\n\n{:?}\n", &tokenstream));
91100

92-
std::process::exit(0);
93-
94101
let ast = match parser::parse_tokens(tokenstream) {
95102
Ok(ast) => ast,
96103
Err(e) => {
@@ -99,7 +106,11 @@ fn main() {
99106
}
100107
};
101108

102-
// LOG.debug(&format!("Parsed:\n\n{:?}\n", &ast));
109+
LOG.debug(&format!("Parsed:\n\n{:?}\n", &ast));
103110

104111
todo!("AST parsing!");
105112
}
113+
114+
fn explanation(s: &String) -> &'static str {
115+
todo!()
116+
}

0 commit comments

Comments
 (0)