Skip to content

Commit 04db5e8

Browse files
committed
uh i forgot this, well it has multiline comments or sum
1 parent 6890d5a commit 04db5e8

File tree

6 files changed

+35
-3
lines changed

6 files changed

+35
-3
lines changed

lang/examples/mixed.modu

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ if c == 3 {
1919
example();
2020
}
2121

22+
print('test');
23+
let d = 'potato' + " chips";
24+
print(d + '!');
2225

2326
// Output
2427
//
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
cool thingy
3+
made by me
4+
*/
5+
6+
print("lol" /* potato */)
7+
8+
let a = 1 /* +3472834 */ + 1
9+
10+
print(a)

lang/src/ast.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ impl std::fmt::Display for AST {
155155
.replace("\\n", "\n")
156156
.replace("\\r", "\r")
157157
.replace("\\\"", "\"")
158-
.replace("\\'", "'")
159158
.replace("\\\\", "\\")
160-
.replace("\"", "");
159+
.replace("\"", "")
160+
.replace("'", "");
161161

162162
write!(f, "{}", s)
163163
},

lang/src/lexer.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ pub enum Token {
2525
#[regex("//[^\n]*|/\\*([^*]|\\*[^/])*\\*/")]
2626
Comment,
2727

28+
#[token("/*")]
29+
MultiLineCommentStart,
30+
31+
#[token("*/")]
32+
MultiLineCommentEnd,
33+
2834
#[token("let")]
2935
Let,
3036

lang/src/parser.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,7 @@ pub fn parse(input: &str, context: &mut HashMap<String, AST>) -> Result<(), (Str
863863
let mut line_map = HashMap::new();
864864
let mut current_line = 0;
865865
let mut bodies_deep = 0;
866+
let mut inside_multiline_comment = false;
866867

867868
for line in input.split("\n") {
868869
current_line += 1;
@@ -873,7 +874,19 @@ pub fn parse(input: &str, context: &mut HashMap<String, AST>) -> Result<(), (Str
873874
let mut body_starts = false;
874875

875876
while let Some(token) = lexer.next() {
877+
if inside_multiline_comment {
878+
if token == Ok(Token::MultiLineCommentEnd) {
879+
inside_multiline_comment = false;
880+
} else {
881+
continue;
882+
}
883+
}
884+
876885
match token {
886+
Ok(Token::MultiLineCommentStart) => {
887+
inside_multiline_comment = true;
888+
}
889+
877890
Ok(Token::Import) => {
878891
temp_ast.push(AST::Import {
879892
file: None,

lang/src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ mod tests {
6969
fn create_context_test() {
7070
let context = create_context();
7171

72-
assert_eq!(context.len(), 3);
72+
assert_eq!(context.len(), 4);
7373
assert_eq!(context.contains_key("print"), true);
7474
assert_eq!(context.contains_key("exit"), true);
7575
assert_eq!(context.contains_key("input"), true);

0 commit comments

Comments
 (0)