Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty print statement #246

Merged
merged 4 commits into from
May 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"clean": "rimraf ./lib ./types",
"test": "jest",
"lint": "tslint --project .",
"prettier:write": "prettier --write '{bin,src,test}/**/*.{js,ts}'",
"prettier": "prettier --check '{bin,src,test}/**/*.{js,ts}'",
"prettier:write": "prettier --write \"{bin,src,test}/**/*.{js,ts}\"",
sjbarag marked this conversation as resolved.
Show resolved Hide resolved
"prettier": "prettier --check \"{bin,src,test}/**/*.{js,ts}\"",
"prepublishOnly": "npm-run-all --serial clean build lint prettier test"
},
"files": [
Expand Down
11 changes: 9 additions & 2 deletions src/parser/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ export class Parser {

//keep track of the current error count, because if the then branch fails,
//we will trash them in favor of a single error on if
var errorsLengthBeforeBlock = errors.length;
let errorsLengthBeforeBlock = errors.length;

// we're parsing a multi-line ("block") form of the BrightScript if/then/else and must find
// a trailing "end if"
Expand Down Expand Up @@ -1056,7 +1056,14 @@ export class Parser {
| Expr.Expression
| Stmt.PrintSeparator.Tab
| Stmt.PrintSeparator.Space)[] = [];
values.push(expression());

//print statements can be empty, so look for empty print conditions
if (isAtEnd() || check(Lexeme.Newline, Lexeme.Colon)) {
let emptyStringLiteral = new Expr.Literal(new BrsString(""), printKeyword.location);
values.push(emptyStringLiteral);
} else {
values.push(expression());
}

while (!check(Lexeme.Newline, Lexeme.Colon, ...additionalterminators) && !isAtEnd()) {
if (check(Lexeme.Semicolon)) {
Expand Down
8 changes: 8 additions & 0 deletions test/parser/statement/PrintStatement.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ describe("parser print statements", () => {
expect(statements).toMatchSnapshot();
});

it("supports empty print", () => {
let { statements, errors } = brs.parser.Parser.parse([token(Lexeme.Print), EOF]);
expect(errors).toEqual([]);
expect(statements).toBeDefined();
expect(statements).not.toBeNull();
expect(statements).toMatchSnapshot();
});

it("parses print lists with no separator", () => {
let { statements, errors } = parser.parse([
token(Lexeme.Print),
Expand Down
43 changes: 43 additions & 0 deletions test/parser/statement/__snapshots__/PrintStatement.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,46 @@ Array [
},
]
`;

exports[`parser print statements supports empty print 1`] = `
Array [
Print {
"expressions": Array [
Literal {
"_location": Object {
"end": Object {
"column": -9,
"line": -9,
},
"start": Object {
"column": -9,
"line": -9,
},
},
"value": BrsString {
"kind": 2,
"value": "",
},
},
],
"tokens": Object {
"print": Object {
"isReserved": false,
"kind": "Print",
"literal": undefined,
"location": Object {
"end": Object {
"column": -9,
"line": -9,
},
"start": Object {
"column": -9,
"line": -9,
},
},
"text": undefined,
},
},
},
]
`;