gsdlab / clafer

Clafer is a lightweight modeling language
http://clafer.org
MIT License
45 stars 13 forks source link

Incorrect parsing of one-line declarations #11

Closed mantkiew closed 12 years ago

mantkiew commented 12 years ago

Clafer v0.1.21-12-2011

Desugaring the following incorrect model

abstract A B C 

abstract D extends A 

E F G

produces an incorrect model

abstract 0 .. * c1_A : clafer 0 .. * {  }
0 .. * c2_B : clafer 1 .. 1 {  }
0 .. * c3_C : clafer 1 .. 1 {  }
abstract 0 .. * c4_D : clafer 0 .. * {  }
0 .. * c5_extends : clafer 1 .. 1 {  }
0 .. * c6_A : clafer 1 .. 1 {  }
0 .. * c7_E : clafer 1 .. 1 {  }
0 .. * c8_F : clafer 1 .. 1 {  }
0 .. * c9_G : clafer 1 .. 1 {  }

but the compiler should produce a syntax error.

mantkiew commented 12 years ago

It would be, however, nice to have the one-liner notation:

abstract A

B, C, D : A
kbak commented 12 years ago

Is it a bug? No one said that clafers must be declared in new lines. I would say that what the translator generates is what I would expect it to generate. BTW, there is no 'extends' keyword anymore.

mantkiew commented 12 years ago

Hmmm. I don't know. I had an old model with "extends" and that's how I discovered this "feature" :-) I remember it used to be a syntax error.

I just updated the tutorial - among others I added a section about desugaring and added some rules about declarations that need to be in new line each.

Please have a look at "Clafer a bit more precisely" and "Desugaring".

http://gsd.uwaterloo.ca/node/310

I put this example

A
    B [
       ...
    ]

as incorrect because you don't know what is the context of the constraint.

How about

A  B
    C

should it be the same as

 A
     C
 B

or

 A
 B
     C

?

Currently, it's desugared to

0 .. * c1_A : clafer 1 .. 1 {  }
0 .. * c2_B : clafer 1 .. 1 {
  0 .. * c3_C : clafer 1 .. 1 {    }
  }

I'd say we should stick to one declaration per line. And introduce special convenience operator ; or | so that I can say

A
   xor B
      C ; D ; E
kbak commented 12 years ago

Ok, the above argument is good enough.

kbak commented 12 years ago

I tried to fix this issue by improving the grammar but the solution didn't work. Probably there is an issue with BNFC. I'm not going to spend more time on this problem now.

mantkiew commented 12 years ago

won't fix.