Ask Your Question
0

Implode Error: 'Cannot find a constructor'

asked Jan 09

Hossein gravatar image Hossein
81 8 20

updated Jan 09

Consider this file:

module Loader

import ParseTree;

import AbstractSyntaxes;
import ConcreteSyntaxes;
import Parser;

data IntermediateHeap = nheap(str name, list[Binding] bs)
                      | uheap(str name, IntermediateHeap h, list[Binding] ebs);

public Heap to_heap(nheap(n, bs)) = norm_heap(n, (b.name: b.exp | b <- bs));
public Heap to_heap(uheap(n, ih, ebs)) = union_heap(n, to_heap(ih), (b.name: b.exp | b <- ebs));

public AbstractSyntaxes::Heap implode(ConcreteSyntaxes::Heap h) =
    to_heap(implode(#IntermediateHeap, h));
public AbstractSyntaxes::Heap load_heap(loc l) = implode(parse_heap(l));

Regardless of what the contents of my other files are, the constructor IntermediateHeap is visibly present here in this very file. Despite that, I get the following very strange load error:

rascal>load_heap(heaps_file);
project://Launch2/src/Loader.rsc:16,9: IllegalArgument(..., "Cannot find a constructor IntermediateHeap")
stacktrace:
    somewhere in: public org.eclipse.imp.pdb.facts.IValue org.rascalmpl.library.ParseTree.implode(org.eclipse.imp.pdb.facts.IConstructor,org.eclipse.imp.pdb.facts.IConstructor)
    somewhere in: implode
    somewhere in: load_heap
    somewhere in: $shell$

Any ideas at all? (Sorry the full error message didn't seem to fit reasonably in this posting. Let me know if you're interested and I'll see how I can coerce it...)

Here is my concrete syntax:

module ConcreteSyntaxes

lexical Ident =  [a-zA-Z][a-zA-Z0-9]* !>> [a-zA-Z0-9];
lexical LAYOUT = [\t-\n\r\ ];
layout LAYOUTLIST = LAYOUT*  !>> [\t-\n\r\ ] ;

start syntax Heap = norm_heap: Ident "=" "{" {HeapBinding ","}* "}"
                  | union_heap: Ident "=" "(" Ident "," {HeapBinding ","}* ")";

syntax HeapBinding = bind: Ident "|-\>" Exp;

syntax Exp = var: Ident
           | lam: "\\" Ident "." Exp
           | app: Exp Ident
           | bracket "(" Exp ")"
           | let: "let" {Binding ","}* "in" Exp;

syntax Binding = binding: Ident "=" Exp;
delete close flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
2

answered Jan 09

DavyLandman gravatar image DavyLandman flag of Netherlands
267 4 17
http://homepages.cwi.nl/~...

updated Jan 09

Look at the documentation of implode, it says:

An IllegalArgument exception is thrown if during implosion a tree is encountered that cannot be imploded to the expected type in the ADT.

And it also gives the most likely reason:

As explained above, this function assumes that the ADT type names correspond to syntax non-terminal names, and constructor names correspond to production labels.

So it sees IntermediateHeap but cannot find this in the CST, so it fails to implode.

link delete flag offensive edit

Comments

I've just added my CST. Hopefully, we'll hunt the matter down. But, maybe this is yet another misleading error message. If the matter is the mismatch you're referring to, then, the error message shouldn't be saying that it can't find IntermediateHeap, should it?

Hossein (Jan 09)edit

Yes, I can confirm that the problem is now fixed. Thanks! I would also like to thank you for helping me demystify the error message; I wish there was a pointer in the error message to the appropriate part of the documentation to follow. Alternatively, the error message could have been more specific.

Hossein (Jan 09)edit

Hi @Hossein, well the only tip I can give you is, read the documentation, we are working hard on updating it. If you feel we could improve it (or the message) leave a comment there.

DavyLandman (Jan 10)edit

Your answer

Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
[hide preview]
Also see the Rascal Tutor.

Question tools

Follow

subscribe to rss feed

Stats

Asked: Jan 09

Seen: 18 times

Last updated: Jan 09