Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Xcore, xbase and EObject literals
Xcore, xbase and EObject literals [message #716075] Tue, 16 August 2011 11:46
Eclipse UserFriend
Originally posted by:

Hi,

I've been thinking of ways of creating EObjects in Xcore/Xbase. The
simplest way is supporting constructors and make the
compiler/interpreter use the appropriate factory. However, often you
want to create object graphs and that requires a lot of code.

There exists a standard notation for human-readable model instances,
called Human-Understandable Textual Notation (HUTN - see
http://www.omg.org/spec/HUTN/), that could provide a starting point.
Here's a simple example of a library Xcore model, followed by an
instance graph in something HUTN-like.

package no.hal.library

class Book {
BookKind kind
String title
refers Person[*] authors opposite books
}

enum BookKind {
novel, shortStory, fairyTale, play
}

class Person {
boolean author
String name
refers Book[*] books opposite authors
}

class Loan {
refers Book[*] books
refers Person borrower
}

class Library {
contains Book[*] books
contains Person[*] authors
contains Person[*] customers
contains Loan[*] loans
}

// HUTN-like syntax
Library {
books:
Book {
novel
title: "War and Peace"
authors: "Tolstoj"
}
authors:
author Person "Tolstoj" {
name: "Leo Tolstoj"
}
customers:
Person "Hallvard" {
~author
name: "Hallvard Trætteberg"
}
loans: Loan {
books: "War and Peace"
borrower: "Hallvard"
}
}

The syntax allows to create hierarchical structures, with cross
references using STRING IDs. The class name can be omitted, e.g. Book,
when you want an instance of the EReference's type and not a subclass.
There's a shorthand for boolean attributes, the attribute name means
true, prefix with ~ and you negate (e,g. ~author). You can also use an
enum literal directly to set a field typed to the corresponding enum,
e.g. novel above means kind: novel. These two shorthands can be used as
prefixes (adjectives), e.g. author Person. novel Book { ... } would mean
Book { novel } which is the same as Book { kind: novel }. The syntax
includes literals for numbers, characters and Strings and with String
support, all serializable EDataTypes can be supported.

I think this can be useful for Xcore/Xbase in two ways:
- expression syntax, as an extension of Xbase
- textual (file) format for instances, similar to XMI, but
human-write/readable

As an expression syntax, you should be able to include expressions for
attribute/reference values. E.g. you can imagine the following operation
in Library class above (the euro sign is used as a keyword), for adding
a Loan instances:

op void addLoan(Book book, Person borrower) {
val loan = € Loan {
books: book
borrower: borrower
}
loans.add(loan)
}

The operation creates and adds a Loan instance with the books and
borrower references set.

I have implemented the syntax above, and I'm now working on technical
issues related to how to handle this in the compiler/interpreter. I've
been thinking of translating it to another XExpression (a bit like macro
expansion) which when evaluated builds the instance graph, and tricking
the compiler/interpreter into using the alternative XExpression.

Ideas, comments, suggestions?

Hallvard
Previous Topic:[CDO] Cannot pass object as parameter into cdoquery
Next Topic:[Teneo] Missing mapping XML
Goto Forum:
  


Current Time: Fri Apr 19 20:42:10 GMT 2024

Powered by FUDForum. Page generated in 0.02172 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top