<< Change List | Constraints >>
This shows the syntax of a jADT file in EBNF notation with informal commentary interspersed. X? means X is optional. X* mean 0 or more occurances of X. X+ means 1 or more occurances of X.
DOC : PACKAGE? IMPORTS DATATYPES
A jADT document has an optional package followed by imports and datatypes.
PACKAGE : JAVA_COMMENTS? "package" PACKAGENAME
PACKAGENAME : identifier ("." identifier)*The package declaration (if it exists) is the keyword "package" followed by a package name. No semicolon required.
IMPORTS : IMPORT*
IMPORT : JAVA_COMMENTS? "import" IMPORTNAME
IMPORTNAME : identifier ("." identifier)* ("." "*")?A jADT document may specify any number (including 0) of package names to import. Each one is the keyword "import" followed by a package name which may include a wildcard *. No semicolon required.
DATATYPES : DATATYPE+
DATATYPE : JAVA_COMMENTS? DATATYPENAME TYPEARGS? JAVA_COMMENTS? "=" CONSTRUCTORS
DATATYPENAME : a valid Java identifier, not qualified with a packageA jADT document must have at least one datatype, but may have as many as you'd like. Each datatype consists of a name, optional type arguments, "=" and a list of constructors.
TYPEARGS : "<" TYPEARG ("," TYPEARG)* ">"
TYPEARG: a valid Java identifierAs in Java, the type arguments for a data type are specfied with <Arg1, Arg2, Arg3, etc>.
CONSTRUCTORS : CONSTRUCTOR (JAVA_COMMENTS? "|" CONSTRUCTOR)*
CONSTRUCTOR : JAVA_COMMENTS? CONSTRUCTORNAME ("(" ARGS ")")?
CONSTRUCTORNAME : a valid Java identifierA datatype must have a list of one or more constructors separated by "|". Each constructor is a name followed by an optional list of argument fields surrounded by "(" and ")". If a constructor has no args then it must not have a "(" ")" pair.
ARGS : ARG ("," ARG)*
ARG : ARGMODIFIER* TYPE ARGNAME
ARGNAME : a valid Java identifierIf a constructor has an argument field list then it must have a least one argument. An argument is a list of argument modifiers (separated by whitespace) followed by a type followed by a name. Multiple args are separated by ",".
ARGMODIFIER : FINAL FINAL : "final"
Currently the only modifier allowed on an arg is "final."
TYPE : PRIMITIVETYPE | REFTYPE
A type is a primitive or reference type.
REFTYPE : ARRAYTYPE | CLASSTYPE
A reference type is an array type or a classtype.
ARRAYTYPE : TYPE "[]"
An array is any type followed by "[]".
CLASSTYPE : CLASSNAME("<" TYPEPARAMS ">")?
CLASSNAME : a valid Java class name, possibly qualified with a packageA class type is a valid Java class name (which may be qualfied as in foo.bar.Baz), optionally followed by type parameters surrounded by "<" and ">".
TYPEPARAMS : REFTYPE ("," REFTYPE)*Type params must be a series of 1 or more reference types separated by ",".
PRIMITIVETYPE : "boolean" | "byte" | "char" | "double" |
"float" | "int" | "long" | "short"Primitives types are the Java primitive types.
JAVA_COMMENTS : Java style comments - end of line (//), block (/* */), and JavaDoc (/** */).
Java style comments are allowed in several places as described by this grammar, but there are limitations on their location.