Skip to content

Commit 24ae40d

Browse files
proper aliasing for the modules imported with proper malayalam grammar for it
1 parent 6a8fd10 commit 24ae40d

6 files changed

Lines changed: 731 additions & 593 deletions

File tree

src/executor/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub enum Statement {
1717
EmptyExpression((usize, usize), Expression),
1818
Return((usize, usize), Expression),
1919
Write((usize, usize), Expression),
20-
Import((usize, usize), Vec<usize>),
20+
Import((usize, usize), Vec<usize>, Option<usize>),
2121
}
2222

2323
#[derive(Debug, Clone, PartialEq)]

src/executor/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ impl Executor {
221221
self.return_storage = self.eval_arithmetic_logic_expression(expr)?;
222222
self.subroutine_exit_flag = true;
223223
}
224-
Statement::Import((p, q), path) => {
224+
Statement::Import((p, q), path, alias) => {
225225
let mut module_path = String::new();
226226
let mut module_name = String::new();
227227
for (i, id) in path.iter().enumerate() {
@@ -271,7 +271,11 @@ impl Executor {
271271
)),
272272
));
273273
}
274-
self.modules.insert(module_name, exec);
274+
let final_name = match alias {
275+
Some(id) => self.get_symbol_name(*id).unwrap(),
276+
None => module_name,
277+
};
278+
self.modules.insert(final_name, exec);
275279
}
276280
}
277281
}

src/lexer/keywords.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ impl Keywords {
3737
["um", "ഉം"] => TokenType::Um,
3838
["ne_kal", "നെകാൾ"] => TokenType::Nekal,
3939
["kodukuga","kodukuka","madakiayakuga","madakiayakuka","കൊടുക്കുക","മടക്കിഅയയ്ക്കുക"] => TokenType::Return,
40-
["ulppeduthuka","ulppeduthuga","ഉൾപ്പെടുത്തുക"] => TokenType::Import
40+
["ulppeduthuka","ulppeduthuga","ഉൾപ്പെടുത്തുക"] => TokenType::Import,
41+
["ennu","ayi","എന്ന്","ആയി"] => TokenType::As
4142
);
4243

4344
Self { list }

src/lexer/tokens.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ pub enum TokenType {
4141
Import,
4242
Colon,
4343
Dot,
44+
As,
4445
}
4546

4647
impl Display for TokenType {
@@ -86,6 +87,7 @@ impl Display for TokenType {
8687
TokenType::Import => write!(f, "ulppeduthuka"),
8788
TokenType::Colon => write!(f, ":"),
8889
TokenType::Dot => write!(f, "."),
90+
TokenType::As => write!(f, "ennu"),
8991
}
9092
}
9193
}

src/parser/grammar.lalrpop

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ Statement:Statement = {
3535
<a:@L> <expr:Expression> ";" <b:@R> => Statement::EmptyExpression((a,b),expr),
3636
<a:@L> <condition:Conditional> If Loop "{" <s:SourceUnit> "}" <b:@R> => Statement::Loop((a,b),condition,s),
3737
<a:@L> <condition:ConditionalWithAgglutination> Loop "{" <s:SourceUnit> "}" <b:@R> => Statement::Loop((a,b),condition,s),
38-
<a:@L> <path:ImportPath> Import ";" <b:@R> => Statement::Import((a,b), path),
38+
<a:@L> <path:ImportPath> <alias:Identifier> As Import ";" <b:@R> => Statement::Import((a,b), path, Some(match alias { TokenType::Symbol(s) => s, _ => unreachable!() })),
39+
<a:@L> <path:ImportPath> Import ";" <b:@R> => Statement::Import((a,b), path, None),
3940
};
4041

4142
ImportPath: Vec<usize> = {
@@ -151,6 +152,7 @@ extern {
151152
"[" => TokenType::SquareOpen,
152153
"]" => TokenType::SquareClose,
153154
Import => TokenType::Import,
155+
As => TokenType::As,
154156
":" => TokenType::Colon,
155157
"." => TokenType::Dot,
156158
}

0 commit comments

Comments
 (0)