@dbml/core
Version:
> TODO: description
34 lines • 252 kB
JavaScript
/*
* Generated by PEG.js 0.10.0.
*
* http://pegjs.org/
*/"use strict";function _typeof(obj){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj;}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;},_typeof(obj);}function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);enumerableOnly&&(symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable;})),keys.push.apply(keys,symbols);}return keys;}function _objectSpread(target){for(var i=1;i<arguments.length;i++){var source=null!=arguments[i]?arguments[i]:{};i%2?ownKeys(Object(source),!0).forEach(function(key){_defineProperty(target,key,source[key]);}):Object.getOwnPropertyDescriptors?Object.defineProperties(target,Object.getOwnPropertyDescriptors(source)):ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key));});}return target;}function _defineProperty(obj,key,value){key=_toPropertyKey(key);if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}function _toPropertyKey(arg){var key=_toPrimitive(arg,"string");return _typeof(key)==="symbol"?key:String(key);}function _toPrimitive(input,hint){if(_typeof(input)!=="object"||input===null)return input;var prim=input[Symbol.toPrimitive];if(prim!==undefined){var res=prim.call(input,hint||"default");if(_typeof(res)!=="object")return res;throw new TypeError("@@toPrimitive must return a primitive value.");}return(hint==="string"?String:Number)(input);}function _toConsumableArray(arr){return _arrayWithoutHoles(arr)||_iterableToArray(arr)||_unsupportedIterableToArray(arr)||_nonIterableSpread();}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}function _unsupportedIterableToArray(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen);}function _iterableToArray(iter){if(typeof Symbol!=="undefined"&&iter[Symbol.iterator]!=null||iter["@@iterator"]!=null)return Array.from(iter);}function _arrayWithoutHoles(arr){if(Array.isArray(arr))return _arrayLikeToArray(arr);}function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++)arr2[i]=arr[i];return arr2;}var _=require("lodash"),pluralize=require("pluralize");function peg$subclass(child,parent){function ctor(){this.constructor=child;}ctor.prototype=parent.prototype;child.prototype=new ctor();}function peg$SyntaxError(message,expected,found,location){this.message=message;this.expected=expected;this.found=found;this.location=location;this.name="SyntaxError";if(typeof Error.captureStackTrace==="function"){Error.captureStackTrace(this,peg$SyntaxError);}}peg$subclass(peg$SyntaxError,Error);peg$SyntaxError.buildMessage=function(expected,found){var DESCRIBE_EXPECTATION_FNS={literal:function literal(expectation){return"\""+literalEscape(expectation.text)+"\"";},"class":function _class(expectation){var escapedParts="",i;for(i=0;i<expectation.parts.length;i++){escapedParts+=expectation.parts[i]instanceof Array?classEscape(expectation.parts[i][0])+"-"+classEscape(expectation.parts[i][1]):classEscape(expectation.parts[i]);}return"["+(expectation.inverted?"^":"")+escapedParts+"]";},any:function any(expectation){return"any character";},end:function end(expectation){return"end of input";},other:function other(expectation){return expectation.description;}};function hex(ch){return ch.charCodeAt(0).toString(16).toUpperCase();}function literalEscape(s){return s.replace(/\\/g,'\\\\').replace(/"/g,'\\"').replace(/\0/g,'\\0').replace(/\t/g,'\\t').replace(/\n/g,'\\n').replace(/\r/g,'\\r').replace(/[\x00-\x0F]/g,function(ch){return'\\x0'+hex(ch);}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(ch){return'\\x'+hex(ch);});}function classEscape(s){return s.replace(/\\/g,'\\\\').replace(/\]/g,'\\]').replace(/\^/g,'\\^').replace(/-/g,'\\-').replace(/\0/g,'\\0').replace(/\t/g,'\\t').replace(/\n/g,'\\n').replace(/\r/g,'\\r').replace(/[\x00-\x0F]/g,function(ch){return'\\x0'+hex(ch);}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(ch){return'\\x'+hex(ch);});}function describeExpectation(expectation){return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation);}function describeExpected(expected){var descriptions=new Array(expected.length),i,j;for(i=0;i<expected.length;i++){descriptions[i]=describeExpectation(expected[i]);}descriptions.sort();if(descriptions.length>0){for(i=1,j=1;i<descriptions.length;i++){if(descriptions[i-1]!==descriptions[i]){descriptions[j]=descriptions[i];j++;}}descriptions.length=j;}switch(descriptions.length){case 1:return descriptions[0];case 2:return descriptions[0]+" or "+descriptions[1];default:return descriptions.slice(0,-1).join(", ")+", or "+descriptions[descriptions.length-1];}}function describeFound(found){return found?"\""+literalEscape(found)+"\"":"end of input";}return"Expected "+describeExpected(expected)+" but "+describeFound(found)+" found.";};function peg$parse(input,options){options=options!==void 0?options:{};var peg$FAILED={},peg$startRuleFunctions={parser:peg$parseparser},peg$startRuleFunction=peg$parseparser,peg$c0=function peg$c0(commands){commands.forEach(function(cmd){var command_name=cmd.command_name,_cmd$value=cmd.value,syntax_name=_cmd$value.syntax_name,value=_cmd$value.value,warning=cmd.warning;switch(command_name.toLowerCase()){case"create_table":var table=value;switch(syntax_name.toLowerCase()){case"create_table_normal":tables.push(table);var pkList=[];table.fields.forEach(function(field){// process inline_refs
if(field.inline_refs){refs.push.apply(refs,_toConsumableArray(field.inline_refs.map(function(ref){return{name:ref.name,endpoints:[{tableName:table.name,schemaName:table.schemaName,fieldNames:[field.name],relation:"*"},ref.endpoint],onDelete:ref.onDelete,onUpdate:ref.onUpdate};})));}// process composite primary key, if primary key is in composite form, push it into indexes
if(field.pk){pkList.push(field);}});if(pkList.length>1){table.fields=table.fields.map(function(field){delete field.pk;return field;});var index={columns:pkList.map(function(field){return{value:field.name,type:'column'};}),pk:true};if(table.indexes){table.indexes.push(index);}else{table.indexes=[index];}}break;case"create_table_of":break;case"create_table_partition_of":break;}break;case"create_index":var table_name=value.table_name;delete value.table_name;// remove table_name from column
var table_index=findTable(table_name.schemaName,table_name.name);if(table_index.indexes){table_index.indexes.push(value);}else{table_index.indexes=[value];}break;case"create_type":switch(syntax_name.toLowerCase()){case"create_type_enum":enums.push(value);break;case"create_type_range":break;}break;case"alter_table":switch(syntax_name.toLowerCase()){case"alter_table_action":value.forEach(function(v){var type=v.type;switch(type.toLowerCase()){case"fk":v.t_value.forEach(function(endpoints){refs.push(endpoints);});}});break;}break;case"comment":switch(syntax_name.toLowerCase()){case"column":{var schemaName=value.schemaName,tableName=value.tableName,columnName=value.columnName;var foundTable=findTable(schemaName,tableName);if(foundTable){var foundField=findField(foundTable,columnName);if(foundField)foundField.note=value.text?{value:value.text}:null;}break;}case"table":{var _value$table_name=value.table_name,_schemaName=_value$table_name.schemaName,_tableName=_value$table_name.name;var _foundTable=findTable(_schemaName,_tableName);if(_foundTable)_foundTable.note=value.text?{value:value.text}:null;break;}}break;case"ignore_syntax":// warnings.push(warning);
break;}});return{tables:tables,refs:refs,enums:enums};},peg$c1="create",peg$c2=peg$literalExpectation("CREATE",true),peg$c3="alter",peg$c4=peg$literalExpectation("ALTER",true),peg$c5="unique",peg$c6=peg$literalExpectation("UNIQUE",true),peg$c7="index",peg$c8=peg$literalExpectation("INDEX",true),peg$c9="type",peg$c10=peg$literalExpectation("TYPE",true),peg$c11="enum",peg$c12=peg$literalExpectation("ENUM",true),peg$c13="concurrenly",peg$c14=peg$literalExpectation("CONCURRENLY",true),peg$c15="foreign",peg$c16=peg$literalExpectation("FOREIGN",true),peg$c17="key",peg$c18=peg$literalExpectation("KEY",true),peg$c19="references",peg$c20=peg$literalExpectation("REFERENCES",true),peg$c21="on",peg$c22=peg$literalExpectation("ON",true),peg$c23="using",peg$c24=peg$literalExpectation("USING",true),peg$c25="table",peg$c26=peg$literalExpectation("TABLE",true),peg$c27="if",peg$c28=peg$literalExpectation("IF",true),peg$c29="not",peg$c30=peg$literalExpectation("NOT",true),peg$c31="exists",peg$c32=peg$literalExpectation("EXISTS",true),peg$c33="global",peg$c34=peg$literalExpectation("GLOBAL",true),peg$c35="local",peg$c36=peg$literalExpectation("LOCAL",true),peg$c37="temporary",peg$c38=peg$literalExpectation("TEMPORARY",true),peg$c39="temp",peg$c40=peg$literalExpectation("TEMP",true),peg$c41="unlogged",peg$c42=peg$literalExpectation("UNLOGGED",true),peg$c43="collate",peg$c44=peg$literalExpectation("COLLATE",true),peg$c45="collation",peg$c46=peg$literalExpectation("COLLATION",true),peg$c47="partition",peg$c48=peg$literalExpectation("PARTITION",true),peg$c49="by",peg$c50=peg$literalExpectation("BY",true),peg$c51="range",peg$c52=peg$literalExpectation("RANGE",true),peg$c53="list",peg$c54=peg$literalExpectation("LIST",true),peg$c55="hash",peg$c56=peg$literalExpectation("HASH",true),peg$c57="like",peg$c58=peg$literalExpectation("LIKE",true),peg$c59="inherits",peg$c60=peg$literalExpectation("INHERITS",true),peg$c61="inherit",peg$c62=peg$literalExpectation("INHERIT",true),peg$c63="with",peg$c64=peg$literalExpectation("WITH",true),peg$c65="without",peg$c66=peg$literalExpectation("WITHOUT",true),peg$c67="oids",peg$c68=peg$literalExpectation("OIDS",true),peg$c69="commit",peg$c70=peg$literalExpectation("COMMIT",true),peg$c71="preserve",peg$c72=peg$literalExpectation("PRESERVE",true),peg$c73="rows",peg$c74=peg$literalExpectation("ROWS",true),peg$c75="delete",peg$c76=peg$literalExpectation("DELETE",true),peg$c77="drop",peg$c78=peg$literalExpectation("DROP",true),peg$c79="tablespace",peg$c80=peg$literalExpectation("TABLESPACE",true),peg$c81="constraint",peg$c82=peg$literalExpectation("CONSTRAINT",true),peg$c83="no",peg$c84=peg$literalExpectation("NO",true),peg$c85="null",peg$c86=peg$literalExpectation("NULL",true),peg$c87="check",peg$c88=peg$literalExpectation("CHECK",true),peg$c89="default",peg$c90=peg$literalExpectation("DEFAULT",true),peg$c91="primary",peg$c92=peg$literalExpectation("PRIMARY",true),peg$c93="match",peg$c94=peg$literalExpectation("MATCH",true),peg$c95="full",peg$c96=peg$literalExpectation("FULL",true),peg$c97="partial",peg$c98=peg$literalExpectation("PARTIAL",true),peg$c99="simple",peg$c100=peg$literalExpectation("SIMPLE",true),peg$c101="update",peg$c102=peg$literalExpectation("UPDATE",true),peg$c103="deferrable",peg$c104=peg$literalExpectation("DEFERRABLE",true),peg$c105="initially",peg$c106=peg$literalExpectation("INITIALLY",true),peg$c107="deferred",peg$c108=peg$literalExpectation("DEFERRED",true),peg$c109="immediate",peg$c110=peg$literalExpectation("IMMEDIATE",true),peg$c111="exclude",peg$c112=peg$literalExpectation("EXCLUDE",true),peg$c113="where",peg$c114=peg$literalExpectation("WHERE",true),peg$c115="including",peg$c116=peg$literalExpectation("INCLUDING",true),peg$c117="excluding",peg$c118=peg$literalExpectation("EXCLUDING",true),peg$c119="comments",peg$c120=peg$literalExpectation("COMMENTS",true),peg$c121="constraints",peg$c122=peg$literalExpectation("CONSTRAINTS",true),peg$c123="generated",peg$c124=peg$literalExpectation("GENERATED",true),peg$c125="always",peg$c126=peg$literalExpectation("ALWAYS",true),peg$c127="as",peg$c128=peg$literalExpectation("AS",true),peg$c129="add",peg$c130=peg$literalExpectation("ADD",true),peg$c131="only",peg$c132=peg$literalExpectation("ONLY",true),peg$c133="defaults",peg$c134=peg$literalExpectation("DEFAULTS",true),peg$c135="identity",peg$c136=peg$literalExpectation("IDENTITY",true),peg$c137="indexes",peg$c138=peg$literalExpectation("INDEXES",true),peg$c139="statistics",peg$c140=peg$literalExpectation("STATISTICS",true),peg$c141="storage",peg$c142=peg$literalExpectation("STORAGE",true),peg$c143="include",peg$c144=peg$literalExpectation("INCLUDE",true),peg$c145="includes",peg$c146=peg$literalExpectation("INCLUDES",true),peg$c147="all",peg$c148=peg$literalExpectation("ALL",true),peg$c149="of",peg$c150=peg$literalExpectation("OF",true),peg$c151="options",peg$c152=peg$literalExpectation("OPTIONS",true),peg$c153="for",peg$c154=peg$literalExpectation("FOR",true),peg$c155="values",peg$c156=peg$literalExpectation("VALUES",true),peg$c157="in",peg$c158=peg$literalExpectation("IN",true),peg$c159="from",peg$c160=peg$literalExpectation("FROM",true),peg$c161="to",peg$c162=peg$literalExpectation("TO",true),peg$c163="modulus",peg$c164=peg$literalExpectation("MODULUS",true),peg$c165="remainder",peg$c166=peg$literalExpectation("REMAINDER",true),peg$c167="true",peg$c168=peg$literalExpectation("TRUE",true),peg$c169="false",peg$c170=peg$literalExpectation("FALSE",true),peg$c171="maxvalue",peg$c172=peg$literalExpectation("MAXVALUE",true),peg$c173="minvalue",peg$c174=peg$literalExpectation("MINVALUE",true),peg$c175="subtype",peg$c176=peg$literalExpectation("SUBTYPE",true),peg$c177="subtype_opclass",peg$c178=peg$literalExpectation("SUBTYPE_OPCLASS",true),peg$c179="canonical",peg$c180=peg$literalExpectation("CANONICAL",true),peg$c181="subtype_diff",peg$c182=peg$literalExpectation("SUBTYPE_DIFF",true),peg$c183="valid",peg$c184=peg$literalExpectation("VALID",true),peg$c185="column",peg$c186=peg$literalExpectation("COLUMN",true),peg$c187="set",peg$c188=peg$literalExpectation("SET",true),peg$c189="data",peg$c190=peg$literalExpectation("DATA",true),peg$c191="reset",peg$c192=peg$literalExpectation("RESET",true),peg$c193="plain",peg$c194=peg$literalExpectation("PLAIN",true),peg$c195="external",peg$c196=peg$literalExpectation("EXTERNAL",true),peg$c197="extended",peg$c198=peg$literalExpectation("EXTENDED",true),peg$c199="main",peg$c200=peg$literalExpectation("MAIN",true),peg$c201="asc",peg$c202=peg$literalExpectation("ASC",true),peg$c203="desc",peg$c204=peg$literalExpectation("DESC",true),peg$c205="nulls",peg$c206=peg$literalExpectation("NULLS",true),peg$c207="first",peg$c208=peg$literalExpectation("FIRST",true),peg$c209="last",peg$c210=peg$literalExpectation("LAST",true),peg$c211="comment",peg$c212=peg$literalExpectation("COMMENT",true),peg$c213="IS",peg$c214=peg$literalExpectation("IS",false),peg$c215="insert",peg$c216=peg$literalExpectation("INSERT",true),peg$c217="select",peg$c218=peg$literalExpectation("SELECT",true),peg$c219="use",peg$c220=peg$literalExpectation("USE",true),peg$c221="sequence",peg$c222=peg$literalExpectation("SEQUENCE",true),peg$c223="schema",peg$c224=peg$literalExpectation("SCHEMA",true),peg$c225="view",peg$c226=peg$literalExpectation("VIEW",true),peg$c227="rename",peg$c228=peg$literalExpectation("RENAME",true),peg$c229="owned",peg$c230=peg$literalExpectation("OWNED",true),peg$c231="attach",peg$c232=peg$literalExpectation("ATTACH",true),peg$c233="detach",peg$c234=peg$literalExpectation("DETACH",true),peg$c235=peg$otherExpectation("expression"),peg$c236=function peg$c236(factors){return removeReduntdantSpNewline(_.flattenDeep(factors).join(""));},peg$c237="(",peg$c238=peg$literalExpectation("(",false),peg$c239=")",peg$c240=peg$literalExpectation(")",false),peg$c241=",",peg$c242=peg$literalExpectation(",",false),peg$c243=");",peg$c244=peg$literalExpectation(");",false),peg$c245=peg$anyExpectation(),peg$c246=function peg$c246(factors){return _.flattenDeep(factors).join("");},peg$c247=/^["',.a-z0-9_+-:<>=!*]/i,peg$c248=peg$classExpectation(["\"","'",",",".",["a","z"],["0","9"],"_",["+",":"],"<",">","=","!","*"],false,true),peg$c249=/^['.a-z0-9_+\-]/i,peg$c250=peg$classExpectation(["'",".",["a","z"],["0","9"],"_","+","-"],false,true),peg$c251=peg$otherExpectation("valid column name"),peg$c252=".",peg$c253=peg$literalExpectation(".",false),peg$c254=function peg$c254(names){var dbName=null;var schemaName=null;if(names&&names.length>0){if(names.length===1)schemaName=names[0][0];else{dbName=names[0][0];schemaName=names[1][0];}}return{dbName:dbName,schemaName:schemaName};},peg$c255=peg$otherExpectation("valid table name"),peg$c256=function peg$c256(pathName,name){return _objectSpread(_objectSpread({},pathName),{},{name:name});},peg$c257=peg$otherExpectation("valid enum name"),peg$c258=peg$otherExpectation("string"),peg$c259="'",peg$c260=peg$literalExpectation("'",false),peg$c261=function peg$c261(c){return c.join('');},peg$c262="''",peg$c263=peg$literalExpectation("''",false),peg$c264=function peg$c264(){return"'";},peg$c265=/^[^']/,peg$c266=peg$classExpectation(["'"],true,false),peg$c267="\"",peg$c268=peg$literalExpectation("\"",false),peg$c269=function peg$c269(c){return c.join('');},peg$c270="\"\"",peg$c271=peg$literalExpectation("\"\"",false),peg$c272=function peg$c272(){return'"';},peg$c273=/^[^"]/,peg$c274=peg$classExpectation(["\""],true,false),peg$c275=peg$otherExpectation("number"),peg$c276="e",peg$c277=peg$literalExpectation("e",false),peg$c278="+",peg$c279=peg$literalExpectation("+",false),peg$c280="-",peg$c281=peg$literalExpectation("-",false),peg$c282=function peg$c282(a){return _.flattenDeep(a).filter(function(ele){return ele;}).join('');},peg$c283=function peg$c283(d){return d.join('');},peg$c284=/^[0-9]/,peg$c285=peg$classExpectation([["0","9"]],false,false),peg$c286=peg$otherExpectation("VALID TYPE"),peg$c287="character",peg$c288=peg$literalExpectation("CHARACTER",true),peg$c289="varying",peg$c290=peg$literalExpectation("VARYING",true),peg$c291=function peg$c291(c1,c2,args,dimensions){var c="".concat(c1," ").concat(c2);c=args?c+'('+args[1]+')':c;return{type_name:c+(dimensions?dimensions.map(function(dimension){return'['+dimension+']';}).join(''):''),args:args?args[1]:null};},peg$c292="timestamptz",peg$c293=peg$literalExpectation("timestamptz",true),peg$c294=function peg$c294(number,dimensions){var args=number?number[2]:null;return{type_name:(args!==null?"timestamptz(".concat(args,")"):"timestamptz")+(dimensions?dimensions.map(function(dimension){return'['+dimension+']';}).join(''):''),args:args};},peg$c295="timestamp",peg$c296=peg$literalExpectation("timestamp",true),peg$c297=peg$literalExpectation("without",true),peg$c298=peg$literalExpectation("with",true),peg$c299="time",peg$c300=peg$literalExpectation("time",true),peg$c301="zone",peg$c302=peg$literalExpectation("zone",true),peg$c303=function peg$c303(number,dimensions){var args=number?number[2]:null;return{type_name:(args!==null?"timestamp(".concat(args,")"):"timestamp")+(dimensions?dimensions.map(function(dimension){return'['+dimension+']';}).join(''):''),args:args};},peg$c304="timetz",peg$c305=peg$literalExpectation("timetz",true),peg$c306=function peg$c306(number,dimensions){var args=number?number[2]:null;return{type_name:(args!==null?"timetz(".concat(args,")"):"timetz")+(dimensions?dimensions.map(function(dimension){return'['+dimension+']';}).join(''):''),args:args};},peg$c307=function peg$c307(number,dimensions){var args=number?number[2]:null;return{type_name:(args!==null?"time(".concat(args,")"):"time")+(dimensions?dimensions.map(function(dimension){return'['+dimension+']';}).join(''):''),args:args};},peg$c308=function peg$c308(c,dimensions){var args=c.args;return{type_name:c.type_name+(dimensions?dimensions.map(function(dimension){return'['+dimension+']';}).join(''):''),schemaName:c.schemaName,args:args};},peg$c309=/^[^"\n]/,peg$c310=peg$classExpectation(["\"","\n"],true,false),peg$c311=function peg$c311(c){return{type_name:c.join(""),args:null};},peg$c312=function peg$c312(pathName,c,args){var type_name=c.join("");args=args?args[1]:null;if(type_name.toLowerCase()!=='enum'){type_name=args?type_name+'('+args+')':type_name;}return _objectSpread(_objectSpread({},pathName),{},{type_name:type_name,args:args});},peg$c313="array",peg$c314=peg$literalExpectation("array",true),peg$c315="[",peg$c316=peg$literalExpectation("[",false),peg$c317="]",peg$c318=peg$literalExpectation("]",false),peg$c319=function peg$c319(singledimenson){return[singledimenson?singledimenson[3]:''];},peg$c320=function peg$c320(multidimenson){// this will parse into Array(Array('[', _ , expression , _ ']'))
return multidimenson.map(function(dimension){return dimension[2];});},peg$c321=function peg$c321(val){return{value:val,type:'string'};},peg$c322=function peg$c322(val){return{value:val,type:'number'};},peg$c323=function peg$c323(val){return{value:val,type:'boolean'};},peg$c324=function peg$c324(val){var str=val;if(val&&val.length>2&&val[0]==='('&&val[val.length-1]===')'){str=val.slice(1,-1);}return{value:str,type:'expression'};},peg$c325=" ",peg$c326=peg$literalExpectation(" ",false),peg$c327="\t",peg$c328=peg$literalExpectation("\t",false),peg$c329=";",peg$c330=peg$literalExpectation(";",false),peg$c331=peg$otherExpectation("endline"),peg$c332=peg$otherExpectation("newline"),peg$c333="\r\n",peg$c334=peg$literalExpectation("\r\n",false),peg$c335="\n",peg$c336=peg$literalExpectation("\n",false),peg$c337=peg$otherExpectation("space"),peg$c338=peg$otherExpectation("comment"),peg$c339="--",peg$c340=peg$literalExpectation("--",false),peg$c341=/^[^\n]/,peg$c342=peg$classExpectation(["\n"],true,false),peg$c343="/*",peg$c344=peg$literalExpectation("/*",false),peg$c345="*/",peg$c346=peg$literalExpectation("*/",false),peg$c347=peg$otherExpectation("letter, number or underscore"),peg$c348=/^[a-z0-9_]/i,peg$c349=peg$classExpectation([["a","z"],["0","9"],"_"],false,true),peg$c350="&&",peg$c351=peg$literalExpectation("&&",false),peg$c352="=",peg$c353=peg$literalExpectation("=",false),peg$c354=function peg$c354(table_name,table_properties){var table={name:table_name.name,schemaName:table_name.schemaName,fields:[],indexes:[]};// process table_properties
table_properties.forEach(function(_ref){var table_property_name=_ref.table_property_name,value=_ref.value;switch(table_property_name.toLowerCase()){case"column":// if column contains inline_refs
// if(value.inline_refs && value.inline_refs.length > 0) {
// value.inline_refs.forEach(({ endpoints }) => {
// endpoints[0].tableName = table_name;
// })
// }
table.fields.push(value);break;case"table_constraint":var type=value.type,t_value=value.t_value;switch(type.toLowerCase()){case"unique":// set property unique for column
t_value.forEach(function(value){var field=table.fields.find(function(field){return field.name===value;});if(field){field.unique=true;}else{//throw Error(`${table_name}: UNIQUE - Can not find column ${value}.`);
}});break;case"pk":// set property pk for column, pk: PRIMARY KEY
t_value.forEach(function(value){var field=table.fields.find(function(field){return field.name===value;});if(field){field.pk=true;}else{//throw Error(`${table_name}: PRIMARY KEY - Can not find column ${value}.`);
}});break;case"fk":// set inline_ref for column
t_value.forEach(function(ref){var fieldNames=ref.endpoints[0].fieldNames;// set tableName for endpoints[0];
// endpoints[0].tableName = table_name;
var field=table.fields.find(function(field){return field.name===fieldNames[0];});if(!field){//throw Error(`${table_name}: FOREIGN KEY - Can not find column ${fieldNames}`);
}if(!field.inline_refs){field.inline_refs=[];}field.inline_refs.push({name:ref.name,endpoint:ref.endpoints[1],onDelete:ref.onDelete,onUpdate:ref.onUpdate});});break;}break;case"like":break;}});return{syntax_name:"create_table_normal",value:table};},peg$c355=function peg$c355(first,rest){return[first].concat(_toConsumableArray(rest.map(function(r){return r[3];})));},peg$c356=function peg$c356(table_constraint){return{table_property_name:"table_constraint",value:table_constraint};},peg$c357=function peg$c357(source_table){return{table_property_name:"like",value:source_table};},peg$c358=function peg$c358(column_name,data_type,column_constraints){var column={name:column_name,type:data_type};var columnTypeName=column.type.type_name.toLowerCase();var serialIncrementType=new Set(['serial','smallserial','bigserial']);// process type for increment
if(serialIncrementType.has(columnTypeName)){column.increment=true;}// map from grammar to right object
column_constraints=column_constraints.map(function(c){return c[1];});// process column_constraints
column_constraints.forEach(function(_ref2){var type=_ref2.type,value=_ref2.value;switch(type.toLowerCase()){case"not_null":column.not_null=value;break;case"increment":column.increment=true;break;case"dbdefault":column.dbdefault=value;break;case"unique":column.unique=true;break;case"pk":column.pk=true;break;case"fk":if(!column.inline_refs){column.inline_refs=[];}column.inline_refs.push(value);break;}});return{table_property_name:"column",value:column};},peg$c359=function peg$c359(constraint_name){return constraint_name;},peg$c360=function peg$c360(constraint_name){return{type:"not_null",value:true};},peg$c361=function peg$c361(constraint_name){return{type:"not_null",value:false};},peg$c362=function peg$c362(constraint_name){return{type:"not_supported"};},peg$c363=function peg$c363(constraint_name,default_expr){return{type:"dbdefault",value:default_expr};},peg$c364=function peg$c364(constraint_name){return{type:"increment"};},peg$c365=function peg$c365(constraint_name){return{type:"unique"};},peg$c366=function peg$c366(constraint_name){return{type:"pk"};},peg$c367=function peg$c367(constraint_name,reftable,refcolumn){return refcolumn;},peg$c368=function peg$c368(constraint_name,reftable,refcolumn,fk_actions){var ref_actions={};fk_actions.forEach(function(fkAction){if(fkAction.type==='delete'){ref_actions.onDelete=fkAction.action;return;}ref_actions.onUpdate=fkAction.action;});return{type:"fk",value:_objectSpread({name:constraint_name,endpoint:{tableName:reftable.name,schemaName:reftable.schemaName,fieldNames:refcolumn?[refcolumn]:null,relation:"1"}},ref_actions)};},peg$c369=function peg$c369(constraint_name,column_constraint){return column_constraint;},peg$c370=function peg$c370(constraint_name){return{type:"not_supported"};},peg$c371=function peg$c371(constraint_name,column_names){return{type:"unique",t_value:column_names};},peg$c372=function peg$c372(constraint_name,column_names){return{type:"pk",t_value:column_names};},peg$c373=function peg$c373(constraint_name){return{type:"not_supported"};},peg$c374=function peg$c374(constraint_name,column_names,reftable,refcolumn){return refcolumn;},peg$c375=function peg$c375(constraint_name,column_names,reftable,refcolumn,fk_actions){var value=[];if(refcolumn&&refcolumn.length>column_names.length){//throw Error(`Line ${location().start.line}: There are extra ${refcolumn.length - column_names.length} refer column(s) not matched.`);
}//if(refcolumn && key >= refcolumn.length) {
//throw Error(`Line ${location().start.line}: ${column_name} do not have referenced column.`)
//}
var v={name:constraint_name,endpoints:[{tableName:null,fieldNames:column_names,relation:"*"},{tableName:reftable.name,schemaName:reftable.schemaName,fieldNames:refcolumn,// ? refcolumn[key] : null,
relation:"1"}]};fk_actions.forEach(function(fkAction){if(fkAction.type==='delete'){v.onDelete=fkAction.action;return;}v.onUpdate=fkAction.action;});value.push(v);return{type:"fk",t_value:value};},peg$c376=function peg$c376(constraint_name,table_constraint){return table_constraint;},peg$c377=function peg$c377(type,action){return{type:type.toLowerCase(),action:action.toLowerCase()};},peg$c378="restrict",peg$c379=peg$literalExpectation("RESTRICT",true),peg$c380="cascade",peg$c381=peg$literalExpectation("CASCADE",true),peg$c382="action",peg$c383=peg$literalExpectation("ACTION",true),peg$c384="btree",peg$c385=peg$literalExpectation("BTREE",true),peg$c386="gist",peg$c387=peg$literalExpectation("GIST",true),peg$c388="gin",peg$c389=peg$literalExpectation("GIN",true),peg$c390="brin",peg$c391=peg$literalExpectation("BRIN",true),peg$c392="sp-gist",peg$c393=peg$literalExpectation("SP-GIST",true),peg$c394=function peg$c394(index_method){return index_method;},peg$c395=function peg$c395(index_parameters){return index_parameters;},peg$c396="fillfactor",peg$c397=peg$literalExpectation("fillfactor",true),peg$c398="parallel_worlers",peg$c399=peg$literalExpectation("parallel_worlers",true),peg$c400="autovacuum_enabled",peg$c401=peg$literalExpectation("autovacuum_enabled",true),peg$c402="toast.autovacuum_enabled",peg$c403=peg$literalExpectation("toast.autovacuum_enabled",true),peg$c404="autovacuum_vacuum_threshold",peg$c405=peg$literalExpectation("autovacuum_vacuum_threshold",true),peg$c406="toast.autovacuum_vacuum_threshold",peg$c407=peg$literalExpectation("toast.autovacuum_vacuum_threshold",true),peg$c408="autovacuum_vacuum_scale_factor",peg$c409=peg$literalExpectation("autovacuum_vacuum_scale_factor",true),peg$c410="toast.autovacuum_vacuum_scale_factor",peg$c411=peg$literalExpectation("toast.autovacuum_vacuum_scale_factor",true),peg$c412="autovacuum_analyze_threshold",peg$c413=peg$literalExpectation("autovacuum_analyze_threshold",true),peg$c414="autovacuum_analyze_scale_factor",peg$c415=peg$literalExpectation("autovacuum_analyze_scale_factor",true),peg$c416="autovacuum_vacuum_cost_delay",peg$c417=peg$literalExpectation("autovacuum_vacuum_cost_delay",true),peg$c418="toast.autovacuum_vacuum_cost_delay",peg$c419=peg$literalExpectation("toast.autovacuum_vacuum_cost_delay",true),peg$c420="autovacuum_vacuum_cost_limit",peg$c421=peg$literalExpectation("autovacuum_vacuum_cost_limit",true),peg$c422="toast.autovacuum_vacuum_cost_limit",peg$c423=peg$literalExpectation("toast.autovacuum_vacuum_cost_limit",true),peg$c424="autovacuum_freeze_min_age",peg$c425=peg$literalExpectation("autovacuum_freeze_min_age",true),peg$c426="toast.autovacuum_freeze_min_age",peg$c427=peg$literalExpectation("toast.autovacuum_freeze_min_age",true),peg$c428="autovacuum_freeze_max_age",peg$c429=peg$literalExpectation("autovacuum_freeze_max_age",true),peg$c430="toast.autovacuum_freeze_max_age",peg$c431=peg$literalExpectation("toast.autovacuum_freeze_max_age",true),peg$c432="autovacuum_freeze_table_age",peg$c433=peg$literalExpectation("autovacuum_freeze_table_age",true),peg$c434="toast.autovacuum_freeze_table_age",peg$c435=peg$literalExpectation("toast.autovacuum_freeze_table_age",true),peg$c436="autovacuum_multixact_freeze_min_age",peg$c437=peg$literalExpectation("autovacuum_multixact_freeze_min_age",true),peg$c438="toast.autovacuum_multixact_freeze_min_age",peg$c439=peg$literalExpectation("toast.autovacuum_multixact_freeze_min_age",true),peg$c440="autovacuum_multixact_freeze_max_age",peg$c441=peg$literalExpectation("autovacuum_multixact_freeze_max_age",true),peg$c442="toast.autovacuum_multixact_freeze_max_age",peg$c443=peg$literalExpectation("toast.autovacuum_multixact_freeze_max_age",true),peg$c444="autovacuum_multixact_freeze_table_age",peg$c445=peg$literalExpectation("autovacuum_multixact_freeze_table_age",true),peg$c446="toast.autovacuum_multixact_freeze_table_age",peg$c447=peg$literalExpectation("toast.autovacuum_multixact_freeze_table_age",true),peg$c448="log_autovacuum_min_duration",peg$c449=peg$literalExpectation("log_autovacuum_min_duration",true),peg$c450="toast.log_autovacuum_min_duration",peg$c451=peg$literalExpectation("toast.log_autovacuum_min_duration",true),peg$c452="user_catalog_table",peg$c453=peg$literalExpectation("user_catalog_table",true),peg$c454=function peg$c454(table_name,type_name){var table={name:table_name.name,schemaName:table_name.schemaName,type:type_name};return{syntax_name:"create_table_of",value:table};},peg$c455=function peg$c455(column_name,column_constraints){return{table_property_name:"table_constraint",value:{name:column_name,column_constraints:column_constraints}};},peg$c456=function peg$c456(table_name,parent_table){var table={name:table_name.name,schemaName:table_name.schemaName,parent_table:parent_table};return{syntax_name:"create_table_partition_of",value:table};},peg$c457=function peg$c457(create_table_normal){return{command_name:"create_table",value:create_table_normal};},peg$c458=function peg$c458(create_table_of){return{command_name:"create_table",value:create_table_of};},peg$c459=function peg$c459(create_table_partition_of){return{command_name:"create_table",value:create_table_partition_of};},peg$c460=function peg$c460(enumName,labels){var values=labels.map(function(name){return{name:name};});return{syntax_name:"create_type_enum",value:_objectSpread(_objectSpread({},enumName),{},{values:values})};},peg$c461=function peg$c461(first,rest){return[first].concat(_toConsumableArray(rest.map(function(r){return r[3];})));},peg$c462=function peg$c462(name,subtype){return{syntax_name:"create_table_range"};},peg$c463=function peg$c463(create_type_enum){return{command_name:"create_type",value:create_type_enum};},peg$c464=function peg$c464(create_type_range){return{command_name:"create_type",value:create_type_range};},peg$c465=function peg$c465(alter_sub_syntax){return{command_name:"alter_table",value:alter_sub_syntax};},peg$c466="*",peg$c467=peg$literalExpectation("*",false),peg$c468=function peg$c468(){return{syntax_name:"alter_table_rename"};},peg$c469=function peg$c469(){return{syntax_name:"alter_table_set_schema"};},peg$c470=function peg$c470(){return{syntax_name:"alter_set_tablespace"};},peg$c471=function peg$c471(){return{syntax_name:"alter_table_attach"};},peg$c472=function peg$c472(){return{syntax_name:"alter_table_detach"};},peg$c473=function peg$c473(name,actions){actions.forEach(function(_ref3){var type=_ref3.type,t_value=_ref3.t_value;switch(type.toLowerCase()){case"fk":t_value.forEach(function(_ref4){var endpoints=_ref4.endpoints;endpoints[0].tableName=name.name;endpoints[0].schemaName=name.schemaName;});}});return{syntax_name:"alter_table_action",value:actions};},peg$c474=function peg$c474(table_constraint){// reuse table_constraint in Create_table_normal.pegjs
return table_constraint;},peg$c475=function peg$c475(column_name,data_type,e){return e;},peg$c476=function peg$c476(column_name,data_type,expression){return{type:"type",expression:expression};},peg$c477=function peg$c477(column_name,expression){return{type:"set_default",expression:expression};},peg$c478=function peg$c478(column_name){return{type:"drop_default"};},peg$c479=function peg$c479(column_name,action){if(action.toUpperCase()==="SET"){return{type:"set_not_null"};}else{return{type:"drop_not_null"};}},peg$c480=function peg$c480(column_name,value){return{type:"set_statistics",value:value};},peg$c481=function peg$c481(column_name){return{type:"set_options"};},peg$c482=function peg$c482(column_name){return{type:"reset_options"};},peg$c483=function peg$c483(column_name,value){return{type:"set_storage",value:value.toLowerCase()};},peg$c484=function peg$c484(){return{type:"unknown"};},peg$c485=/^[^,;]/,peg$c486=peg$classExpectation([",",";"],true,false),peg$c487=function peg$c487(c){return removeReduntdantSpNewline(c.join(''));},peg$c488=function peg$c488(unique){return null;},peg$c489=function peg$c489(unique,name){return name;},peg$c490=function peg$c490(unique,name,table_name,type){return type;},peg$c491=function peg$c491(unique,name,table_name,type,index_properties){var value={syntax_name:"create_table",value:{table_name:table_name,columns:index_properties}};if(name)value.value.name=name;if(unique)value.value.unique=true;if(type)value.value.type=type.toUpperCase();return{command_name:"create_index",value:value};},peg$c492=function peg$c492(c,c1){return{value:"".concat(c,"(").concat(removeReduntdantSpNewline(_.flattenDeep(c1).join("")),")"),type:"expression"};},peg$c493=function peg$c493(c){return{value:"".concat(c),type:"string"};},peg$c494=function peg$c494(e){return{value:"".concat(e),type:"expression"};},peg$c495="COLLATE",peg$c496=peg$literalExpectation("COLLATE",false),peg$c497="ASC",peg$c498=peg$literalExpectation("ASC",false),peg$c499="DESC",peg$c500=peg$literalExpectation("DESC",false),peg$c501="NULLS",peg$c502=peg$literalExpectation("NULLS",false),peg$c503="FIRST",peg$c504=peg$literalExpectation("FIRST",false),peg$c505="LAST",peg$c506=peg$literalExpectation("LAST",false),peg$c507=function peg$c507(column){return column;},peg$c508="vacuum_cleanup_index_scale_factor",peg$c509=peg$literalExpectation("vacuum_cleanup_index_scale_factor",true),peg$c510="buffering",peg$c511=peg$literalExpectation("buffering",true),peg$c512="fastupdate",peg$c513=peg$literalExpectation("fastupdate",true),peg$c514="gin_pending_list_limit",peg$c515=peg$literalExpectation("gin_pending_list_limit",true),peg$c516="pages_per_range",peg$c517=peg$literalExpectation("pages_per_range",true),peg$c518="autosummarize",peg$c519=peg$literalExpectation("autosummarize",true),peg$c520=function peg$c520(comment_option,text){if(text.toLowerCase()!=="null"){comment_option.value.text=text;}else comment_option.value.text=null;return{command_name:"comment",value:comment_option};},peg$c521=function peg$c521(path,column_name){var dbName=null,schemaName=null,tableName;if(path.length===1){tableName=path[0][0];}else if(path.length===2){schemaName=path[0][0];tableName=path[1][0];}else{dbName=path[0][0];schemaName=path[1][0];tableName=path[2][0];}return{syntax_name:"column",value:{dbName:dbName,schemaName:schemaName,tableName:tableName,columnName:column_name}};},peg$c522=function peg$c522(object_name){return{syntax_name:"table",value:{table_name:object_name}};},peg$c523=/^[^;]/,peg$c524=peg$classExpectation([";"],true,false),peg$c525=function peg$c525(){return{syntax_name:"insert"};},peg$c526=function peg$c526(){return{syntax_name:"set"};},peg$c527=function peg$c527(){return{syntax_name:"reset"};},peg$c528=function peg$c528(){return{syntax_name:"select"};},peg$c529=function peg$c529(){return{syntax_name:"drop"};},peg$c530=function peg$c530(){return{syntax_name:"use"};},peg$c531=function peg$c531(){return{syntax_name:"create_sequence"};},peg$c532=function peg$c532(){return{syntax_name:"create_schema"};},peg$c533=function peg$c533(){return{syntax_name:"create_view"};},peg$c534=function peg$c534(){return{syntax_name:"alter_not_table"};},peg$c535=function peg$c535(){return{syntax_name:"comment_and_space"};},peg$c536=function peg$c536(value){var loc=location();var t=text();return{command_name:"ignore_syntax",value:value,warning:{type:'ignore',location:loc,text:t,message:"ignoring \"".concat(t,"\" at line: ").concat(loc.start.line)}};},peg$c537=function peg$c537(create_table){return create_table;},peg$c538=function peg$c538(create_type){return create_type;},peg$c539=function peg$c539(alter_table){return alter_table;},peg$c540=function peg$c540(create_index){return create_index;},peg$c541=function peg$c541(comment){return comment;},peg$c542=function peg$c542(ignore_syntax){return ignore_syntax;},peg$currPos=0,peg$savedPos=0,peg$posDetailsCache=[{line:1,column:1}],peg$maxFailPos=0,peg$maxFailExpected=[],peg$silentFails=0,peg$result;if("startRule"in options){if(!(options.startRule in peg$startRuleFunctions)){throw new Error("Can't start parsing from rule \""+options.startRule+"\".");}peg$startRuleFunction=peg$startRuleFunctions[options.startRule];}function text(){return input.substring(peg$savedPos,peg$currPos);}function location(){return peg$computeLocation(peg$savedPos,peg$currPos);}function expected(description,location){location=location!==void 0?location:peg$computeLocation(peg$savedPos,peg$currPos);throw peg$buildStructuredError([peg$otherExpectation(description)],input.substring(peg$savedPos,peg$currPos),location);}function error(message,location){location=location!==void 0?location:peg$computeLocation(peg$savedPos,peg$currPos);throw peg$buildSimpleError(message,location);}function peg$literalExpectation(text,ignoreCase){return{type:"literal",text:text,ignoreCase:ignoreCase};}function peg$classExpectation(parts,inverted,ignoreCase){return{type:"class",parts:parts,inverted:inverted,ignoreCase:ignoreCase};}function peg$anyExpectation(){return{type:"any"};}function peg$endExpectation(){return{type:"end"};}function peg$otherExpectation(description){return{type:"other",description:description};}function peg$computePosDetails(pos){var details=peg$posDetailsCache[pos],p;if(details){return details;}else{p=pos-1;while(!peg$posDetailsCache[p]){p--;}details=peg$posDetailsCache[p];details={line:details.line,column:details.column};while(p<pos){if(input.charCodeAt(p)===10){details.line++;details.column=1;}else{details.column++;}p++;}peg$posDetailsCache[pos]=details;return details;}}function peg$computeLocation(startPos,endPos){var startPosDetails=peg$computePosDetails(startPos),endPosDetails=peg$computePosDetails(endPos);return{start:{offset:startPos,line:startPosDetails.line,column:startPosDetails.column},end:{offset:endPos,line:endPosDetails.line,column:endPosDetails.column}};}function peg$fail(expected){if(peg$currPos<peg$maxFailPos){return;}if(peg$currPos>peg$maxFailPos){peg$maxFailPos=peg$currPos;peg$maxFailExpected=[];}peg$maxFailExpected.push(expected);}function peg$buildSimpleError(message,location){return new peg$SyntaxError(message,null,null,location);}function peg$buildStructuredError(expected,found,location){return new peg$SyntaxError(peg$SyntaxError.buildMessage(expected,found),expected,found,location);}function peg$parseparser(){var s0,s1,s2;s0=peg$currPos;s1=[];s2=peg$parsecommand();while(s2!==peg$FAILED){s1.push(s2);s2=peg$parsecommand();}if(s1!==peg$FAILED){peg$savedPos=s0;s1=peg$c0(s1);}s0=s1;return s0;}function peg$parseCREATE(){var s0;if(input.substr(peg$currPos,6).toLowerCase()===peg$c1){s0=input.substr(peg$currPos,6);peg$currPos+=6;}else{s0=peg$FAILED;if(peg$silentFails===0){peg$fail(peg$c2);}}return s0;}function peg$parseALTER(){var s0;if(input.substr(peg$currPos,5).toLowerCase()===peg$c3){s0=input.substr(peg$currPos,5);peg$currPos+=5;}else{s0=peg$FAILED;if(peg$silentFails===0){peg$fail(peg$c4);}}return s0;}function peg$parseUNIQUE(){var s0;if(input.substr(peg$currPos,6).toLowerCase()===peg$c5){s0=input.substr(peg$currPos,6);peg$currPos+=6;}else{s0=peg$FAILED;if(peg$silentFails===0){peg$fail(peg$c6);}}return s0;}function peg$parseINDEX(){var s0;if(input.substr(peg$currPos,5).toLowerCase()===peg$c7){s0=input.substr(peg$currPos,5);peg$currPos+=5;}else{s0=peg$FAILED;if(peg$silentFails===0){peg$fail(peg$c8);}}return s0;}function peg$parseTYPE(){var s0;if(input.substr(peg$currPos,4).toLowerCase()===peg$c9){s0=input.substr(peg$currPos,4);peg$currPos+=4;}else{s0=peg$FAILED;if(peg$silentFails===0){peg$fail(peg$c10);}}return s0;}function peg$parseENUM(){var s0;if(input.substr(peg$currPos,4).toLowerCase()===peg$c11){s0=input.substr(peg$currPos,4);peg$currPos+=4;}else{s0=peg$FAILED;if(peg$silentFails===0){peg$fail(peg$c12);}}return s0;}function peg$parseCONCURRENTLY(){var s0;if(input.substr(peg$currPos,11).toLowerCase()===peg$c13){s0=input.substr(peg$currPos,11);peg$currPos+=11;}else{s0=peg$FAILED;if(peg$silentFails===0){peg$fail(peg$c14);}}return s0;}function peg$parseFOREIGN_KEY(){var s0,s1,s2,s3;s0=peg$currPos;if(input.substr(peg$currPos,7).toLowerCase()===peg$c15){s1=input.substr(peg$currPos,7);peg$currPos+=7;}else{s1=peg$FAILED;if(peg$silentFails===0){peg$fail(peg$c16);}}if(s1!==peg$FAILED){s2=peg$parse__();if(s2!==peg$FAILED){if(input.substr(peg$currPos,3).toLowerCase()===peg$c17){s3=input.substr(peg$currPos,3);peg$currPos+=3;}else{s3=peg$FAILED;if(peg$silentFails===0){peg$fail(peg$c18);}}if(s3!==peg$FAILED){s1=[s1,s2,s3];s0=s1;}else{peg$currPos=s0;s0=peg$FAILED;}}else{peg$currPos=s0;s0=peg$FAILED;}}else{peg$currPos=s0;s0=peg$FAILED;}return s0;}function peg$parseREFERENCES(){var s0;if(input.substr(peg$currPos,10).toLowerCase()===peg$c19){s0=input.substr(peg$currPos,10);peg$currPos+=10;}else{s0=peg$FAILED;if(peg$silentFails===0){peg$fail(peg$c20);}}return s0;}function peg$parseON(){var s0;if(input.substr(peg$currPos,2).toLowerCase()===peg$c21){s0=input.substr(peg$currPos,2);peg$currPos+=2;}else{s0=peg$FAILED;if(peg$silentFails===0){peg$fail(peg$c22);}}return s0;}function peg$parseUSING(){var s0;if(input.substr(peg$currPos,5).toLowerCase()===peg$c23){s0=input.substr(peg$currPos,5);peg$currPos+=5;}else{s0=peg$FAILED;if(peg$silentFails===0){peg$fail(peg$c24);}}return s0;}function peg$parseTABLE(){var s0;if(input.substr(peg$currPos,5).toLowerCase()===peg$c25){s0=input.substr(peg$currPos,5);peg$currPos+=5;}else{s0=peg$FAILED;if(peg$silentFails===0){peg$fail(peg$c26);}}return s0;}function peg$parseIF_NOT_EXISTS(){var s0,s1,s2,s3,s4,s5;s0=peg$currPos;if(input.substr(peg$currPos,2).toLowerCase()===peg$c27){s1=input.substr(peg$currPos,2);peg$currPos+=2;}else{s1=peg$FAILED;if(peg$silentFails===0){peg$fail(peg$c28);}}if(s1!==peg$FAILED){s2=peg$parse__();if(s2!==peg$FAILED){if(input.substr(peg$currPos,3).toLowerCase()===peg$c29){s3=input.substr(peg$currPos,3);peg$currPos+=3;}else{s3=peg$FAILED;if(peg$silentFails===0){peg$fail(peg$c30);}}if(s3!==peg$FAILED){s4=peg$parse__();if(s4!==peg$FAILED){if(input.substr(peg$currPos,6).toLowerCase()===peg$c31){s5=input.substr(peg$currPos,6);peg$currPos+=6;}else{s5=peg$FAILED;if(peg$silentFails===0){peg$fail(peg$c32);}}if(s5!==peg$FAILED){s1=[s1,s2,s3,s4,s5];s0=s1;}else{peg$currPos=s0;s0=peg$FAILED;}}else{peg$currPos=s0;s0=peg$FAILED;}}else{peg$currPos=s0;s0=peg$FAILED;}}else{peg$currPos=s0;s0=peg$FAILED;}}else{peg$currPos=s0;s0=peg$FAILED;}return s0;}function peg$parseIF_EXISTS(){var s0,s1,s2,s3;s0=peg$currPos;if(input.substr(peg$currPos,2).toLowerCase()===peg$c27){s1=input.substr(peg$currPos,2);peg$currPos+=2;}else{s1=peg$FAILED;if(peg$silentFails===0){peg$fail(peg$c28);}}if(s1!==peg$FAILED){s2=peg$parse__();if(s2!==peg$FAILED){if(input.substr(peg$currPos,6).toLowerCase()===peg$c31){s3=input.substr(peg$currPos,6);peg$currPos+=6;}else{s3=peg$FAILED;if(peg$silentFails===0){peg$fail(peg$c32);}}if(s3!==peg$FAILED){s1=[s1,s2,s3];s0=s1;}else{peg$currPos=s0;s0=peg$FAILED;}}else{peg$currPos=s0;s0=peg$FAILED;}}else{peg$currPos=s0;s0=peg$FAILED;}return s0;}function peg$parseGLOBAL(){var s0;if(input.substr(peg$currPos,6).toLowerCase()===peg$c33){s0=input.substr(peg$currPos,6);peg$currPos+=6;}else{s0=peg$FAILED;if(peg$silentFails===0){peg$fail(peg$c34);}}return s0;}function peg$parseLOCAL(){var s0;if(input.substr(peg$currPos,5).toLowerCase()===peg$c35){s0=input.substr(peg$currPos,5);peg$currPos+=5;}else{s0=peg$FAILED;if(peg$silentFails===0){peg$fail(peg$c36);}}return s0;}function peg$parseTEMPORARY(){var s0;if(input.substr(peg$currPos,9).toLowerCase()===peg$c37){s0=input.substr(peg$currPos,9);peg$currPos+=9;}else{s0=peg$FAILED;if(peg$silentFails===0){peg$fail(peg$c38);}}return s0;}function peg$parseTEMP(){var s0;if(input.substr(peg$currPos,4).toLowerCase()===peg$c39){s0=input.substr(peg$currPos,4);peg$currPos+=4;}else{s0=peg$FAILED;if(peg$silentFails===0){peg$fail(peg$c40);}}return s0;}function peg$parseUNLOGGED(){var s0;if(input.substr(peg$currPos,8).toLowerCase()===peg$c41){s0=input.substr(peg$currPos,8);peg$currPos+=8;}else{s0=peg$FAILED;if(peg$silentFails===0){peg$fail(peg$c42);}}return s0;}function peg$parseCOLLATE(){var s0;if(input.substr(peg$currPos,7).toLowerCase()===peg$c43){s0=input.substr(peg$currPos,7);peg$currPos+=7;}else{s0=peg$FAILED;if(peg$silentFails===0){peg$fail(peg$c44);}}return s0;}function peg$parseCOLLATION(){var s0;if(input.substr(peg$currPos,9).toLowerCase()===peg$c45){s0=input.substr(peg$currPos,9);peg$currPos+=9;}else{s0=peg$FAILED;if(peg$silentFails===0){peg$fail(peg$c46);}}return s0;}function peg$parsePARTITION(){var s0;if(input.substr(peg$currPos,9).toLowerCase()===peg$c47){s0=input.substr(peg$currPos,9);peg$currPos+=9;}else{s0=peg$FAILED;if(peg$silentFails===0){peg$fail(peg$c48);}}return s0;}function peg$parseBY(){var s0;if(input.substr(peg$currPos,2).toLowerCase()===peg$c49){s0=input.substr(peg$currPos,2);peg$currPos+=2;}else{s0=peg$FAILED;if(peg$silentFails===0){peg$fail(peg$c50);}}return s0;}function peg$parseRANGE(){var s0;if(input.substr(peg$currPos,5).toLowerCase()===peg$c51){s0=input.substr(peg$currPos,5);peg$currPos+=5;}else{s0=peg$FAILED;if(peg$silentFails===0){peg$fail(peg$c52);}}return s0;}function peg$parseLIST(){var s0;if(input.substr(peg$currPos,4).toLowerCase()===peg$c53){s0=input.substr(peg$currPos,4);peg$currPos+=4;}else{s0=peg$FAILED;if(peg$silentFails===0){peg$fail(peg$c54);}}return s0;}function peg$parseHASH(){var s0;if(input.substr(peg$currPos,4).toLowerCase()===peg$c55){s0=input.substr(peg$currPos,4);peg$currPos+=4;}else{s0=peg$FAILED;if(peg$silentFails===0){peg$fail(peg$c56);}}return s0;}function peg$parseLIKE(){var s0;if(input.substr(peg$currPos,4).toLowerCase()===peg$c57){s0=input.substr(peg$currPos,4);peg$currPos+=4;}else{s0=peg$FAILED;if(peg$silentFails===0){peg$fail(peg$c58);}}return s0;}function peg$parseINHERITS(){var s0;if(input.substr(peg$currPos,8).toLowerCase()===peg$c59){s0=input.substr(peg$currPos,8);peg$currPos+=8;}else{s0=peg$FAILED;if(peg$silentFails===0){peg$fail(peg$c60);}}return s0;}function peg$parseINHERIT(){var s0;if(input.substr(peg$currPos,7).toLowerCase()===peg$c61){s0=input.substr(peg$currPos,7);peg$currPos+=7;}else{s0=peg$FAILED;if(peg$silentFails===0){peg$fail(peg$c62);}}return s0;}function peg$parseWITH(){var s0;if(input.substr(peg$currPos,4).toLowerCase()===peg$c63){s0=input.substr(peg$currPos,4);peg$currPos+=4;}else{s0=peg$FAILED;if(peg$silentFails===0){peg$fail(peg$c64);}}return s0;}function peg$parseWITHOUT(){var s0;if(input.substr(peg$currPos,7).toLowerCase()===peg$c65){s0=input.substr(peg$currPos,7);peg$currPos+=7;}else{s0=peg$FAILED;if(peg$silentFails===0){peg$fail(peg$c66);}}return s0;}function peg$p