mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
@@ -1,38 +1,3 @@
|
||||
|
||||
|
||||
print 1 == 1; //true
|
||||
print 1 != 1; //false
|
||||
|
||||
print 1 < 2; //true
|
||||
|
||||
print "foo" > "bar"; //true
|
||||
|
||||
|
||||
print 1 < 2; //true
|
||||
print 1 > 2; //false
|
||||
|
||||
print 2 <= 2; //true
|
||||
print 2 >= 2; //true
|
||||
|
||||
print 1 <= 2; //true
|
||||
print 1 >= 2; //false
|
||||
|
||||
print true && true; //true
|
||||
print true && false; //false
|
||||
print false && true; //false
|
||||
print false && false; //false
|
||||
|
||||
print true || true; //true
|
||||
print true || false; //true
|
||||
print false || true; //true
|
||||
print false || false; //false
|
||||
|
||||
print !true; //false
|
||||
print !false; //true
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//nesting
|
||||
print true && false || true; //TODO: a warning is needed for this
|
||||
print "\tHello\nworld";
|
||||
|
||||
@@ -309,11 +309,14 @@ static Toy_AstFlag literal(Toy_Bucket** bucketHandle, Toy_Parser* parser, Toy_As
|
||||
|
||||
case TOY_TOKEN_LITERAL_STRING: {
|
||||
char buffer[parser->previous.length + 1];
|
||||
unsigned int escapeCounter = 0;
|
||||
|
||||
unsigned int i = 0, o = 0;
|
||||
do {
|
||||
buffer[i] = parser->previous.lexeme[o];
|
||||
if (buffer[i] == '\\' && parser->previous.lexeme[++o]) {
|
||||
escapeCounter++;
|
||||
|
||||
//also handle escape characters
|
||||
switch(parser->previous.lexeme[o]) {
|
||||
case 'n':
|
||||
@@ -334,7 +337,7 @@ static Toy_AstFlag literal(Toy_Bucket** bucketHandle, Toy_Parser* parser, Toy_As
|
||||
} while (parser->previous.lexeme[o++] && i < parser->previous.length);
|
||||
|
||||
buffer[i] = '\0';
|
||||
Toy_private_emitAstValue(bucketHandle, rootHandle, TOY_VALUE_FROM_STRING(Toy_createStringLength(bucketHandle, buffer, i)));
|
||||
Toy_private_emitAstValue(bucketHandle, rootHandle, TOY_VALUE_FROM_STRING(Toy_createStringLength(bucketHandle, buffer, i - escapeCounter)));
|
||||
|
||||
return TOY_AST_FLAG_NONE;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,9 @@ print "Hello world!";
|
||||
//print a concatenated string
|
||||
print "Hello" .. "world!";
|
||||
|
||||
//print with escaped characters
|
||||
print "\tHello\nworld";
|
||||
|
||||
//TODO: in the repl, -s to supress output, or -d to print debugging info
|
||||
|
||||
//TODO: the `assert` keyword will be useful for these
|
||||
//TODO: the `assert` keyword will be useful for these
|
||||
|
||||
Reference in New Issue
Block a user