Parse Haxe lines

This commit is contained in:
2019-03-13 14:42:21 -06:00
parent cc290b4ee7
commit cd88a35999
2 changed files with 14 additions and 7 deletions

View File

@@ -19,6 +19,7 @@ enum ExprType {
EStitch(name: String);
EComment(message: String);
ENoOp;
EHaxeLine(haxe: String);
}
typedef HankExpr = {
@@ -37,7 +38,8 @@ class Parser {
'->' => divert,
'===' => knot,
'==' => knot,
'=' => stitch
'=' => stitch,
'~' => haxeLine
];
var buffers: Array<FileBuffer> = [];
@@ -115,7 +117,7 @@ class Parser {
}
static function lineComment(line: String, rob: FileBuffer, position: FileBuffer.Position) : ExprType {
return EComment(line.substr(2));
return EComment(StringTools.trim(line.substr(2)));
}
static function blockComment(line: String, rob: FileBuffer, position: FileBuffer.Position) : ExprType {
@@ -140,7 +142,7 @@ class Parser {
text = rob.take(endIdx);
rob.drop('*/');
return EComment(text);
return EComment(StringTools.trim(text));
}
static function include(line: String, rob: FileBuffer, position: FileBuffer.Position) : ExprType {
@@ -167,4 +169,8 @@ class Parser {
return EStitch("tokens[1]");
}
static function haxeLine(line: String, rob: FileBuffer, position: FileBuffer.Position) : ExprType {
return EHaxeLine(StringTools.trim(line.substr(1)));
}
}

View File

@@ -20,9 +20,10 @@ class ParserTest extends utest.Test {
function testParseMain() {
var parser = new Parser();
ast = parser.parseFile('examples/main/main.hank');
assertNextExpr(EComment(" comments in Hank start with a double-slash"));
assertNextExpr(EComment(" Or you can split comments\nacross more than one line "));
assertNextExpr(EComment(" Or you can use block comments inline "));
assertNextExpr(EComment("comments in Hank start with a double-slash"));
assertNextExpr(EComment("Or you can split comments\nacross more than one line"));
assertNextExpr(EComment("Or you can use block comments inline"));
assertNextExpr(EHaxeLine('var demo_var = "dynamic content";'));
assertNextExpr(EComment("Hank scripts can embed Haxe logic by starting a line with '~'"));
}
}