Skip to content

Commit

Permalink
Merge pull request beanshell#754 from beanshell/fix_753
Browse files Browse the repository at this point in the history
Fix parser errors handling multi-line comments beanshell#753
  • Loading branch information
nickl- authored Jan 3, 2024
2 parents b35aac4 + ddf0a0e commit 2ffb804
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/jjtree/bsh.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ SPECIAL_TOKEN : /* COMMENTS */
/* Moved FORMAL_COMMENT to a real token. Modified MULTI_LINE_COMMENT to not
catch formal comments (require no star after star) */
| <MULTI_LINE_COMMENT:
("/***" (["*"])* | "/*") (~["*"])* "*" ("*" | (~["*","/"] (~["*"])* "*"))* "/">
("/***" (["*"])* | "/*" ~["*"]) (~["*"])* "*" ("*" | (~["*","/"] (~["*"])* "*"))* "/">
}

TOKEN : /* RESERVED WORDS AND LITERALS */
Expand Down
36 changes: 36 additions & 0 deletions src/test/resources/test-scripts/parserissues2.bsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/java bsh.Interpreter

source("TestHarness.bsh");
source("Assert.bsh");

import bsh.*;

/**
* test that formal comments are picked up as nodes, and other types of comments are skipped
*/

/*
* This comment should be skipped
*/

/**********************************
* This comment should be skipped
**********************************/

// This comment should be skipped

parser = new Parser(new FileReader(bsh.cwd+"/"+getSourceFileInfo()));
parser.setRetainComments(true);

assertFalse("parse line 1", parser.Line());
assertEquals("node 1 class", BSHAssignment.class, parser.popNode().getClass());
assertFalse("parse line 2", parser.Line());
assertEquals("node 2 class", BSHAssignment.class, parser.popNode().getClass());
assertFalse("parse line 3", parser.Line());
assertEquals("node 3 class", BSHImportDeclaration.class, parser.popNode().getClass());
assertFalse("parse line 4", parser.Line());
assertEquals("node 4 class", BSHFormalComment.class, parser.popNode().getClass());
assertFalse("parse line 5", parser.Line());
assertEquals("node 5 class", BSHAssignment.class, parser.popNode().getClass());

complete();

0 comments on commit 2ffb804

Please sign in to comment.