jamesrhester / Lerche.jl

A Julia port of the Lark parser
MIT License
45 stars 3 forks source link

Using an undefined rule: start #11

Closed kskyten closed 3 years ago

kskyten commented 3 years ago

I tried to use the tartiflette Lark grammar for Graphql with

const GRAMMAR = read("grammar.lark", String)
const Parser = Lark(GRAMMAR, parser="lalr", lexer="contextual")

This gives the following error message:

ERROR: LoadError: Lerche.GrammarError("Using an undefined rule: start")
Stacktrace:
 [1] init_analyser!(::Lerche.LALR_Analyzer, ::Lerche.ParserConf; debug::Bool) at ~/.julia/packages/Lerche/rO9vr/src/parsers/grammar_analysis.jl:187                                          
 [2] Lerche.LALR_Analyzer(::Lerche.ParserConf; debug::Bool) at ~/.julia/packages/Lerche/rO9vr/src/parsers/lalr_analysis.jl:140                                             
 [3] Lerche.LALRParser(::Lerche.ParserConf; debug::Bool) at ~/.julia/packages/Lerche/rO9vr/src/parsers/lalr_parser.jl:46                                                
 [4] Lerche.LALR_ContextualLexer(::Lerche.LexerConf, ::Lerche.ParserConf; options::Lerche.LarkOptions) at ~/.julia/packages/Lerche/rO9vr/src/parser_frontends.jl:102                                                  
 [5] _build_parser(::Lerche.LarkOptions, ::Array{Lerche.Rule,1}, ::Lerche.LexerConf) at ~/.julia/packages/Lerche/rO9vr/src/lark.jl:227                                                              
 [6] Lerche.Lark(::String, ::Dict{String,Any}, ::String, ::String) at ~/.julia/packages/Lerche/rO9vr/src/lark.jl:197                                                              
 [7] Lerche.Lark(::String; options::Base.Iterators.Pairs{Symbol,String,Tuple{Symbol,Symbol},NamedTuple{(:parser, :lexer),Tuple{String,String}}}) at ~/.julia/packages/Lerche/rO9vr/src/lark.jl:121                   
 [8] top-level scope at ~/src/github.com/kskyten/GraphQL/src/GraphQL.jl:6
 [9] include(::Function, ::Module, ::String) at ./Base.jl:380
 [10] include(::Module, ::String) at ./Base.jl:368
 [11] top-level scope at none:2
 [12] eval at ./boot.jl:331 [inlined]
 [13] eval(::Expr) at ./client.jl:467
 [14] top-level scope at ./none:3
in expression starting at ~/src/github.com/kskyten/GraphQL/src/GraphQL.jl:6
ERROR: Failed to precompile GraphQL [3fab2794-5d30-4b3b-b133-1ffc1d4718cd] to ~/.julia/compiled/v1.5/GraphQL/JXO19_ccLnE.ji.
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] compilecache(::Base.PkgId, ::String) at ./loading.jl:1305
 [3] _require(::Base.PkgId) at ./loading.jl:1030
 [4] require(::Base.PkgId) at ./loading.jl:928
 [5] require(::Module, ::Symbol) at ./loading.jl:923

However, the grammar does not even contain the word start.

jamesrhester commented 3 years ago

The top level grammar rule needs to be stated explicitly, unless it is named "start". So you should call the parser as follows:

Lark(GRAMMAR, parser="lalr", lexer="contextual",start="document")

assuming document is the top-level rule. Python Lark should also require the "start" option for this grammar.

kskyten commented 3 years ago

Thanks! It works now.