19.11.2014 Views

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - CiteSeerX

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 9<br />

Traits<br />

Traits are declared by trait declarations. Traits define new named types. A trait specifies a collection of methods<br />

(described in Section 9.2). One trait can extend others, which means that it inherits the methods from those traits, and<br />

that the type defined by that trait is a subtype of the types of traits it extends.<br />

9.1 Trait Declarations<br />

Syntax:<br />

TraitDecl ::= TraitHeader (MdDecl | AbsFldDecl | PropertyDecl) ∗ end<br />

TraitHeader ::= TraitMod ∗ trait Id [StaticParams] [Extends] [Excludes] [Comprises] [Where]<br />

Extends ::= extends TraitTypes<br />

Excludes ::= excludes TraitTypes<br />

Comprises ::= comprises MayTraitTypes<br />

TraitTypes ::= TraitType<br />

| { TraitTypeList }<br />

TraitTypeList ::= TraitType ( , TraitType) ∗<br />

MayTraitTypes ::= {}<br />

| TraitTypes<br />

TraitType ::= DottedId [StaticArgList ]<br />

| { TypeRef ↦→ TypeRef }<br />

| 〈 TypeRef 〉<br />

| TypeRef [ [ArraySize] ]<br />

| TypeRef [ MatrixSize ]<br />

ArraySize ::= Extent (, Extent) ∗<br />

Extent ::= NatRef<br />

| NatRef # NatRef<br />

MatrixSize ::= NatRef (× NatRef ) +<br />

Syntactically, a trait declaration starts with an optional sequence of modifiers followed by the special reserved word<br />

trait , followed by the name of the trait, an optional sequence of static parameters (described in Chapter 11), an<br />

optional set of extended traits, an optional set of excluded traits, an optional set of comprises on the trait, an optional<br />

where clause (described in Section 11.6), a list of method declarations, abstract field declarations, and property<br />

declarations (described in Section 19.6), and finally the special reserved word end .<br />

Each of extends , excludes , and comprises clauses consist of the special reserved word extends , excludes ,<br />

and comprises respectively followed by a set of trait references separated by commas and enclosed in braces ‘{’ and<br />

70

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!