19.11.2014 Views

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - CiteSeerX

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

sql<br />

SELECT spectral class FROM stars<br />

end<br />

would be expanded into the following <strong>Fortress</strong> SyntaxTree:<br />

Call(Empty,<br />

List(VarRef(Identifier(“SqlQuery”)),<br />

Call(Empty,<br />

List(VarRef(Identifier(“Select”)),<br />

String(“spectral_class”))),<br />

Call(Empty,<br />

List(VarRef(Identifier(“From”)),<br />

String(“stars”)))))<br />

(<strong>The</strong> Empty lists passed to Calls are the lists of static parameters to these calls). Note that this SyntaxTree corresponds<br />

to the following <strong>Fortress</strong> concrete syntax:<br />

SqlQuery(Select(“spectral_class”), From(“stars”))<br />

36.2 Declarations of Syntax Expanders<br />

Syntax:<br />

AbsDecl ::= AbsExternalSyntax<br />

AbsExternalSyntax ::= syntax OpenExpander Id CloseExpander<br />

A declaration of a syntax expander is syntactically identical to the definition of a syntax expander, except that =<br />

and the body of the expander (i.e., the expression following the = sign in an expander definition) are elided. Syntax<br />

expander declarations must occur only in APIs. A component that exports an API A must provide, for each syntax<br />

expander declaration d in A, a syntax expander definition with a header identical to d.<br />

36.3 Restrictions on Delimiters<br />

Consider the set S of syntax expander declarations imported by a component or API B, along with the syntax expanders<br />

defined or declared in B directly. Every expander in S must have a distinct opening delimiter, or it is a static<br />

error. Moreover, the terminating delimiter of each syntax expander must be distinct from every opening delimiter of<br />

every syntax expander in S, or it is a static error.<br />

36.4 Processing Syntax Expanders<br />

In a given component, only syntax expander declarations appearing in APIs imported by the component may be used.<br />

A component exporting an API A that includes a syntax expander must not import APIs that are not also imported by<br />

A, or it is a static error. This restriction ensures that all names in scope of the definition of the syntax expander are also<br />

in scope of any component importing the syntax expander in A. Additionally, all use sites of a syntax expander must<br />

occur in simple components other than the defining component. Furthermore, multiple components containing syntax<br />

expanders must not be cyclically linked. <strong>The</strong>se restrictions avoid pathologies with nontermination during expansion.<br />

Finally, to maintain proper separation of test code, a syntax expander definition is statically forbidden from referring<br />

to variables or functions that have modifier test .<br />

242

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

Saved successfully!

Ooh no, something went wrong!