Ask Your Question
1

Can you explain this parse error at end of file?

asked Jan 01

Hossein gravatar image Hossein
81 8 20

updated Jan 05

JurgenVinju gravatar image JurgenVinju flag of Netherlands
554 6 20
http://jurgen.vinju.org/

With the following "concrete" syntax:

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;

And you need this information as well:

module HeapParser

import HeapConcreteSyntax;
import ParseTree;

public Heap parse_heap(loc l) = parse(#Heap, l);

module HeapLoader

import HeapConcreteSyntax;
import Heap;
import HeapParser;
import ParseTree;

public Heap::Heap implode(HeapConcreteSyntax::Heap p) = implode(#Heap::Heap, p);
public Heap::Heap load_heap(loc l) = implode(parse_heap(l));

When I try to load a file containing the following sole line:

D = (G, x1 |-> \x.x, x2 |-> \y.y)

I get the following cryptic error message:

rascal>load_heap(heaps_file);
project://Launchbury/src/HeapParser.rsc:6,32: ParseError(|file://.../input_heaps.launchburry|(34,0,<1,34>,<1,34>))
stacktrace:
    /src/HeapParser.rsc:6,32
    somewhere in: parse_heap
    somewhere in: load_heap
    somewhere in: $shell$
    somewhere in: public org.eclipse.imp.pdb.facts.IValue org.rascalmpl.library.ParseTree.parse(org.eclipse.imp.pdb.facts.IConstructor,org.eclipse.imp.pdb.facts.ISourceLocation,org.rascalmpl.interpreter.IEvaluatorContext)
    somewhere in: parse_heap
    somewhere in: load_heap
    somewhere in: $shell$

Any idea?

delete close flag offensive retag edit

Comments

Hi Hossein, I apologize for so rudely removing all the answers, but this discussion needed some redesign to be understandable for others. We should definitely not use the answers to discuss. We can always edit an original question to clarify and use the comments to ask for clarification. Thanks!

JurgenVinju (Jan 05)edit

And thanks for the great questions!

JurgenVinju (Jan 05)edit

Hi Jurgen. No problem with the removal. I didn't find that rude. In addition to learning Rascal itself, here, I am after all learning the proper etiquette of this forum too. :) I wish there was some automatic notification about these changes as well as other placing comments on one's post.

Hossein (Jan 08)edit

2 Answers

Sort by ยป oldest newest most voted
1

answered Jan 05

JurgenVinju gravatar image JurgenVinju flag of Netherlands
554 6 20
http://jurgen.vinju.org/

Let me start again. I have removed previous answers and comments and will provide different answers for the different questions embedded.

The parse error is caused by choosing the non-terminal Heap in:

public Heap parse_heap(loc l) = parse(#Heap, l);

This means that the top of the file needs to be a Heap, and a Heap does not end with whitespace or comments, but rather with a "}" or a ")".

To be able to accept whitespace at the end and the beginning of a file, Rascal provides start non-terminals, generated automatically for all non-terminals labeled with the start modifier:

start syntax Heap = ...

It generates the following rule for you (since you defined a layout non-terminal called LAYOUT):

syntax start[Heap] = layout[LAYOUT] Heap top layout[LAYOUT];

Now you can call the parser by giving the start[Heap] non-terminal instead:

public start[Heap] parse_heap(loc l) = parse(#start[Heap], l);

This will produce a value of type start[Heap], which has a field named "top", so instead you could do:

public Heap parse_heap(loc l) = parse(#start[Heap], l).top;
link delete flag offensive edit

Comments

OK, this does the parsing. Yet, when I try to load, I get an exception:

rascal>loadheap(inputheaps); project://Launchbury/src/HeapLoader.rsc:8,56: IllegalArgument(appl(prod(lex("Ident"),[\char-class([range(65,90),range(97,122)]),conditional(\iter-star(\char-class([range(48,57),range(65,90),range(97,122)])),{\not-follow(\char-class([range(48,57),range(65,90),range(97,122)]))})],{}),[char(71),appl(regular(\iter-star(\char-class([range(48,57),range(65,90),range(97,122)]))),[])[@loc=|file:///home/hossein/Documents/Rascal/TeachMyself/Launchbury/inputheaps.launchburry|(6,0,<1,6>,<1,6>)]])[@loc=|file:///home/hossein/Documents/Rascal/TeachMyself/Launchbury/inputheaps.launchburry|(5,1,<1,5>,<1,6>)],"Missing lexical constructor") 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$

Hossein (Jan 08)edit

OK, this does the parsing. Yet, when I try to load, I get an exception:

Hossein (Jan 08)edit

Should I fork a separate thread? Or, should we follow up right in the current one? BTW, this 'comment' mechanism is too restrictive -- as opposed to the 'reply' one -- and, not suitable at all for discussion.

Hossein (Jan 08)edit

rascal>loadheap(inputheaps); project://Launchbury/src/HeapLoader.rsc:8,56: IllegalArgument(appl(prod(lex("Ident"),[\char-class([range(65,90),range(97,122)]),conditional(\iter-star(\char-class([range(48,57),range(65,90),range(97,122)])),{\not-follow(\char-class([range(48,57),range(65,90),range(97,122)]))})],{}),[char(71),appl(regular(\iter-star(\char-class([range(48,57),range(65,90),range(97,122)]))),[])[@loc=|file:///home/hossein/Documents/Rascal/TeachMyself/Launchbury/inputheaps.launchburry|(6,0,<1,6>,<1,6>)]])[@loc=|file:///home/hossein/Documents/Rascal/TeachMyself/Launchbury/inputheaps.launchburry|(5,1,<1,5>,<1,6>)],"Missing lexical constructor") 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$

Hossein (Jan 08)edit

Hi Hossein, this definitely looks confusing. Could you start another thread? It looks like a message from the implode function. Also, while you're at it, could you flag the current answers when/if you are happy with them? Cheers!

JurgenVinju (Jan 30)edit
0

answered Jan 05

JurgenVinju gravatar image JurgenVinju flag of Netherlands
554 6 20
http://jurgen.vinju.org/

updated Jan 05

This answer explains the cryptic error message and how to deal with it programmatically.

project://Launchbury/src/HeapParser.rsc:6,32: ParseError(|file://.../input_heaps.launchburry|(34,0,<1,34>,<1,34>))
stacktrace:
    /src/HeapParser.rsc:6,32
    somewhere in: parse_heap
    somewhere in: load_heap
    somewhere in: $shell$
    somewhere in: public org.eclipse.imp.pdb.facts.IValue org.rascalmpl.library.ParseTree.parse(org.eclipse.imp.pdb.facts.IConstructor,org.eclipse.imp.pdb.facts.ISourceLocation,org.rascalmpl.interpreter.IEvaluatorContext)
    somewhere in: parse_heap
    somewhere in: load_heap
    somewhere in: $shell$

What you see here is a Rascal exception thrown by the parse function. It is intended for you to catch, so you can provide a proper message to the user. All Rascal exceptions that are thrown but not caught end up being printed in the console like this.

Here is an example on how to catch and print a messsage to the user:

try {
    Heap heap = parse(#Heap, l);
    // do what is needed with heap
}
catch ParseError(loc here): {
   println("Found a parse error on line: <here.begin.line>, column: <here.begin.column>");
}
link delete flag offensive 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
1 follower

subscribe to rss feed

Stats

Asked: Jan 01

Seen: 37 times

Last updated: Jan 22