From 32df9c00eee5a4edaed291f29fde9460ae8c9e5f Mon Sep 17 00:00:00 2001 From: Sergey Igushkin Date: Tue, 20 Feb 2018 21:09:26 +0300 Subject: [PATCH] Update literals in the grammar reference Add missing long literal suffix Add binary integer literals Introduce IntegerLiteral lexer rule, which is closer to the actual lexer Issue #KT-22713 Fixed --- .../parsing/KotlinExpressionParsing.java | 1 - grammar/src/expressions.grm | 1 - grammar/src/lexical.grm | 26 ++++++++++++++++--- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/parsing/KotlinExpressionParsing.java b/compiler/frontend/src/org/jetbrains/kotlin/parsing/KotlinExpressionParsing.java index 4d969f888b9..d9f1af4fb2d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/parsing/KotlinExpressionParsing.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/parsing/KotlinExpressionParsing.java @@ -803,7 +803,6 @@ public class KotlinExpressionParsing extends AbstractKotlinParsing { * : stringTemplate * : NoEscapeString * : IntegerLiteral - * : LongLiteral * : CharacterLiteral * : FloatLiteral * : "null" diff --git a/grammar/src/expressions.grm b/grammar/src/expressions.grm index 64e454c011f..d49c0f22111 100644 --- a/grammar/src/expressions.grm +++ b/grammar/src/expressions.grm @@ -137,7 +137,6 @@ literalConstant : stringTemplate : NoEscapeString : IntegerLiteral - : HexadecimalLiteral : CharacterLiteral : FloatLiteral : "null" diff --git a/grammar/src/lexical.grm b/grammar/src/lexical.grm index 4201a053694..b0fe25823cd 100644 --- a/grammar/src/lexical.grm +++ b/grammar/src/lexical.grm @@ -2,12 +2,23 @@ # Lexical structure */ +[helper] +LongSuffix + : "L" + ; + +IntegerLiteral + : DecimalLiteral LongSuffix? + : HexadecimalLiteral LongSuffix? + : BinaryLiteral LongSuffix? + ; + [helper] Digit : ["0".."9"] ; -IntegerLiteral +DecimalLiteral : Digit : Digit (Digit | "_")* Digit ; @@ -22,10 +33,19 @@ HexDigit ; HexadecimalLiteral - : "0x" HexDigit - : "0x" HexDigit (HexDigit | "_")* HexDigit + : "0" ("x" | "X") HexDigit + : "0" ("x" | "X") HexDigit (HexDigit | "_")* HexDigit ; +[helper] +BinaryDigit + : ("0" | "1") + ; + +BinaryLiteral + : "0" ("b" | "B") BinaryDigit + : "0" ("b" | "B") BinaryDigit (BinaryDigit | "_")* BinaryDigit + CharacterLiteral : ;