String and Character tokens in intellij grammar-kit BNF grammar not recognised in PSI preview mode

Answered
0

I am trying to develop a language plugin for intellij and am using the Grammar-Kit an PSI plugins as per the tutorial. I have developed a simple BNF-based grammar, but it does not work in PSI preview. The grammar is below:

{
  parserClass="org.intellij.sdk.language.parser.ASTRAParser"

  extends="com.intellij.extapi.psi.ASTWrapperPsiElement"

  psiClassPrefix="ASTRA"
  psiImplClassSuffix="Impl"
  psiPackage="org.intellij.sdk.language.psi"
  psiImplPackage="org.intellij.sdk.language.psi.impl"

  elementTypeHolderClass="org.intellij.sdk.language.psi.ASTRATypes"
  elementTypeClass="org.intellij.sdk.language.psi.ASTRAElementType"
  tokenTypeClass="org.intellij.sdk.language.psi.ASTRATokenType"

  psiImplUtilClass="org.intellij.sdk.language.psi.impl.ASTRAPsiImplUtil"

  tokens=[
    space='regexp:\s+'
    comment='regexp:((/[*])([\s\S]+)([*]/))|([/]{2,}[^\n]+)'
    char="regexp:'.'"
    string='regexp:"([^"\\]|\\.)*"'
    id='regexp:\p{Alpha}\w*'

    PERIOD='.'
    COMMA=','
    SEMI=';'

    INT='int'
    LONG='long'
    FLOAT='float'
    DOUBLE='double'
    STRING='string'
    CHAR='char'
    BOOLEAN='boolean'
    FUNCT='funct'
    LIST='list'
  ]
}

astraFile ::= [package] agent
package ::= 'package' className SEMI
className ::= id (PERIOD id)*
agent ::= 'agent' id ['extends' id (COMMA id)*] '{' statement* '}'
statement ::= module | types | initial

module ::= 'module' className id SEMI

types ::= 'types' id '{' formula* '}'
formula ::= 'formula' signature SEMI
signature ::= id '(' [type (COMMA type)*] ')'

initial ::= 'initial' atom (COMMA atom)* SEMI
private atom ::= goal | predicate
goal ::= '!' predicate
predicate ::= id '(' string ')'
private arg ::= variable
    | literal
    | id
literal ::= string
variable ::= type id
type ::= INT | LONG | FLOAT | DOUBLE | STRING | CHAR | BOOLEAN | FUNCT | LIST | className

The test program is:

agent test {
    initial test("dd");
}

The error is 'string expected, got "dd":2'

Any help would be much appreciated.

0
4 comments
Avatar
Permanently deleted user

Hi Jakub,

Do you know if the list of reserved keywords is documented anywhere?

Rem

 

 

0

Generated PSI classes are Java files, so I'd go with the Java keywords list. You should also verify these files manually to make sure if the syntax is correct.

0
Avatar
Permanently deleted user

Now it all makes sense! Thanks

0

Please sign in to leave a comment.