Parser not reducing expressions


I'm writing a custom language plugin for Coq language and I've already implemented a lexer and syntax highlighting
Now I'm trying to write a parser but I can't get it to work, the problem is that it doesn't reduce expressions. It just parses a PsiFile and a list of PsiElement under it, though those elements are well recognized it doesn't group them following the syntax tree.
I simplified the bnf definition to see if I was doing something wrong, but it doesn't work anyways.

This is my simplified bnf:




coqFile ::= sentence *

sentence ::= definition_expr | parameter_expr | comment_expr

definition_expr ::= DEFINITION PARAMETER


comment_expr ::= COMMENT

This is what gets parsed (using PsiViewer):
Test file contains this text:
Definition Parameter
(* comment *)
Parameter a: a;
Parameter a: a;
Parameter a: a;
Definition Parameter

Any idea what I could be doing wrong? Thanks!

I'm using Idea IC-123.72 and JDK 1.6.0_32 on Ubuntu 12.04.

Comment actions Permalink

1. Grammar-Kit parser expects lexer to emit tokens defined in (generated to)


You can always check these kind of problems using debugger by placing breakpoint in GPUB.consumeToken() method.
Please make sure that the lexer really returns all those token types.
I think this should fix correct COQ sequences parsing. The part below should help in handling the rest.

2. Please read Error recovery section in the Grammar-Kit documentation or tutorial page.
Without corresponding pin & recoverUntil attributes the grammar will match correct token sequenses only.
And PSI Viewer again will show just a list of tokens.

Comment actions Permalink

It worked, I had my token types defined twice so they weren't matching.
Thank you for your quick and precise response! :)


Please sign in to leave a comment.