TCS: Textual Concrete Syntax - PowerPoint PPT Presentation

1 / 22
About This Presentation
Title:

TCS: Textual Concrete Syntax

Description:

Text hovers. Syntax highlighting. Outline with bidirectional synchronization ... To provide text hovers and hyperlinks. 2nd AMMA/ATL Workshop - May 4, 2006 - Nantes ... – PowerPoint PPT presentation

Number of Views:59
Avg rating:3.0/5.0
Slides: 23
Provided by: frdr4
Category:

less

Transcript and Presenter's Notes

Title: TCS: Textual Concrete Syntax


1
TCS Textual Concrete Syntax A DSL for the
Specification of Textual Concrete Syntaxes in
MDE Frédéric Jouault ATLAS group (INRIA
LINA), University of Nantes, France http//www.sci
ences.univ-nantes.fr/lina/atl/
2
Contents
  • Introduction
  • A case study KM3
  • Specification of KM3 Textual Concrete Syntax
  • Basic constructs templates, properties, and
    literals
  • More constructs conditionals, symbol table
    handling
  • Advanced constructs operators, function
    templates
  • Other features
  • Textual Concrete Syntax for KM3
  • Textual Generic Editor
  • Conclusion

3
Introduction
  • Metamodels can be specified
  • Graphically with
  • a UML modeling tool transformations (e.g.
    UML2MOF.atl),
  • a metamodeling tool, etc.
  • Textually with
  • KM3,
  • emfatic, etc.
  • What about the specification of models?
  • Graphically with
  • ad-hoc solutions developed for each DSL (e.g.
    using EMF and GEF),
  • a generic tool like Eclipse/GMF, etc.
  • Textually with
  • ad-hoc solutions (e.g. Velocity for model-to-text
    and ANTLR for text-to-model),
  • a generic tool like TCS.

4
Introduction, continued
  • Textual Concrete Syntax (TCS)
  • is a DSL defined with a KM3 metamodel,
  • has a Textual Concrete Syntax specified in TCS,
  • can be used to
  • parse text-to-model,
  • serialize model-to-text,
  • with a single (bidirectional) specification.
  • The present implementation of TCS
  • Performs text-to-model by generating an ANTLR
    grammar (TCS2ANTLR.atl),
  • Performs model-to-text using a Java-based
    extractor or by generating an ATL OCL query.

5
A case study KM3
Note The KM3 metamodel used in this
presentation has been slightly simplified.
6
KM3 definition of the KM3 metamodel
  • package KM3
  • abstract class ModelElement
  • attribute name String
  • reference "package" Package oppositeOf
    contents
  • class Package extends ModelElement
  • reference contents ordered container
    ModelElement
  • oppositeOf "package"
  • class Classifier extends ModelElement
  • class DataType extends Classifier
  • class Class extends Classifier
  • attribute isAbstract Boolean
  • reference supertypes Class
  • reference structuralFeatures ordered
    container

7
KM3 definition of the KM3 metamodel, continued
  • -- continued from previous slide
  • class StructuralFeature extends ModelElement
  • attribute lower Integer
  • attribute upper Integer
  • attribute isOrdered Boolean
  • attribute isUnique Boolean
  • reference type Classifier
  • reference owner Class oppositeOf
    structuralFeatures
  • class Attribute extends StructuralFeature
  • class Reference extends StructuralFeature
  • attribute isContainer Boolean
  • reference opposite0-1 Reference

8
Basic constructs templates, properties, and
literalsTextual representation of Package
  • Metamodel excerpt
  • abstract class ModelElement
  • attribute name String
  • reference "package" Package
    oppositeOf contents
  • class Package extends ModelElement
  • reference contents ordered
    container ModelElement oppositeOf "package"
  • Corresponding TCS excerpt
  • template ModelElement abstract
  • template Package main context
  • "package" name ""
  • contents
  • ""

9
Basic constructs remarks
  • There is little redundancy between the metamodel
    and the TCS
  • The links between metamodel and TCS elements are
    done by name (e.g. Class Template, properties,
    etc.),
  • The (primitive) type of the name attribute is
    known from the metamodel whereas its position in
    the text is known from the TCS,
  • The (complex) type and multiplicity of the
    contents reference are known from the metamodel
    whereas its position in the text is known from
    the TCS.
  • Structural elements are defined in KM3.
  • Syntax elements are defined in TCS
  • Keywords as alpha-numeric strings between double
    quotes,
  • Symbols as non-alpha-numeric strings between
    double quotes.

10
More constructs conditionals, symbol table
handlingTextual representation of Class
  • Metamodel excerpt
  • abstract class ModelElement
  • attribute name String
  • class Class extends Classifier
  • attribute isAbstract Boolean
  • reference supertypes Class
  • reference structuralFeatures
    ordered container StructuralFeature
  • oppositeOf owner
  • Corresponding TCS excerpt
  • template Classifier abstract
    addToContext
  • template Class context
  • (isAbstract ? "abstract")
    "class" name
  • (isDefined(supertypes) ?
  • "extends" supertypesrefersTo name,
    separator ",", autoCreate never

11
More constructs remarks
  • TCS handles the symbol table
  • Elements are marked as being contexts using the
    context keyword,
  • Elements are added in the current context using
    the addToContext keyword,
  • Elements are referred to by the value of one of
    their properties using the refersTo keyword.
  • Conditional elements
  • Using the value of Boolean properties (e.g.
    isAbstract here),
  • Testing the value of a property (not shown yet),
  • Testing whether a property is set for
    multiplicities 0-n, 1 n (e.g. supertypes here).
  • Miscellaneous
  • Separators can be specified for multi-valued
    properties (e.g. supertypes here).

12
Advanced constructs operators, function templates
  • TCS can also deal with operators
  • Operators and their priorities are first defined,
  • operatorTemplates are used to specify their use,
  • The notation can be chosen
  • Infix 1 x 4
  • RPN ( 1 ( x 4))
  • More complex symbol table handling can be
    performed
  • Context importation (e.g. to deal with class
    inheritance),
  • Search for a target element in another context
    than the current one using the lookIn keyword
    (see the Reference template later in this
    presentation).
  • Functions can be defined to factorize code (see
    later in this presentation).

13
Other features
  • Model-to-text actually needs more than the
    syntax
  • Indentation blocks can be defined,
  • Specific separators can be used (new line, blank,
    tab, etc.).
  • Text-to-model traceability is provided
  • The location attribute of each generated element
    is set with
  • Line and column numbers of beginning,
  • Line and column numbers of ending,
  • Comments may be kept (and serialized).

14
Textual Concrete Syntax for KM3
  • syntax KM3
  • template ModelElement abstract
  • template Package main context
  • "package" name ""
  • contents
  • ""
  • template Classifier abstract
    addToContext
  • template DataType
  • "datatype" name ""
  • template Class context
  • (isAbstract ? "abstract")
    "class" name
  • (isDefined(supertypes) ?

15
Textual Concrete Syntax for KM3, continued
  • -- continued from previous slide
  • template StructuralFeature abstract
  • template Reference addToContext
  • "reference" name
    multiplicity (isContainer ? "container") "
  • typerefersTo name,
    autoCreate never
  • (isDefined(opposite) ?
  • "oppositeOf"
  • oppositerefersTo
    name, lookIn type, autoCreate never
  • )
  • ""
  • template Attribute
  • "attribute" name
    multiplicity
  • typerefersTo name,
    autoCreate never ""

-- uses lookIn
-- function call
16
Textual Concrete Syntax for KM3, continued
  • -- continued from previous slide
  • function multiplicity(StructuralFeature)
  • (lower 1 and upper 1
    ?
  • --
    nothing
  • (lower
    0 and upper -1 ?

  • "" "" ""

  • (upper -1 ?

  • "" lower "-" "" ""


  • "" lower "-" upper ""

  • )
  • )
  • )
  • (isOrdered ? "ordered")

-- function definition
-- test of integer propreties
17
Textual Concrete Syntax for KM3, continued
  • -- continued from previous slide
  • symbols
  • lsquare ""
  • rsquare ""
  • coma ","
  • lcurly ""
  • rcurly ""
  • semi ""
  • colon ""
  • minus "-"
  • star ""

18
Textual Generic Editor
  • Eclipse Editor Plugin
  • Hyperlinks
  • Text hovers
  • Syntax highlighting
  • Outline with bidirectional synchronization

19
Textual Generic Editor
  • Language definition is an EMF model specifying
  • Comment blocks,
  • Keywords list,
  • Highlighting format (font and color),
  • ? Can be generated by TCS2Editor.atl.
  • Outline definition is an EMF model specifying
  • Nodes to display,
  • Label format,
  • Can be generated by KM32Outline.atl.
  • Uses TCS-generated parser
  • To populate the outline,
  • To provide text hovers and hyperlinks.

20
Conclusion
  • Modeling using a DSL can be done textually.
  • Specifying a bidirectional mapping between a
    metamodel and a textual syntax is possible and
    rather straightforward using TCS.
  • TCS has been used for several DSLs KM3, TCS,
    ATL, ACG, AM3, Editor, SQLDDL, etc.
  • HUTN has been partially implemented with a
    KM32TCS.atl transformation.
  • Eclipse-based textual editor (TGE) for free.

21
Conclusion, continued
  • Although only the textual syntax is presently
    used to create TCS models, it could be defined in
    some other way (for instance using weaving).
  • Some current limitations
  • Code formatting is specified with the syntax,
  • Text-to-model traceability is added in the target
    model,
  • Grammar ambiguities are not traced back to TCS
    constructs,
  • TCS is meant to provide textual syntaxes for
    DSLs, when one can make compromises on the
    textual syntax,
  • It may not be usable to parse Java or C code,
    although it may be usable to serialize such code
    (there are less constraints in this direction),
  • More complex cases could probably be dealt with
    using weaving between grammars and metamodels.

22
End of the presentation
  • Thanks
  • Questions?
  • Comments?
  • AMMA_at_lina.univ-nantes.fr
  • ATLAS group, INRIA LINA, Nantes
Write a Comment
User Comments (0)
About PowerShow.com