Parser not reducing expressions
Hi!
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:
{
parserClass="com.qq.coqide.syntax.parser.CoqParser"
stubParserClass="com.qq.coqide.syntax.parser.GeneratedParserUtilBase"
extends="com.intellij.extapi.psi.ASTWrapperPsiElement"
psiClassPrefix="Coq"
psiImplClassSuffix="Impl"
psiPackage="com.qq.coqide.syntax.parser.psi"
psiImplPackage="com.qq.coqide.syntax.parser.psi"
elementTypeHolderClass="com.qq.coqide.syntax.parser.CoqTokenTypes"
elementTypeClass="com.qq.coqide.lexer.CoqElementType"
tokenTypeClass="com.qq.coqide.lexer.CoqTokenType"
}
coqFile ::= sentence *
sentence ::= definition_expr | parameter_expr | comment_expr
definition_expr ::= DEFINITION PARAMETER
parameter_expr ::= PARAMETER IDENT COLON IDENT SEMICOLON
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.
Please sign in to leave a comment.
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.
It worked, I had my token types defined twice so they weren't matching.
Thank you for your quick and precise response! :)