-
-
Save avuserow/3e02faf868f743de03ef to your computer and use it in GitHub Desktop.
Perl 6 SQL grammar for mysqldump files
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
grammar SQL { | |
token TOP { | |
^ <statement>? <comment>? $ | |
} | |
rule statement { | |
[ | |
| <insert-statement> | |
| <drop-statement> | |
| <create-statement> | |
| <lock-statement> | |
| <unlock-statement> | |
] \; | |
} | |
rule drop-statement { | |
DROP TABLE [IF EXISTS]? <table> | |
} | |
rule create-statement { | |
CREATE TABLE <table> <-[;]>+ | |
} | |
rule lock-statement { | |
LOCK TABLES <table> WRITE | |
} | |
rule unlock-statement { | |
UNLOCK TABLES | |
} | |
rule insert-statement { | |
INSERT INTO <table> VALUES [\( <value>+ % ',' \)]+ % ',' | |
} | |
rule value { | |
| \-?\d+[\.\d+]? | |
| NULL | |
| <simple-string> | |
| <string-with-escapes> | |
} | |
rule simple-string { | |
\'<-[\']>*\' | |
} | |
rule string-with-escapes { | |
\'[\\\\|\\\'|<-[\']>]*\' | |
} | |
rule table { | |
| <identifier> | |
| \`<identifier>\` | |
} | |
rule identifier { | |
\w+ | |
} | |
rule comment { | |
| <block-comment> | |
| <line-comment> | |
} | |
rule block-comment { | |
'/*' .+ '*/;' | |
} | |
rule line-comment { | |
'--' .* $ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment