-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3376a88
commit 3fd0a09
Showing
2 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// $antlr-format alignTrailingComments true, columnLimit 500, maxEmptyLinesToKeep 1, reflowComments false, useTab false | ||
// $antlr-format allowShortRulesOnASingleLine true, allowShortBlocksOnASingleLine true, minEmptyLines 0, alignSemicolons ownLine | ||
// $antlr-format alignColons trailing, singleLineOverrulesHangingColon true, alignLexerCommands true, alignLabels true, alignTrailers true | ||
|
||
lexer grammar RedisLexer; | ||
|
||
options { | ||
caseInsensitive = true; | ||
} | ||
|
||
// Spaces | ||
|
||
SPACE : [ \t]+ -> channel (HIDDEN); | ||
NEWLINE : ('\r' '\n'? | '\n') -> channel (HIDDEN); | ||
|
||
// Keywords | ||
|
||
SET : 'SET'; | ||
GET : 'GET'; | ||
INCR : 'INCR'; | ||
DECR : 'DECR'; | ||
NX : 'NX'; | ||
XX : 'XX'; | ||
EX : 'EX'; | ||
PX : 'PX'; | ||
EXAT : 'EXAT'; | ||
PXAT : 'PXAT'; | ||
KEEPTTL : 'KEEPTTL'; | ||
|
||
// Constructors symbols | ||
|
||
SINGLE_QUOTE : '\''; | ||
DOUBLE_QUOTE : '"'; | ||
|
||
// Literal Primitives | ||
|
||
fragment DECIMAL_DIGIT: [0-9]; | ||
|
||
DECIMAL_LITERAL: DECIMAL_DIGIT+; | ||
|
||
// Identifiers | ||
// Should be at the very bottom, for it is the most general token | ||
|
||
fragment DOUBLE_QUOTE_STRING : '"' ( '\\' . | ~('"' | '\\' | '\n' | '\r'))* '"'; | ||
fragment SINGLE_QUOTE_STRING : '\'' ('\\' . | ~('\'' | '\\' | '\n' | '\r'))* '\''; | ||
fragment BASE_IDENTIFIER : ~(' ' | '\t' | '\'' | '"' | '\n' | '\r')+; | ||
|
||
IDENTIFIER: BASE_IDENTIFIER | DOUBLE_QUOTE_STRING | SINGLE_QUOTE_STRING; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// $antlr-format columnLimit 500, minEmptyLines 1, maxEmptyLinesToKeep 1, useTab false, reflowComments false, breakBeforeBraces false | ||
// $antlr-format keepEmptyLinesAtTheStartOfBlocks false, allowShortRulesOnASingleLine false, alignSemicolons hanging, alignColons hanging | ||
// $antlr-format alignTrailingComments true | ||
|
||
parser grammar RedisParser; | ||
|
||
options { | ||
tokenVocab = RedisLexer; | ||
} | ||
|
||
root | ||
: commands? EOF | ||
; | ||
|
||
// We can omit newline only if it's the last statement | ||
commands | ||
: command NEWLINE? | ||
| command NEWLINE commands | ||
; | ||
|
||
command | ||
: setCommand | ||
| getCommand | ||
| incrementCommand | ||
| decrementCommand | ||
; | ||
|
||
setCommand | ||
: SET keyName identifier (NX | XX)? GET? expirationClause? | ||
; | ||
|
||
expirationClause | ||
: EX DECIMAL_LITERAL | ||
| PX DECIMAL_LITERAL | ||
| EXAT DECIMAL_LITERAL | ||
| PXAT DECIMAL_LITERAL | ||
| KEEPTTL | ||
; | ||
|
||
getCommand | ||
: GET keyName | ||
; | ||
|
||
incrementCommand | ||
: INCR keyName | ||
; | ||
|
||
decrementCommand | ||
: DECR keyName | ||
; | ||
|
||
identifier | ||
: IDENTIFIER | ||
| DECIMAL_LITERAL | ||
; | ||
|
||
keyName | ||
: identifier | ||
; |