Skip to content

Commit

Permalink
Allow comments as their own lines in AA literals. (#29)
Browse files Browse the repository at this point in the history
Fixes #28
  • Loading branch information
TwitchBronBron authored Oct 2, 2019
1 parent dc59af1 commit d9da90b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/Program.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ describe('Program', () => {

it('normalizes file paths', async () => {
let filePath = `${rootDir}/source\\main.brs`;
console.log('filePath', filePath);
await program.addOrReplaceFile(filePath, '');

expect(program.contexts.global.getFile(filePath)).to.exist;
Expand Down
3 changes: 2 additions & 1 deletion src/files/BrsFile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1386,7 +1386,7 @@ describe('BrsFile', () => {
`);
});

it('works for a complex function with comments at the end of each line', async () => {
it('works for a complex function with comments all over the place', async () => {
await testTranspile(`
'import some library
library "v30/bslCore.brs" 'comment
Expand All @@ -1396,6 +1396,7 @@ describe('BrsFile', () => {
person = { 'comment
name: "parent", 'comment
"age": 12,
'comment as whole line
child: { 'comment
name: "child" 'comment
}
Expand Down
11 changes: 11 additions & 0 deletions src/parser/parser/Parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ describe('parser', () => {
expect((statements as any)[2].text).to.equal('comment 2');
});

it('works in aa literal as its own statement', () => {
let { tokens } = Lexer.scan(`
obj = {
"name": true,
'comment
}
`);
let { errors, statements } = parser.parse(tokens);
expect(errors).to.be.lengthOf(0, 'Error count should be 0');
});

it('parses after function call', () => {
let { tokens } = Lexer.scan(`
sub Main()
Expand Down
7 changes: 7 additions & 0 deletions src/parser/parser/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1749,11 +1749,18 @@ export class Parser {
}

while (match(Lexeme.Comma, Lexeme.Newline, Lexeme.Colon, Lexeme.Comment)) {
//check for comment at the end of the current line
if (check(Lexeme.Comment) || checkPrevious(Lexeme.Comment)) {
let token = checkPrevious(Lexeme.Comment) ? previous() : advance();
members.push(new Stmt.CommentStatement([token]));
} else {
while (match(Lexeme.Newline, Lexeme.Colon));
//check for a comment on its own line
if (check(Lexeme.Comment) || checkPrevious(Lexeme.Comment)) {
let token = checkPrevious(Lexeme.Comment) ? previous() : advance();
members.push(new Stmt.CommentStatement([token]));
continue;
}

if (check(Lexeme.RightBrace)) {
break;
Expand Down

0 comments on commit d9da90b

Please sign in to comment.