org.openxma.dsl.ddl.DdlDsl.xtext Maven / Gradle / Ivy
grammar org.openxma.dsl.ddl.DdlDsl with org.eclipse.xtext.common.Terminals
generate ddlDsl "http://www.openxma.org/dsl/ddl/DdlDsl"
Ddl:
{Ddl} (statements+=DdlStatement)*; //http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_1001.htm#sthref3207
DdlStatement:
Alter|Create|Drop|Comment|OtherStatement;
OtherStatement:
Other* ';'
;
Alter:
'ALTER' 'TABLE' table=[CreateTable|QID] action=AlterTableAction Other* ';';
AlterTableAction:
AddTableConstraint|DropTableConstraint|AlterTableActionOther;
AlterTableActionOther:
'ADD'|'ALTER'|'DROP' ;
DropTableConstraint:
'DROP' 'CONSTRAINT'? (constraintRef=[Constraint]|constraint=Constraint);
Comment:
TableComment | ColumnComment
;
TableComment:
'COMMENT' 'ON' 'TABLE' table=[CreateTable|QID] 'is' comment=STRING ';'
;
ColumnComment:
'COMMENT' 'ON' 'COLUMN' column=[Column|QID] 'is' comment=STRING ';'
;
AddTableConstraint:
'ADD' '('? 'CONSTRAINT' name=QID constraint=Constraint;
Create:
CreateTable|CreateIndex|CreateOther;
CreateTable:
'CREATE' ('GLOBAL' 'TEMPORARY')? 'TABLE' name=QID '(' properties+=TableProperty (','
properties+=TableProperty)* ')' Other* ';';
CreateIndex:
'CREATE' (unique?='UNIQUE')? 'INDEX' name=QID 'ON' table=[CreateTable|QID] '(' columns
+=[Column] (sortOrders+=SortDirectionEnum)? (',' columns+=[Column] (sortOrders+=
SortDirectionEnum)?)* ')' Other* ';';
TableProperty:
Column|Constraint;
Column:
name=ID type=SqlDataType (sorted?='SORT'|constraint=Constraint|default=ColumnDefault|
reference=ReferenceClause)*;
ColumnDefault:
'DEFAULT' Other*;
CreateOther:
'CREATE' Other* ';';
Drop:
'DROP' object=DataBaseObject Other* ';';
QID:
ID ('.' ID)*;
Other:
STRING|ANY_OTHER|ID|INT|'('|')'|'.'|','|'ON'|'TO'|'CASCADE'|DataBaseObject;
Constraint:
(NullableConstraint|UniqueKeyConstraint|PrimaryKeyConstraint|
ForeignKeyConstraint|CheckConstraint) (name=ID)?;
NullableConstraint:
('CONSTRAINT' name=ID)? (not?='NOT')? 'NULL';
UniqueKeyConstraint:
('CONSTRAINT' name=ID)? 'UNIQUE' 'KEY'? ('(' columns+=[Column|QID] (',' columns+=[
Column|QID])* ')')?;
PrimaryKeyConstraint:
('CONSTRAINT' name=ID)? 'PRIMARY' 'KEY' ('(' columns+=[Column|QID] (',' columns+=[
Column|QID])* ')')?;
CheckConstraint:
'CHECK' Other*;
ForeignKeyConstraint:
'FOREIGN' 'KEY' '(' columns+=[Column|QID] (',' columns+=[Column|QID])* ')' reference=
ReferenceClause;
ReferenceClause:
'REFERENCES' table=[CreateTable|QID] ('(' columns+=[Column|QID] (',' columns+=[Column|QID])* ')')?
Other*;
SqlDataType:
(SqlCharacter|SqlNumber|LongRaw|SqlDateTime|LargeObjectType|RowIdType|SqlBoolean) (name=ID)?;
SqlCharacter:
(national?='NATIONAL')? name=( 'CHAR' | 'VARCHAR2' | 'VARCHAR' | 'CHARACTER' | 'NCHAR' | 'NVARCHAR2' ) 'VARYING'? ('(' size=INT ('BYTE'|'CHAR')? ')')?;
SqlNumber:
name=( 'NUMBER' | 'NUMERIC' | 'DECIMAL' | 'DEC' | 'INTEGER' | 'INT' | 'SMALLINT' | 'BIGINT' | 'FLOAT' |
'DOUBLE' | 'REAL' | 'BINARY_FLOAT' | 'BINARY_DOUBLE' ) (hasPrecision?='PRECISION')? ('(' precision=INT (','
scale=INT)? ')')?;
LongRaw:
Long|Raw;
Long:
name='LONG' raw?='RAW';
Raw:
name='RAW' '(' size=INT ')';
SqlDateTime:
SqlDate|SqlTimeStamp|SqlInterval;
SqlDate:
name='DATE';
SqlTimeStamp:
name='TIMESTAMP' ('(' precision=INT ')')? ('WITH' 'LOCAL'? 'TIME' 'ZONE')?;
SqlInterval:
name='INTERVAL' year?='YEAR'|day?='DAY' ('(' precision=INT ')')? 'TO' 'MONTH'|'SECOND'
('(' secondsPrecision=INT ')')?;
LargeObjectType:
name=('BLOB'|'CLOB'|'NCLOB'|'BFILE'|'VARBINARY'|'LONGVARBINARY'|'BINARY')('(' size=INT ')')?;
RowIdType:
name=('ROWID'|'UROWID') ('(' size=INT ')')?;
SqlBoolean:
name=('BIT'|'BOOLEAN');
DataBaseObject:
'TABLE'|'VIEW'|'TABLESPACE'|'INDEX'|'SEQUENCE'|'DATABASE'|'INDEX';
enum SortDirectionEnum:
ASC | DESC;