cenotelie / hime

Apache License 2.0
27 stars 4 forks source link

Proper use of the Hime SDK #109

Open xuanbachle opened 1 month ago

xuanbachle commented 1 month ago

I can not get the SDK CompilationTask to work properly to generate an in memory parser for the MathExp.gram example. I keep getting: ParseErrors { errors: [UnexpectedToken(ParseErrorUnexpectedToken { position: TextPosition { line: 1, column: 1 }, length: 1, value: "1", terminal: Symbol { id: 7, name: "NUMBER" }, expected: [Symbol { id: 17, name: "-" }] })] }

when I tried to use the in memory parser to parse a simple "1 + 2" input. Part of my code to get the in memory parser is below:

                        let data = l.grammars[0].build(Some(ParsingMethod::LR1), 0);
                        //println!("{:?}", data);
                        match data {
                            Ok(d) => {
                                match output::build_in_memory_grammar(&l.grammars[0], &d) {
                                    Ok(parser) => {

                                        let res = parser.parse("1 + 2");
                                        println!("{:?}", res.errors);
                                        print(res.get_ast().get_root(), &[]);

What should I do to get this work?