Skip to content

Commit ca8583b

Browse files
committed
Corrected #5
Thanks to @consultingwerk
1 parent 9552445 commit ca8583b

2 files changed

Lines changed: 29 additions & 10 deletions

File tree

build.number

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
#Thu Jan 07 23:00:00 PDT 2016
2-
build.number=1130
1+
#Mon Mar 07 23:00:00 PDT 2016
2+
build.number=1131

src/main/java/com/joanju/proparse/Lexer.java

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class Lexer implements ProParserTokenTypes {
4545
private static final int EOF_CHAR = Preprocessor.EOF_CHAR;
4646

4747

48-
48+
4949

5050
//////////////// Lexical productions listed first, support functions follow.
5151

@@ -89,7 +89,7 @@ ProToken nextToken() throws IOException {
8989
textStartSource = prepro.getSourceNum();
9090
currText.setLength(1);
9191
currText.setCharAt(0, (char)currInt);
92-
92+
9393
if (gettingAmpIfDefArg) {
9494
getChar();
9595
gettingAmpIfDefArg = false;
@@ -122,6 +122,8 @@ ProToken nextToken() throws IOException {
122122
getChar();
123123
if (currChar=='*') {
124124
return comment();
125+
} else if (currChar == '/') {
126+
return singleComment();
125127
} else if (currChar=='(' || currIsSpace()) {
126128
// slash (division) can only be followed by whitespace or '('
127129
// ...that's what I found empirically, anyway. (jag 2003/05/09)
@@ -250,8 +252,8 @@ ProToken nextToken() throws IOException {
250252
}
251253
}
252254
}
253-
254-
255+
256+
255257
/** Get argument for &IF DEFINED(...).
256258
* The nextToken function is necessarily the main entry point. This is just
257259
* a wrapper around that.
@@ -260,19 +262,19 @@ ProToken getAmpIfDefArg() throws IOException {
260262
gettingAmpIfDefArg = true;
261263
return nextToken();
262264
}
263-
264-
265+
266+
265267
/** Get the text between the parens for &IF DEFINED(...).
266268
* The compiler seems to allow any number of tokens between the parens,
267269
* and like with an &Name reference, it allows embedded comments.
268270
* Here, I'm allowing for the embedded comments and just gathering all the text
269271
* up to the closing paren. Hopefully that will do it.
270-
*
272+
*
271273
* The compiler doesn't seem to ignore extra tokens. For example, &if defined(ab cd)
272274
* does not match a macro named "ab". It doesn't match "abcd" either, so all I can guess
273275
* is that they are combining the text of all the tokens between the parens.
274276
* I haven't found any macro name that matches &if defined(ab"cd").
275-
*
277+
*
276278
* The compiler works different here than it does for a typical ID token.
277279
* An ID token (like a procedure name) may contain arbitrary quotation marks.
278280
* Within an &if defined() function, the quotation marks must match.
@@ -377,6 +379,23 @@ else if (currInt==EOF_CHAR) {
377379
}
378380

379381

382+
ProToken singleComment() throws IOException {
383+
// Single line comments are treated just like regular comments,
384+
// everything till end of line is considered comment - no escape
385+
// character to look after
386+
387+
append(); // currChar=='/'
388+
389+
while (true) {
390+
getChar();
391+
unEscapedAppend();
392+
if (currChar == '\r' || currChar == '\n' || currInt == EOF_CHAR) {
393+
return makeToken(COMMENT);
394+
}
395+
}
396+
}
397+
398+
380399
ProToken quotedString() throws IOException {
381400
// Inside quoted strings (string constants) we preserve
382401
// the source code's original text - we don't discard

0 commit comments

Comments
 (0)