Thursday, July 06, 2006

 

Indexing clauses and syntax errors

EiffelStudio supports an extension that allows multiple indexing clauses within an Eiffel class. You can have one at the top of the class, plus one at the bottom of the class, and you can also write an indexing clause for any feature of the class.

This can lead to a syntax error, which has become a "Frequently Asked Question" over on the es-devel mailing list. Consider the following code:
class A
...
feature -- Test
test: ANY
-- Test
indexing
...
end -- class A
How does the compiler know whether this indexing clause is the "end-of-class" indexing clause, or the one associated with the attribute 'test'?

The compiler can't tell, and it throws a syntax error. You can fix this with a judiciously-placed semicolon, for example:
class A
...
feature -- Test
test: ANY;
-- Test
indexing
...
end -- class A
Now, the indexing clause is taken to be the "end-of-class" indexing clause.

ECMA Eiffel does not have this ambiguity, because it does not support the "indexing" clause. Instead, it supports the "Notes" construct, which uses the "note" keyword. This construct can appear at the top or bottom of a class, but not with a feature.

Comments:
Note that `Note' did not make it into features in this first revision of standard to accomadate some other Eiffel compilers. But will most likely make it at some point.
 
Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?