Remove comment tokens from parsing

This commit is contained in:
2019-03-15 22:27:15 -06:00
parent df878b4409
commit 520f97ebe3
4 changed files with 12 additions and 41 deletions

View File

@@ -1,4 +1,5 @@
This file contains test cases for /*output expression*/ parsing.
This file contains test cases for output expression parsing.
A line won't be interrupted /*by inline comments*/ or anything.
Multiline comments /*will not
split*/ an output expression. This should parse as one line of output.
Comments at the end of lines won't parse as part of the Output. // I'm my own expression!
@@ -12,4 +13,5 @@ You can {
} the value of multiline expressions without splitting a line of output.
You can have diverts inline. -> somewhere_else
You can have diverts as branches of a sequence {-> first_time|-> second_time}
You can have diverts as branches of a sequence {-> first_time|-> second_time}
You can have partial output[.]that changes after a choice is made!

View File

@@ -5,7 +5,6 @@ enum OutputType {
// Alt(a: Alt); // TODO re-implement Alts recursively. Each alt branch should be an Output
HExpression(h: String); // An embedded Haxe expression whose value will be inserted
InlineDivert(t: String); // A divert statement on the same line as an output sequence.
InlineComment(c: String); // A block comment in the middle of an output sequence
ToggleOutput(o: Output, invert: Bool); // Output that will sometimes be displayed (i.e. [bracketed] section in a choice text or the section following the bracketed section)
}
@@ -17,7 +16,11 @@ class Output {
this.parts = parts;
}
public static function parse(expression): Output {
public static function parse(expression, rob: FileBuffer): Output {
// Parse out optional text parts
// Find the first level of nested brace, expressions, and parse them out
return new Output([]);
}
}

View File

@@ -6,7 +6,6 @@ enum ExprType {
EDivert(target: String);
EKnot(name: String);
EStitch(name: String);
EComment(message: String);
ENoOp;
EHaxeLine(haxe: String);
}
@@ -22,8 +21,6 @@ typedef HankAST = Array<HankExpr>;
class Parser {
var symbols = [
'INCLUDE ' => include,
'//' => lineComment,
'/*' => blockComment,
'->' => divert,
'===' => knot,
'==' => knot,
@@ -105,35 +102,6 @@ class Parser {
return tokens;
}
static function lineComment(line: String, rob: FileBuffer, position: FileBuffer.Position) : ExprType {
return EComment(StringTools.trim(line.substr(2)));
}
static function blockComment(line: String, rob: FileBuffer, position: FileBuffer.Position) : ExprType {
var text = line.substr(2);
rob.give(text + '\n');
var nesting = 1;
var endIdx = -1;
while (nesting > 0) {
var nextCommentTerminator = rob.peekWhichComesNext(['/*', '*/']);
switch (nextCommentTerminator) {
case Some([0, index]):
nesting += 1;
case Some([1, index]):
nesting -= 1;
endIdx = index;
case None:
throw 'Block comment starting at ${position} never terminates!';
}
}
text = rob.take(endIdx);
rob.drop('*/');
return EComment(StringTools.trim(text));
}
static function include(line: String, rob: FileBuffer, position: FileBuffer.Position) : ExprType {
var tokens = lineTokens(line, 2, position);
return EIncludeFile(tokens[1]);
@@ -145,7 +113,7 @@ class Parser {
}
static function output(line: String, rob: FileBuffer, position: FileBuffer.Position) : ExprType {
return EOutput(Output.parse(line));
return EOutput(Output.parse(line, rob));
}
static function knot(line: String, rob: FileBuffer, position: FileBuffer.Position) : ExprType {

View File

@@ -21,17 +21,15 @@ class ParserTest extends utest.Test {
function testParseOutput() {
var parser = new Parser();
ast = parser.parseFile('examples/parsing/output.hank');
assertNextExpr(EOutput(new Output([Text("This file contains test cases for output expression parsing.")])));
assertNextExpr(EOutput(new Output([Text("A line won't be interrupted or anything.")])));
}
function testParseMisc() {
var parser = new Parser();
ast = parser.parseFile('examples/parsing/misc.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(EHaxeLine('var demo_var = "dynamic content";'));
assertNextExpr(EComment("Hank scripts can embed Haxe logic by starting a line with '~'"));
assertNextExpr(EKnot("knot_example"));
}
}