-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: basic Redis grammar, parseRedisQueryWithoutCursor function, tests #207
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3fd0a09
feat: create basic Redis grammar
roberthovsepyan 1626eee
feat: add redis to build
roberthovsepyan 57e58cc
feat: generate Redis parsers
roberthovsepyan 7794dc7
feat: add parseRedisQueryWithoutCursor function
roberthovsepyan 985ae5e
feat: redis grammar tests
roberthovsepyan e468280
fix: redis newline token in lexer
roberthovsepyan f5b9d76
fix: newline in redis parser
roberthovsepyan fc32412
fix: grammar and test fixes
roberthovsepyan 01cf6e8
fix: eslint warning
roberthovsepyan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is |
||
; | ||
|
||
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 | ||
; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure we should call it
command
, and notstatement
?Statements
is a common name afaikThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's the way they call it everywhere in regards to Redis (including official docs), so I thought we better stick to conventional naming
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one!