How to implement such a different ImportedNamespace? [message #1060981] |
Wed, 29 May 2013 12:16 |
Matthew Liu Messages: 9 Registered: March 2013 |
Junior Member |
|
|
Hi all,
Xtext documentation (15 Minutes Tutorial) gives an example to implement the following language (the main purpose is to show how to use importedNamespace to support 'Packages" and 'Import').
// datatypes.dmodel, the first file
datatype String
// commons.dmodel, the second file
package my.company.common {
entity HasAuthor {
author: String
}
}
// blogs.dmodel, the third file
package my.company.blog {
import my.company.common.*
entity Blog {
title: String
many posts: Post
}
entity Post extends my.company.common.HasAuthor {
title: String
content: String
many comments: Comment
}
entity Comment extends HasAuthor {
content: String
}
}
The following is the full grammar.
grammar org.example.domainmodel.Domainmodel with
org.eclipse.xtext.common.Terminals
generate domainmodel "www.example.org/domainmodel/Domainmodel"
Domainmodel:
(elements += AbstractElement)*
;
PackageDeclaration:
'package' name = QualifiedName '{'
(elements += AbstractElement)*
'}'
;
AbstractElement:
PackageDeclaration | Type | Import
;
QualifiedName:
ID ('.' ID)*
;
Import:
'import' importedNamespace = QualifiedNameWithWildcard
;
QualifiedNameWithWildcard:
QualifiedName '.*'?
;
Type:
DataType | Entity
;
DataType:
'datatype' name=ID
;
Entity:
'entity' name = ID ('extends' superType = [Entity | QualifiedName])? '{'
(features += Feature)*
'}'
;
Feature:
(many ?= 'many')? name = ID ':' type = [Type | QualifiedName]
;
However, I want my language to support the following 'Import' mechanism.
import * from my.company.common // equivalent to "import my.company.common.*"
import my.company.common // no '.*', equivalent to "import my.company.common.*"
import HasAuthor from my.company.common // equivalent to "import my.company.common.HasAuthor", that is, only "HasAuthor" is imported
Could anyone please give some advices on how to implement this kind of 'Import' mechanism? Thanks in advance!
Best Regards,
Matthew
[Updated on: Sun, 02 June 2013 09:07] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02962 seconds