antlr4 - How to make an "global parser rule"? -
i'm building grammar parsing quake iii shaders antlr4.
here's exemple of shader:
textures/liquids/lava-example { deformvertexes wave sin 0 3 0 0.1 q3map_tesssize 64 surfaceparm lava qer_editorimage textures/common/lava.tga { map textures/common/lava.tga } }
as can see, structure is:
shadername { directive directive //.... { directive //... } }
my question
as can see, directive composed key , parameters. keys , parameters known (more 100 keys possible). wonder how set global rule directive (key + parameters) , specify of them beside of it. moreover, if can separate of them in different files keeping clean grammars, better.
what have now
parser grammar shaderparser; options { tokenvocab=shaderlexer; } shaderlist : shader+ ; shader : shadername lbracket directive* stage* rbracket ; shadername : path compiletime? ; stage : lbracket directive* rbracket ; directive : key parameter? | key dquote parameter dquote | key squote parameter squote ; key : word ; parameter : word | integer | double | path ;
the directive, key , parameter (a single 1 testing) rules getting main grammar.
thanks help!
the grammar seems need newlines statement separators. should add them @ end of each directive. parameters can match grammar 1 @ most.
shader : shadername newline lbracket newline directive* stage* rbracket newline? eof ; shadername : path compiletime? ; stage : lbracket newline directive* rbracket newline ; directive : key maybequotedparameter* newline ; maybequotedparameter : parameter? | dquote parameter dquote | squote parameter squote ; key : word ; parameter : word | integer | double | path ;
Comments
Post a Comment