iguana-parser / iguana

prototype parser run-time, back-end for different kinds of parser generators, including rascal.
51 stars 15 forks source link

Cannot parse "iggy.json" correctly? #15

Open paulzfm opened 5 years ago

paulzfm commented 5 years ago

Hi, I am planning to use your iguana parser to perform GLL parsing. I download the latest commit (https://github.com/iguana-parser/iguana/commit/5b7dce5f6f89e4047f828232dbfe71fbb82f7570) in master branch and build a jar (ignoring all test cases).

However, I have no idea how the CLI works (it seems only .json grammars are supported?), so I read the tutorial in this link and write my own test code (I have added a new file Main.java):

package org.iguana;

import org.iguana.grammar.Grammar;
import org.iguana.iggy.IggyParser;

import java.io.IOException;

public class Main {
    public static void main(String[] args) {
        try {
            Grammar g = IggyParser.getGrammar(PATH_TO_Simple.iggy); // Main.java:11
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

I create a iggy grammar file "Simple.iggy" according to the tutorial:

A ::= A 'a' 
   |  'a'

However, the program crashes:

Exception in thread "main" java.lang.RuntimeException: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "category" (class org.iguana.grammar.symbol.Terminal$Builder), not marked as ignorable (9 known properties: "label", "regex", "postConditions", "name", "nodeType", "object", "terminalPostConditions", "preConditions", "terminalPreConditions"])
 at [Source: (String)"{"kind":"Rule","head":{"kind":"Nonterminal","name":"Symbol","parameters":["p"]},"body":[{"kind":"Terminal","name":"ignore","category":"Keyword","regex":{"kind":"Seq","symbols":[{"kind":"Char","val":105},{"kind":"Char","val":103},{"kind":"Char","val":110},{"kind":"Char","val":111},{"kind":"Char","val":114},{"kind":"Char","val":101}]}},{"kind":"Nonterminal","name":"Layout"},{"kind":"Nonterminal","name":"Symbol","variable":"r","arguments":[{"kind":"Integer","value":3}]},{"kind":"Return","name":"{(r"[truncated 397 chars]; line: 1, column: 136] (through reference chain: org.iguana.grammar.symbol.Rule$Builder["body"]->java.util.ArrayList[0]->org.iguana.grammar.symbol.Terminal$Builder["category"])
    at org.iguana.iggy.IggyParser.iggyGrammar(IggyParser.java:29)
    at org.iguana.iggy.IggyParser.getGrammar(IggyParser.java:47)
    at org.iguana.Main.main(Main.java:11)
Caused by: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "category" (class org.iguana.grammar.symbol.Terminal$Builder), not marked as ignorable (9 known properties: "label", "regex", "postConditions", "name", "nodeType", "object", "terminalPostConditions", "preConditions", "terminalPreConditions"])
 at [Source: (String)"{"kind":"Rule","head":{"kind":"Nonterminal","name":"Symbol","parameters":["p"]},"body":[{"kind":"Terminal","name":"ignore","category":"Keyword","regex":{"kind":"Seq","symbols":[{"kind":"Char","val":105},{"kind":"Char","val":103},{"kind":"Char","val":110},{"kind":"Char","val":111},{"kind":"Char","val":114},{"kind":"Char","val":101}]}},{"kind":"Nonterminal","name":"Layout"},{"kind":"Nonterminal","name":"Symbol","variable":"r","arguments":[{"kind":"Integer","value":3}]},{"kind":"Return","name":"{(r"[truncated 397 chars]; line: 1, column: 136] (through reference chain: org.iguana.grammar.symbol.Rule$Builder["body"]->java.util.ArrayList[0]->org.iguana.grammar.symbol.Terminal$Builder["category"])
    at com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:61)
    at com.fasterxml.jackson.databind.DeserializationContext.handleUnknownProperty(DeserializationContext.java:823)
    at com.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:1153)
    at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperty(BeanDeserializerBase.java:1589)
    at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownVanilla(BeanDeserializerBase.java:1567)
// and so on

I tried to browse the code and I guess the problem is caused by a failure in parsing the json file IggyParser.class.getResourceAsStream("/iggy.json"), in file iguana/src/org/iguana/iggy/IggyParser.java.

I have no idea if I did the right thing to build a parser (for some customized grammar) using iguana? Or do you have clearer documents explaining the usage?

Thanks.