Add comments

This commit is contained in:
ElementG9 2020-08-24 21:35:16 -06:00
parent 93e6d490a0
commit 3daa431ec3
2 changed files with 58 additions and 7 deletions

View File

@ -61,6 +61,43 @@ pub fn tokenize(source: &str) -> Vec<Token> {
}); });
current += 1; current += 1;
} }
'/' => {
if chars.get(current + 1) == Some(&'/') {
// A "// ..." comment.
'comment: loop {
if chars.get(current) == Some(&'\n') || chars.get(current) == None {
break 'comment;
}
current += 1;
}
} else if chars.get(current + 1) == Some(&'*') {
let mut depth = 1;
'comment: loop {
if chars.get(current) == Some(&'*')
&& chars.get(current + 1) == Some(&'/')
&& depth == 1
{
break 'comment;
} else if chars.get(current) == None {
break 'comment;
} else {
current += 1;
}
}
// 'comment: loop {
// if (chars.get(current) == Some(&'/')
// && chars.get(current - 1) == Some(&'*'))
// || chars.get(current) == None
// {
// current += 1;
// break 'comment;
// }
// current += 1;
// }
} else {
current += 1;
}
}
_ => current += 1, // Just skip it if it's incorrect. _ => current += 1, // Just skip it if it's incorrect.
} }
} }

View File

@ -1,7 +1,21 @@
log(2); // A comment
log(5i);
log(3f); /* A multi-line
log(2.5); comment! */
log(true, false);
log("Hello world!"); /*
log('Goodbye cruel world!') A multi-line comment!
/*
A nested multi-line comment!
*/
*/
log(2); // An implicit int.
log(5i); // An explicit int.
log(2.5); // An implicit float.
log(3f); // An explicit float.
log(true, false); // Logging two things in one log call, and booleans.
log("Hello world!"); // A string literal.
log("What's that over there?"); // A string showing how different delimiters layer.