comments WIP
This commit is contained in:
1 parent
0b6732fa93
commit
6b3313b45e
1 file changed
+30
-2
@@ -22,6 +22,8 @@ public class Tokenizer implements Iterator<Tokenizer.Token>
|
|||||||
private int pos = 0;
|
private int pos = 0;
|
||||||
private int lineno = 0;
|
private int lineno = 0;
|
||||||
private int linepos = 0;
|
private int linepos = 0;
|
||||||
|
private boolean comments;
|
||||||
|
private boolean newLinesMarkers;
|
||||||
|
|
||||||
|
|
||||||
/** The original input expression. */
|
/** The original input expression. */
|
||||||
@@ -31,10 +33,12 @@ public class Tokenizer implements Iterator<Tokenizer.Token>
|
|||||||
|
|
||||||
private Expression expression;
|
private Expression expression;
|
||||||
|
|
||||||
Tokenizer(Expression expr, String input)
|
Tokenizer(Expression expr, String input, boolean allowComments, boolean allowNewLineMakers)
|
||||||
{
|
{
|
||||||
this.input = input;
|
this.input = input;
|
||||||
this.expression = expr;
|
this.expression = expr;
|
||||||
|
this.comments = allowComments;
|
||||||
|
this.newLinesMarkers = allowNewLineMakers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -214,6 +218,22 @@ public class Tokenizer implements Iterator<Tokenizer.Token>
|
|||||||
&& (pos < input.length()))
|
&& (pos < input.length()))
|
||||||
{
|
{
|
||||||
greedyMatch += ch;
|
greedyMatch += ch;
|
||||||
|
if (comments && "//".equals(greedyMatch))
|
||||||
|
{
|
||||||
|
|
||||||
|
while ( ch != '\n' && pos < input.length())
|
||||||
|
{
|
||||||
|
ch = input.charAt(pos++);
|
||||||
|
linepos++;
|
||||||
|
greedyMatch += ch;
|
||||||
|
|
||||||
|
}
|
||||||
|
if (ch=='\n')
|
||||||
|
{
|
||||||
|
lineno++;
|
||||||
|
linepos = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
pos++;
|
pos++;
|
||||||
linepos++;
|
linepos++;
|
||||||
if (Expression.none.isAnOperator(greedyMatch))
|
if (Expression.none.isAnOperator(greedyMatch))
|
||||||
@@ -222,6 +242,14 @@ public class Tokenizer implements Iterator<Tokenizer.Token>
|
|||||||
}
|
}
|
||||||
ch = pos == input.length() ? 0 : input.charAt(pos);
|
ch = pos == input.length() ? 0 : input.charAt(pos);
|
||||||
}
|
}
|
||||||
|
if (newLinesMarkers && "$".equals(greedyMatch))
|
||||||
|
{
|
||||||
|
lineno++;
|
||||||
|
linepos = 0;
|
||||||
|
token.type = Token.TokenType.MARKER;
|
||||||
|
token.append('$');
|
||||||
|
return token; // skipping previous token lookback
|
||||||
|
}
|
||||||
if (validOperatorSeenUntil != -1)
|
if (validOperatorSeenUntil != -1)
|
||||||
{
|
{
|
||||||
token.append(input.substring(initialPos, validOperatorSeenUntil));
|
token.append(input.substring(initialPos, validOperatorSeenUntil));
|
||||||
@@ -277,7 +305,7 @@ public class Tokenizer implements Iterator<Tokenizer.Token>
|
|||||||
enum TokenType
|
enum TokenType
|
||||||
{
|
{
|
||||||
VARIABLE, FUNCTION, LITERAL, OPERATOR, UNARY_OPERATOR,
|
VARIABLE, FUNCTION, LITERAL, OPERATOR, UNARY_OPERATOR,
|
||||||
OPEN_PAREN, COMMA, CLOSE_PAREN, HEX_LITERAL, STRINGPARAM
|
OPEN_PAREN, COMMA, CLOSE_PAREN, HEX_LITERAL, STRINGPARAM, MARKER
|
||||||
}
|
}
|
||||||
public String surface = "";
|
public String surface = "";
|
||||||
public TokenType type;
|
public TokenType type;
|
||||||
|
|||||||
Reference in new issue
Block a user