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

fix(parser,lexer) Optional chaining implementation side effect #30 #31

Merged
merged 1 commit into from
Dec 1, 2023
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
20 changes: 18 additions & 2 deletions src/lexer/Lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,23 @@ export class Lexer {
addToken(Lexeme.Semicolon);
break;
case "?":
addToken(Lexeme.Print);
switch (peek()) {
case ".":
advance();
addToken(Lexeme.Dot);
break;
case "(":
advance();
addToken(Lexeme.LeftParen);
break;
case "[":
advance();
addToken(Lexeme.LeftBrace);
break;
default:
addToken(Lexeme.Print);
break;
}
break;
case "<":
switch (peek()) {
Expand Down Expand Up @@ -302,7 +318,7 @@ export class Lexer {
case " ":
case "\r":
case "\t":
// ignore whitespace; indentation isn't signficant in BrightScript
// ignore whitespace; indentation isn't significant in BrightScript
break;
case "\n":
// consecutive newlines aren't significant, because they're just blank lines
Expand Down
3 changes: 0 additions & 3 deletions src/parser/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,6 @@ export class Parser {
Lexeme.Newline,
Lexeme.Colon,
Lexeme.Eof,
Lexeme.Identifier,
...additionalterminators
);
}
Expand Down Expand Up @@ -1420,8 +1419,6 @@ export class Parser {
while (true) {
if (match(Lexeme.LeftParen)) {
expr = finishCall(expr);
} else if (match(Lexeme.Print)) {
// doing nothing as invalid check was before
} else if (match(Lexeme.LeftSquare)) {
indexedGet();
} else if (match(Lexeme.Dot)) {
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/Syntax.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ describe("end to end syntax", () => {
"foo is not < 2",
"foo is not < 2 and not > 2",
"#481 fixed",
"2",
"5",
]);
});

Expand Down
15 changes: 12 additions & 3 deletions test/e2e/resources/conditionals.brs
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,22 @@ sub main()
print "foo is not < 2 and not > 2"
end if

test_481()
test_issue_481()
test_issue_30()
end sub

' MWE from https://github.com/rokucommunity/brs/issues/481
sub test_481()
' MWE from https://github.com/sjbarag/brs/issues/481
sub test_issue_481()
nop = sub() : end sub

if false then nop(): print "#481 still repro's": return
print "#481 fixed"
end sub

' Test for https://github.com/rokucommunity/brs/issues/30
function test_issue_30()
testA = ["apple", 2, "banana", "orange", 5, "grape", "pear"]
for fruit = 0 to testA.count()-1
if type(testA[fruit]).inStr(0,"String") = -1 ? testA[fruit]
next
end function
6 changes: 2 additions & 4 deletions test/parser/expression/Indexing.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ describe("parser indexing", () => {
identifier("_"),
token(Lexeme.Equal, "="),
identifier("bar"),
token(Lexeme.Print, "?"),
token(Lexeme.Dot, "."),
token(Lexeme.Dot, "?."),
identifier("foo"),
EOF,
]);
Expand All @@ -48,8 +47,7 @@ describe("parser indexing", () => {
identifier("_"),
token(Lexeme.Equal, "="),
token(Lexeme.Invalid, "invalid", BrsInvalid.Instance),
token(Lexeme.Print, "?"),
token(Lexeme.Dot, "."),
token(Lexeme.Dot, "?."),
identifier("bar"),
EOF,
]);
Expand Down