"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/antlr/GroovyLexer.g4" between
apache-groovy-src-3.0.8.zip and apache-groovy-src-3.0.9.zip

About: Groovy is an agile dynamic (scripting) language for the Java Platform. It has features similar to those of Python, Ruby, Perl, and Smalltalk. Source release.

GroovyLexer.g4  (apache-groovy-src-3.0.8):GroovyLexer.g4  (apache-groovy-src-3.0.9)
skipping to change at line 59 skipping to change at line 59
import java.util.stream.IntStream; import java.util.stream.IntStream;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.EmptyStackException; import java.util.EmptyStackException;
import org.apache.groovy.util.Maps; import org.apache.groovy.util.Maps;
import static org.apache.groovy.parser.antlr4.SemanticPredicates.*; import static org.apache.groovy.parser.antlr4.SemanticPredicates.*;
} }
@members { @members {
private static final Logger LOGGER = Logger.getLogger(GroovyLexer.class.getN ame()); private static final Logger LOGGER = Logger.getLogger(GroovyLexer.class.getN ame());
private long tokenIndex = 0;
private int lastTokenType = 0; private boolean errorIgnored;
private int invalidDigitCount = 0; private long tokenIndex;
private int lastTokenType;
private int invalidDigitCount;
/** /**
* Record the index and token type of the current token while emitting token s. * Record the index and token type of the current token while emitting token s.
*/ */
@Override @Override
public void emit(Token token) { public void emit(Token token) {
this.tokenIndex++; this.tokenIndex++;
int tokenType = token.getType(); int tokenType = token.getType();
if (Token.DEFAULT_CHANNEL == token.getChannel()) { if (Token.DEFAULT_CHANNEL == token.getChannel()) {
this.lastTokenType = tokenType; this.lastTokenType = tokenType;
} }
if (RollBackOne == tokenType) { if (RollBackOne == tokenType) {
this.rollbackOneChar(); this.rollbackOneChar();
} }
super.emit(token); super.emit(token);
} }
private static final int[] REGEX_CHECK_ARRAY = private static final int[] REGEX_CHECK_ARRAY = {
IntStream.of( DEC,
Identifier, CapitalizedIdentifier, NullL INC,
iteral, BooleanLiteral, THIS, RPAREN, RBRACK, RBRACE, THIS,
IntegerLiteral, FloatingPointLiteral, St RBRACE,
ringLiteral, GStringEnd, INC, DEC RBRACK,
).sorted().toArray(); RPAREN,
GStringEnd,
NullLiteral,
StringLiteral,
BooleanLiteral,
IntegerLiteral,
FloatingPointLiteral,
Identifier, CapitalizedIdentifier
};
static {
Arrays.sort(REGEX_CHECK_ARRAY);
}
private boolean isRegexAllowed() { private boolean isRegexAllowed() {
if (Arrays.binarySearch(REGEX_CHECK_ARRAY, this.lastTokenType) >= 0) { return (Arrays.binarySearch(REGEX_CHECK_ARRAY, this.lastTokenType) < 0);
return false;
}
return true;
} }
/** /**
* just a hook, which will be overrided by GroovyLangLexer * just a hook, which will be overrided by GroovyLangLexer
*/ */
protected void rollbackOneChar() {} protected void rollbackOneChar() {}
private static class Paren { private static class Paren {
private String text; private String text;
private int lastTokenType; private int lastTokenType;
skipping to change at line 230 skipping to change at line 241
return Integer.MIN_VALUE; return Integer.MIN_VALUE;
} }
private static boolean isJavaIdentifierStartAndNotIdentifierIgnorable(int co dePoint) { private static boolean isJavaIdentifierStartAndNotIdentifierIgnorable(int co dePoint) {
return Character.isJavaIdentifierStart(codePoint) && !Character.isIdenti fierIgnorable(codePoint); return Character.isJavaIdentifierStart(codePoint) && !Character.isIdenti fierIgnorable(codePoint);
} }
private static boolean isJavaIdentifierPartAndNotIdentifierIgnorable(int cod ePoint) { private static boolean isJavaIdentifierPartAndNotIdentifierIgnorable(int cod ePoint) {
return Character.isJavaIdentifierPart(codePoint) && !Character.isIdentif ierIgnorable(codePoint); return Character.isJavaIdentifierPart(codePoint) && !Character.isIdentif ierIgnorable(codePoint);
} }
public boolean isErrorIgnored() {
return errorIgnored;
}
public void setErrorIgnored(boolean errorIgnored) {
this.errorIgnored = errorIgnored;
}
} }
// §3.10.5 String Literals // §3.10.5 String Literals
StringLiteral StringLiteral
: GStringQuotationMark DqStringCharacter* GStringQuotationMark : GStringQuotationMark DqStringCharacter* GStringQuotationMark
| SqStringQuotationMark SqStringCharacter* SqStringQuotationMark | SqStringQuotationMark SqStringCharacter* SqStringQuotationMark
| Slash { this.isRegexAllowed() && _input.LA(1) != '*' }? SlashyStringCha
| Slash { this.isRegexAllowed() && _input.LA(1) != '*' }? racter+ Slash
SlashyStringCharacter+ Slash
| TdqStringQuotationMark TdqStringCharacter* TdqStringQuotationMark
| TdqStringQuotationMark TdqStringCharacter* TdqStringQuotationMark | TsqStringQuotationMark TsqStringCharacter* TsqStringQuotationMark
| TsqStringQuotationMark TsqStringCharacter* TsqStringQuotationMark | DollarSlashyGStringQuotationMarkBegin DollarSlashyStringCharacter+ Dol
| DollarSlashyGStringQuotationMarkBegin DollarSlashyStringCharacter+ D larSlashyGStringQuotationMarkEnd
ollarSlashyGStringQuotationMarkEnd
; ;
// Groovy gstring
GStringBegin GStringBegin
: GStringQuotationMark DqStringCharacter* Dollar -> pushMode(DQ_GSTRING_MO DE), pushMode(GSTRING_TYPE_SELECTOR_MODE) : GStringQuotationMark DqStringCharacter* Dollar -> pushMode(DQ_GSTRING_MO DE), pushMode(GSTRING_TYPE_SELECTOR_MODE)
; ;
TdqGStringBegin TdqGStringBegin
: TdqStringQuotationMark TdqStringCharacter* Dollar -> type(GStringBegin ), pushMode(TDQ_GSTRING_MODE), pushMode(GSTRING_TYPE_SELECTOR_MODE) : TdqStringQuotationMark TdqStringCharacter* Dollar -> type(GStringBegin ), pushMode(TDQ_GSTRING_MODE), pushMode(GSTRING_TYPE_SELECTOR_MODE)
; ;
SlashyGStringBegin SlashyGStringBegin
: Slash { this.isRegexAllowed() && _input.LA(1) != '*' }? SlashyStringChar acter* Dollar { isFollowedByJavaLetterInGString(_input) }? -> type(GStringBegin) , pushMode(SLASHY_GSTRING_MODE), pushMode(GSTRING_TYPE_SELECTOR_MODE) : Slash { this.isRegexAllowed() && _input.LA(1) != '*' }? SlashyStringChar acter* Dollar { isFollowedByJavaLetterInGString(_input) }? -> type(GStringBegin) , pushMode(SLASHY_GSTRING_MODE), pushMode(GSTRING_TYPE_SELECTOR_MODE)
; ;
DollarSlashyGStringBegin DollarSlashyGStringBegin
skipping to change at line 475 skipping to change at line 491
VOLATILE : 'volatile'; VOLATILE : 'volatile';
WHILE : 'while'; WHILE : 'while';
// §3.10.1 Integer Literals // §3.10.1 Integer Literals
IntegerLiteral IntegerLiteral
: ( DecimalIntegerLiteral : ( DecimalIntegerLiteral
| HexIntegerLiteral | HexIntegerLiteral
| OctalIntegerLiteral | OctalIntegerLiteral
| BinaryIntegerLiteral | BinaryIntegerLiteral
) (Underscore { require(false, "Number ending with underscores is invali d", -1, true); })? ) (Underscore { require(errorIgnored, "Number ending with underscores is invalid", -1, true); })?
// !!! Error Alternative !!! // !!! Error Alternative !!!
| Zero ([0-9] { invalidDigitCount++; })+ { require(false, "Invalid octal n umber", -(invalidDigitCount + 1), true); } IntegerTypeSuffix? | Zero ([0-9] { invalidDigitCount++; })+ { require(errorIgnored, "Invalid octal number", -(invalidDigitCount + 1), true); } IntegerTypeSuffix?
; ;
fragment fragment
Zero Zero
: '0' : '0'
; ;
fragment fragment
DecimalIntegerLiteral DecimalIntegerLiteral
: DecimalNumeral IntegerTypeSuffix? : DecimalNumeral IntegerTypeSuffix?
skipping to change at line 617 skipping to change at line 633
BinaryDigitOrUnderscore BinaryDigitOrUnderscore
: BinaryDigit : BinaryDigit
| Underscore | Underscore
; ;
// §3.10.2 Floating-Point Literals // §3.10.2 Floating-Point Literals
FloatingPointLiteral FloatingPointLiteral
: ( DecimalFloatingPointLiteral : ( DecimalFloatingPointLiteral
| HexadecimalFloatingPointLiteral | HexadecimalFloatingPointLiteral
) (Underscore { require(false, "Number ending with underscores is invali d", -1, true); })? ) (Underscore { require(errorIgnored, "Number ending with underscores is invalid", -1, true); })?
; ;
fragment fragment
DecimalFloatingPointLiteral DecimalFloatingPointLiteral
: Digits Dot Digits ExponentPart? FloatTypeSuffix? : Digits? Dot Digits ExponentPart? FloatTypeSuffix?
| Digits ExponentPart FloatTypeSuffix? | Digits ExponentPart FloatTypeSuffix?
| Digits FloatTypeSuffix | Digits FloatTypeSuffix
; ;
fragment fragment
ExponentPart ExponentPart
: ExponentIndicator SignedInteger : ExponentIndicator SignedInteger
; ;
fragment fragment
skipping to change at line 953 skipping to change at line 969
; ;
// Single-line comments // Single-line comments
SL_COMMENT SL_COMMENT
: '//' ~[\r\n\uFFFF]* { this.ignoreTokenInsideParens(); } -> t ype(NL) : '//' ~[\r\n\uFFFF]* { this.ignoreTokenInsideParens(); } -> t ype(NL)
; ;
// Script-header comments. // Script-header comments.
// The very first characters of the file may be "#!". If so, ignore the first l ine. // The very first characters of the file may be "#!". If so, ignore the first l ine.
SH_COMMENT SH_COMMENT
: '#!' { require(0 == this.tokenIndex, "Shebang comment should appear at t he first line", -2, true); } ShCommand (LineTerminator '#!' ShCommand)* -> skip : '#!' { require(errorIgnored || 0 == this.tokenIndex, "Shebang comment sh ould appear at the first line", -2, true); } ShCommand (LineTerminator '#!' ShCo mmand)* -> skip
; ;
// Unexpected characters will be handled by groovy parser later. // Unexpected characters will be handled by groovy parser later.
UNEXPECTED_CHAR UNEXPECTED_CHAR
: . : . { require(errorIgnored, "Unexpected character: '" + getText().replace( "'", "\\'") + "'", -1, false); }
; ;
 End of changes. 12 change blocks. 
32 lines changed or deleted 47 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)