-
Notifications
You must be signed in to change notification settings - Fork 218
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
[JLINE-730] Support for comments in DefaultParser #731
Conversation
There are some minor things I would like to be fixed before merge.
|
Hi @mattirn Besides that I also noticed a failing test case like |
@@ -333,6 +407,17 @@ public boolean isDelimiter(final CharSequence buffer, final int pos) { | |||
return !isQuoted(buffer, pos) && !isEscaped(buffer, pos) && isDelimiterChar(buffer, pos); | |||
} | |||
|
|||
private int handleDelimiterAndGetRawWordLength(StringBuilder current, List<String> words, int rawWordStart, int rawWordCursor, int rawWordLength, int pos) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I extracted this into a method as now this code block is used in 2 places.
In case you have a better method name suggestion I would consider that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
BlockCommentDelims
constructor should throwInvalidArgumentException
if either ofstart
orend
argument isnull
/empty or if they are equal:
throw new InvalidArgumentException("Bad block comment delimiter!")
-
I would rename also private field
lineComments
aslineCommentDelims
.
private String[] lineComments = null; -
On missing block comment delimiter the error message should be "Missing closing block comment delimiter"
throw new EOFError(-1, -1, "Missing closing block comment",
Please, could you squash the commits in a single commit when finished.
Thanks.
ok, thanks, done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
IllegalArgumentException
should thrown also whenstart.isEmpty() || end.isEmpty()
if (start == null || end == null || start.equals(end)) { -
same test executed twice
parser.setBlockCommentDelims(new DefaultParser.BlockCommentDelims("/*", null));
and
parser.setBlockCommentDelims(new DefaultParser.BlockCommentDelims("/*", null));
Sorry, had to check it before pushing... |
NP. I will do some more testing next week.... I let you know if I find something. |
Probably also need to check that block start and end differ from one line comments and from brackets and quotes |
Partially true... brackets can be used as block comment delimiters if they do not have any other use in CLI. I would not add any other validity checks for comment delimiters. IMHO checks would just make the code more complicate to follow without bringing much more value for implementation. Anyway I guess that the 'standard' comment delimiters (like //, #, /*, */, ...) will be mostly adopted in Jline CLIs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should throw EOFError
also for missing opening block comment:
if (startBlockCommentMissing) {
throw new EOFError(-1, -1, "Missing opening block comment delimiter",
"missing: " + blockCommentStart);
}
Please, change also the line
throw new EOFError(-1, -1, "Missing closing block comment delimiter", |
to
throw new EOFError(-1, -1, "Missing closing block comment delimiter",
"add: " + blockCommentEnd);
The PR makes it possible to set multiline comment start and end.
Also it allows to specify several one-line comments as several engines support several one-line comments
fixes #730