Created
April 17, 2021 13:17
-
-
Save vlsi/352d375325b0e60f6a25ae0e807695d4 to your computer and use it in GitHub Desktop.
SpringDataПостроительПарсер
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
// See https://pegjs.org/online | |
// Sample expressions: | |
// FindBy${Name} | |
// FindFirstBy${Name} | |
// FindBy${Name}And${OperationType}OrderBy${Name}And${OperationType}DescCount | |
Query "query" | |
= s:Start t:Transform* f:Finalizer? | |
{ return {start: s, transforms: t, finalizer: f} } | |
Start "start" | |
= FindBy | |
Transform "transform" | |
= OrderBy | |
Finalizer "finalizer" | |
= 'Count' { return {op: 'COUNT'} } | |
FindBy "findBy" | |
= 'Find' finder:('First' / 'All')? 'By' e: Expression | |
{ return {op: 'FIND', finder: finder, expression: e} } | |
Expression "expr" | |
= head:SimpleExpr tail:('And' e: SimpleExpr { return e })* | |
{ return {type: 'AND', args: [head, ...tail]} } | |
SimpleExpr "simpleExpr" | |
= field:FieldName operation:('Contains' / 'StartsWith' / 'Between')? | |
{ return {type: 'field', fieldName: field, operation: operation} } | |
FieldName "fieldName" | |
= '${' name:([^}]+ { return text() }) '}' { return name } | |
OrderBy "orderBy" | |
= 'OrderBy' head:FieldCollation | |
tail:('And' field: FieldCollation { return field })* { | |
return {op: 'orderBy', columns: [head, ...tail]} | |
} | |
FieldCollation "fieldCollation" | |
= field:FieldName dir:SortDir? { return {field: field, dir: dir} } | |
SortDir "sortDir" | |
= 'Asc' / 'Desc' |
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
// FindBy${Name}And${OperationType}OrderBy${Name}And${OperationType}DescCount | |
{ | |
"start": { | |
"op": "FIND", | |
"finder": null, | |
"expression": { | |
"type": "AND", | |
"args": [ | |
{ | |
"type": "field", | |
"fieldName": "Name", | |
"operation": null | |
}, | |
{ | |
"type": "field", | |
"fieldName": "OperationType", | |
"operation": null | |
} | |
] | |
} | |
}, | |
"transforms": [ | |
{ | |
"op": "orderBy", | |
"columns": [ | |
{ | |
"field": "Name", | |
"dir": null | |
}, | |
{ | |
"field": "OperationType", | |
"dir": "Desc" | |
} | |
] | |
} | |
], | |
"finalizer": { | |
"op": "COUNT" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment