Skip to content

Commit

Permalink
Merge branch 'descriptors' of https://github.com/ceylon/ceylon-spec i…
Browse files Browse the repository at this point in the history
…nto descriptors
  • Loading branch information
gavinking committed Jul 31, 2012
2 parents 3050ded + 9c568cf commit a355fdb
Show file tree
Hide file tree
Showing 61 changed files with 824 additions and 1,634 deletions.
132 changes: 104 additions & 28 deletions Ceylon.g
Expand Up @@ -41,50 +41,99 @@ compilationUnit returns [CompilationUnit compilationUnit]
SEMICOLON
{ $compilationUnit.getCompilerAnnotations().addAll($ca1.annotations); }
)?
importList
{ $compilationUnit.setImportList($importList.importList); }
(
ca2=compilerAnnotations declaration
{ if ($declaration.declaration!=null)
$compilationUnit.addDeclaration($declaration.declaration);
if ($declaration.declaration!=null)
$declaration.declaration.getCompilerAnnotations().addAll($ca2.annotations); }
)*
(
(compilerAnnotations annotations MODULE)=>
moduleDescriptor
{ $compilationUnit.setModuleDescriptor($moduleDescriptor.moduleDescriptor); }
|
(compilerAnnotations annotations PACKAGE)=>
packageDescriptor
{ $compilationUnit.setPackageDescriptor($packageDescriptor.packageDescriptor); }
|
importList
{ $compilationUnit.setImportList($importList.importList); }
(
ca2=compilerAnnotations declaration
{ if ($declaration.declaration!=null)
$compilationUnit.addDeclaration($declaration.declaration);
if ($declaration.declaration!=null)
$declaration.declaration.getCompilerAnnotations().addAll($ca2.annotations); }
)*
)
EOF
;

moduleDescriptor returns [ModuleDescriptor moduleDescriptor]
: compilerAnnotations annotations
MODULE
{ $moduleDescriptor = new ModuleDescriptor($MODULE);
$moduleDescriptor.setAnnotationList($annotations.annotationList);
$moduleDescriptor.getCompilerAnnotations().addAll($compilerAnnotations.annotations); }
packagePath
{ $moduleDescriptor.setImportPath($packagePath.importPath); }
QUOTED_LITERAL
{ $moduleDescriptor.setVersion(new QuotedLiteral($QUOTED_LITERAL)); }
importModuleList
{ $moduleDescriptor.setImportModuleList($importModuleList.importModuleList); }
;

importModuleList returns [ImportModuleList importModuleList]
: LBRACE
{ $importModuleList = new ImportModuleList($LBRACE); }
(
compilerAnnotations annotations
importModule
{ if ($importModule.importModule!=null)
$importModuleList.addImportModule($importModule.importModule);
if ($importModule.importModule!=null)
$importModule.importModule.setAnnotationList($annotations.annotationList);
if ($importModule.importModule!=null)
$importModule.importModule.getCompilerAnnotations().addAll($compilerAnnotations.annotations); }
)*
RBRACE
{ $importModuleList.setEndToken($RBRACE); }
;

packageDescriptor returns [PackageDescriptor packageDescriptor]
: compilerAnnotations annotations
PACKAGE
{ $packageDescriptor = new PackageDescriptor($PACKAGE);
$packageDescriptor.setAnnotationList($annotations.annotationList);
$packageDescriptor.getCompilerAnnotations().addAll($compilerAnnotations.annotations); }
packagePath
{ $packageDescriptor.setImportPath($packagePath.importPath); }
SEMICOLON
{ $packageDescriptor.setEndToken($SEMICOLON); }
;

importModule returns [ImportModule importModule]
: IMPORT
{ $importModule = new ImportModule($IMPORT); }
packagePath
{ $importModule.setImportPath($packagePath.importPath); }
QUOTED_LITERAL
{ $importModule.setVersion(new QuotedLiteral($QUOTED_LITERAL)); }
SEMICOLON
{ $importModule.setEndToken($SEMICOLON); }
;

importList returns [ImportList importList]
: { $importList = new ImportList(null); }
( importDeclaration { $importList.addImport($importDeclaration.importDeclaration); } )*
;

importDeclaration returns [Import importDeclaration]
@init { ImportPath importPath=null; }
: IMPORT
{ $importDeclaration = new Import($IMPORT); }
(
pn1=packageName
{ importPath = new ImportPath(null);
if ($pn1.identifier!=null)
importPath.addIdentifier($pn1.identifier);
$importDeclaration.setImportPath(importPath); }
(
m=MEMBER_OP
{ importPath.setEndToken($m); }
(
pn2=packageName
{ importPath.addIdentifier($pn2.identifier);
importPath.setEndToken(null); }
| { displayRecognitionError(getTokenNames(),
new MismatchedTokenException(LIDENTIFIER, input)); }
)
)*
(
packagePath
{ $importDeclaration.setImportPath($packagePath.importPath); }
| { displayRecognitionError(getTokenNames(),
new MismatchedTokenException(LIDENTIFIER, input)); }
)
importElementList
{ $importDeclaration.setImportMemberOrTypeList($importElementList.importMemberOrTypeList); }
;
;

importElementList returns [ImportMemberOrTypeList importMemberOrTypeList]
@init { ImportMemberOrTypeList il=null;
Expand Down Expand Up @@ -162,6 +211,25 @@ importName returns [Identifier identifier]
| typeName { $identifier=$typeName.identifier; }
;

packagePath returns [ImportPath importPath]
@init { $importPath = new ImportPath(null); }
: pn1=packageName
{ if ($pn1.identifier!=null)
$importPath.addIdentifier($pn1.identifier); }
(
m=MEMBER_OP
{ $importPath.setEndToken($m); }
(
pn2=packageName
{ $importPath.addIdentifier($pn2.identifier);
$importPath.setEndToken(null); }
| { displayRecognitionError(getTokenNames(),
new MismatchedTokenException(LIDENTIFIER, input)); }
)
)*
;


packageName returns [Identifier identifier]
: LIDENTIFIER
{ $identifier = new Identifier($LIDENTIFIER);
Expand Down Expand Up @@ -2980,6 +3048,14 @@ FUNCTION_MODIFIER
: 'function'
;

MODULE
: 'module'
;

PACKAGE
: 'package'
;

NONEMPTY
: 'nonempty'
;
Expand Down
20 changes: 20 additions & 0 deletions Ceylon.nodes
@@ -1,9 +1,29 @@
"A file containing Ceylon source."
^(COMPILATION_UNIT
MODULE_DESCRIPTOR?
PACKAGE_DESCRIPTOR?
COMPILER_ANNOTATION*
IMPORT_LIST?
DECLARATION*)

^(MODULE_DESCRIPTOR:STATEMENT_OR_ARGUMENT
ANNOTATION_LIST?
IMPORT_PATH
QUOTED_LITERAL version
IMPORT_MODULE_LIST)

^(PACKAGE_DESCRIPTOR:STATEMENT_OR_ARGUMENT
ANNOTATION_LIST?
IMPORT_PATH)

^(IMPORT_MODULE_LIST
IMPORT_MODULE*)

^(IMPORT_MODULE:STATEMENT_OR_ARGUMENT
ANNOTATION_LIST?
IMPORT_PATH
QUOTED_LITERAL version)

^(IMPORT_LIST
IMPORT*)

Expand Down

0 comments on commit a355fdb

Please sign in to comment.