grammar SQLCreateTable include SQLRowSupport include SQLDataTypes rule create_table "CREATE" SPACES "TABLE" SPACES table_name SPACES OPEN_PARENS columns_and_datatypes CLOSE_PARENS optional_engine { def eval options = { :columns => columns_and_datatypes.eval, :table_name => table_name.eval } options end def query_type :create_table end def tree values = eval { :table => values[:table_name], :columns => values[:columns] } end } end rule columns_and_datatypes column_with_datatype COMMA columns_and_datatypes { def eval all = column_with_datatype.eval + columns_and_datatypes.eval all.flatten! all end } / column_with_datatype end rule column_with_datatype optional_spaces column_name SPACES datatype optional_column_features? optional_spaces { def eval [column_name.eval] end } end rule optional_column_features optional_column_feature optional_column_feature / optional_column_feature end rule optional_column_feature optional_primary_key / optional_auto_increment / optional_default / optional_not_null end rule optional_primary_key SPACES "PRIMARY" SPACES "KEY" / SPACES "primary" SPACES "key" end rule optional_default SPACES "DEFAULT" SPACES (quoted_string / NULL_KEYWORD / integer) / SPACES "default" SPACES (quoted_string / NULL_KEYWORD / integer) end rule optional_auto_increment SPACES "AUTO_INCREMENT" / SPACES "auto_increment" end rule optional_not_null SPACES (NOT_KEYWORD SPACES)? NULL_KEYWORD end rule optional_engine SPACES "ENGINE=InnoDB" / EMPTY_STRING end end