Skip to content

Commit 1d63c5e

Browse files
committed
parsing new use and namespace syntax
1 parent 852914f commit 1d63c5e

File tree

14 files changed

+221
-162
lines changed

14 files changed

+221
-162
lines changed

cool_app/lib/math.lv

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use foo/bar/baz#(lorem as lorem)
2-
31
-- Adds two integers
42
add :: fun (~x: Int, to y: Int) -> Int: x + y
53

cool_app/main.lv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
use lib/math
22
use num#(get_three, get_four)
33

4-
main :: fun () -> Int: math#add(2, to: get_three())
4+
main :: fun () -> Int: math#add(math#pi, to: get_three())

discussion.md

Lines changed: 0 additions & 33 deletions
This file was deleted.

for_the_website.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

next_up.md

Whitespace-only changes.

src/blossom/printer.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ pub fn error(text: &str) {
77
pub fn success(text: &str) {
88
println!("{}", text.green());
99
}
10+
11+
pub fn info(text: &str) {
12+
println!("{text}");
13+
}

src/checker/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ impl Checker {
304304
type_hint,
305305
)
306306
}
307-
ExpressionKind::Ident(name) => {
307+
ExpressionKind::Ident { name, .. } => {
308308
if let Some((var_id, var_type)) = self.lookup_variable(name, self.cur_scope) {
309309
Self::typed_expression(
310310
CheckedExpressionData::Ident {
@@ -395,7 +395,9 @@ impl Checker {
395395
type_hint,
396396
)
397397
}
398-
ExpressionKind::FunctionCall { name, arguments } => {
398+
ExpressionKind::FunctionCall {
399+
name, arguments, ..
400+
} => {
399401
let mut args = vec![];
400402

401403
for arg in arguments {

src/lexer/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ impl<'src> Lexer<'src> {
3535
match cur_char {
3636
'/' => self.make_single_char_token(cur_index, Slash),
3737
'.' => self.make_single_char_token(cur_index, Dot),
38-
' ' => self.make_single_char_token(cur_index, NamespaceAccess),
3938
'+' => self.make_single_char_token(cur_index, Plus),
4039
'-' => {
4140
self.next();
@@ -61,6 +60,7 @@ impl<'src> Lexer<'src> {
6160
Token::new(Minus, cur_index, 1)
6261
}
6362
}
63+
'#' => self.make_single_char_token(cur_index, Hash),
6464
'*' => self.make_single_char_token(cur_index, Asterisk),
6565
'&' => self.make_single_char_token(cur_index, BitAnd),
6666
'|' => self.make_single_char_token(cur_index, BitOr),
@@ -124,6 +124,7 @@ impl<'src> Lexer<'src> {
124124
let ident = self.read_ident(cur_index);
125125
match ident {
126126
"fun" => Token::new(Fun, cur_index, 3),
127+
"use" => Token::new(Use, cur_index, 3),
127128
"take" => Token::new(Take, cur_index, 4),
128129
"mut" => Token::new(Mut, cur_index, 3),
129130
"read" => Token::new(Read, cur_index, 4),

src/lexer/tokens.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use std::fmt::Display;
55
pub enum TokenKind {
66
// keywords:
77
Fun, // fun
8+
Use, // use
9+
As, // as
810
Take, // take
911
Mut, // mut
1012
Read, // read
@@ -18,18 +20,18 @@ pub enum TokenKind {
1820
False, // false
1921

2022
// syntax
21-
LParen, // (
22-
RParen, // )
23-
LBrace, // {
24-
RBrace, // }
25-
Colon, // :
26-
Comma, // ,
27-
Tilde, // ~
28-
SingleEqual, // =
29-
RArrow, // ->
30-
Slash, // /
31-
Dot, // .
32-
NamespaceAccess, // #
23+
LParen, // (
24+
RParen, // )
25+
LBrace, // {
26+
RBrace, // }
27+
Colon, // :
28+
Comma, // ,
29+
Tilde, // ~
30+
SingleEqual, // =
31+
RArrow, // ->
32+
Slash, // /
33+
Dot, // .
34+
Hash, // #
3335

3436
// operators:
3537
ExclamationMark, // !
@@ -58,6 +60,8 @@ impl Display for TokenKind {
5860
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5961
let str = match self {
6062
Self::Fun => "fun",
63+
Self::Use => "use",
64+
Self::As => "as",
6165
Self::Take => "take",
6266
Self::Mut => "mut",
6367
Self::Read => "read",
@@ -80,7 +84,7 @@ impl Display for TokenKind {
8084
Self::SingleEqual => "=",
8185
Self::Slash => "/",
8286
Self::Dot => ".",
83-
Self::NamespaceAccess => "#",
87+
Self::Hash => "#",
8488
Self::ExclamationMark => "!",
8589
Self::Plus => "+",
8690
Self::Minus => "-",

src/parser/ast.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ impl Expression {
1818
pub enum ExpressionKind {
1919
BoolLiteral(bool),
2020
IntLiteral(isize),
21-
Ident(String),
21+
Ident {
22+
name: String,
23+
namespace: Option<String>,
24+
},
2225
Block(Vec<Expression>),
2326
Prefix {
2427
operator: PrefixOperator,
@@ -42,6 +45,7 @@ pub enum ExpressionKind {
4245
},
4346
FunctionCall {
4447
name: String,
48+
namespace: Option<String>,
4549
arguments: Vec<FunctionArgument>,
4650
},
4751
Use {
@@ -70,7 +74,7 @@ impl ExpressionKind {
7074
Infix { left, right, .. } => left.kind.is_const() && right.kind.is_const(),
7175
VariableDecl { value, mutable, .. } => !mutable && value.kind.is_const(),
7276
FunctionCall { .. } => false,
73-
BoolLiteral(_) | IntLiteral(_) | Ident(_) | Function { .. } | Use { .. } => true,
77+
BoolLiteral(_) | IntLiteral(_) | Ident { .. } | Function { .. } | Use { .. } => true,
7478
}
7579
}
7680
}

0 commit comments

Comments
 (0)