Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@avuserow

avuserow/SQL.pm6 Secret

Created March 9, 2015 05:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avuserow/3e02faf868f743de03ef to your computer and use it in GitHub Desktop.
Save avuserow/3e02faf868f743de03ef to your computer and use it in GitHub Desktop.
Perl 6 SQL grammar for mysqldump files
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