Skip to content

Commit

Permalink
Fixed bug introduced with the gadt fix
Browse files Browse the repository at this point in the history
darcs-hash:20060209142952-49d33-42e1414b77794f911b6d661388ca6b7dc0d399f7.gz
  • Loading branch information
thiagoarrais committed Feb 9, 2006
1 parent ec786f4 commit 6e8b306
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 4 deletions.
Expand Up @@ -119,7 +119,36 @@ public void testGroupDataDeclarationConstructors() {
assertSame(cons, dataDecl.getConstructors()[0]);
}

private IConstructor createConstructor() {
public void testDistributeConstructorsBetweenDataDeclarations() {
final IConstructor fstCons = createConstructor();
final IConstructor sndCons = createConstructor();

fBuilder.startModule();
fBuilder.startDataDeclaration();
fBuilder.addConstructor(fstCons);

fBuilder.startDataDeclaration();
fBuilder.addConstructor(sndCons);

final IModule module = fBuilder.getResult();

final IDeclaration[] decls = module.getDeclarations();
assertEquals(2, decls.length);
assertTrue(decls[0] instanceof IDataDeclaration);
assertTrue(decls[1] instanceof IDataDeclaration);

IDataDeclaration fstDataDecl = (IDataDeclaration) decls[0];
IConstructor[] fstConstructorGroup = fstDataDecl.getConstructors();
assertEquals(1, fstConstructorGroup.length);
assertSame(fstCons, fstConstructorGroup[0]);

IDataDeclaration sndDataDecl = (IDataDeclaration) decls[1];
IConstructor[] sndConstructorGroup = sndDataDecl.getConstructors();
assertEquals(1, sndConstructorGroup.length);
assertSame(sndCons, sndConstructorGroup[0]);
}

private IConstructor createConstructor() {
return new Constructor();
}

Expand Down
Expand Up @@ -528,6 +528,32 @@ public void testDataLocationRecording() throws RecognitionException, TokenStream
assertEquals(3, srcLoc.getLine());
assertEquals(2, srcLoc.getColumn());
}

public void testConsecutiveADTDeclarations() throws RecognitionException, TokenStreamException {
final String input = "module Nature where\n" +
"\n" +
"data Gender = Male | Female\n" +
"data Temperature = Cold | Warm | Hot";
IModule module = parse(input);

IDeclaration[] decls = module.getDeclarations();
assertEquals(2, decls.length);
assertTrue(decls[0] instanceof IDataDeclaration);
assertTrue(decls[1] instanceof IDataDeclaration);

IDataDeclaration fstDataDecl = (IDataDeclaration) decls[0];
IConstructor[] fstConstructorGroup = fstDataDecl.getConstructors();
assertEquals(2, fstConstructorGroup.length);
assertEquals("Male", fstConstructorGroup[0].getName());
assertEquals("Female", fstConstructorGroup[1].getName());

IDataDeclaration sndDataDecl = (IDataDeclaration) decls[1];
IConstructor[] sndConstructorGroup = sndDataDecl.getConstructors();
assertEquals(3, sndConstructorGroup.length);
assertEquals("Cold", sndConstructorGroup[0].getName());
assertEquals("Warm", sndConstructorGroup[1].getName());
assertEquals("Hot", sndConstructorGroup[2].getName());
}

public void testNewtypeLocationRecording() throws RecognitionException, TokenStreamException {
// sample code from darcs source code
Expand Down
Expand Up @@ -393,12 +393,12 @@ constrs

constr
{
Constructor aConstructor = createNode(Constructor.class);
fBuilder.addConstructor(aConstructor);

Constructor aConstructor = null;
String name = null;
}
:
{ aConstructor = createNode(Constructor.class);
fBuilder.addConstructor(aConstructor); }
name=con { aConstructor.setName(name); }
(block | ~(SEMICOLON|ALT|RIGHT_CURLY))*
;
Expand Down
@@ -1,7 +1,13 @@
package net.sf.eclipsefp.haskell.core.jparser;

import de.leiffrenzel.fp.haskell.core.halamo.IConstructor;
import net.sf.eclipsefp.haskell.core.jparser.ast.DataDeclaration;

class NullDataDeclaration extends DataDeclaration {

@Override
public boolean accepts(IConstructor cons) {
return false;
}

}

0 comments on commit 6e8b306

Please sign in to comment.