Previous: , Up: Genparse File Syntax   [Contents][Index]

4.4 Genparse File Grammar

In order to better understand the subtleties of the Genparse file format and its parsing, in the section we provide the formal grammar of Genparse files. This is a slightly edited version of the bison grammar. Items in capitals are tokens that are defined in the lex file.

all: globals entries usages

globals: /* empty */
        | globals global
        | global

global: include 
        | mandatory 
        | exit_value
        | break_lines
        | export_long_options
        | no_struct
        | global_callback

include: #include <FILENAME>

mandatory: #mandatory <FILENAME>

exit_value: #exit_value <VALUE>

break_lines: #break_lines <WIDTH>

export_long_options: #export_long_options

no_struct: #no_struct

global_callback: callback 

entries: entries entry
        | entry

entry: new_entry
        | gp_include

new_entry: param type options

options: options option
        | option

option: default
        | range 
        | callback 
        | descs
        | store_longindex
        | err_msg
        | comment
        | code_lines

descs: descs desc
        | desc

err_msg: __ERR_MSG__ ( ALNUM )
        | __ERR_MSG__ ( QUOTED )

comment: __COMMENT__ ( COMMENT_STR )

gp_include: #gp_include <FILE>

param: short_params
        | NONE / long_param
        | short_params / long_param

short_params: VAR
        | VAR *
        | VAR !

long_param: multi_long_option
	| multi_long_option mandatory_opt_name
	| multi_long_option optional_opt_name

mandatory_opt_name: EQUAL C_VAR
	| EQUAL OPT_NAME

optional_opt_name: [ mandatory_opt_name ]

multi_long_option: VAR
        | VAR *
        | VAR !

type: INT      
        | LONG
        | ULONG
        | INTMAX
        | UINTMAX
        | FLOAT
        | DOUBLE
        | STRING
        | CHAR  
        | FLAG  

default: ALNUM 
        | CHAR_VAL
        | QUOTED_STR

range: [ contiguous_range ]

contiguous_range: ALNUM range_spec more_range 
        | range_spec more_range

more_range: ALNUM
        | C_VAR
        |

range_spec: .. 
        | ...

callback: VAR ()

description: QUOTED_STR 

usages: /* empty */
	| usages usage
	| usage

usage: USAGE_STR

code_lines: code_lines code_line
	| code_line

code_line: single_code_line CODE_END
	| CODE_END
	;

single_code_line: CODE_LINE
	| OPEN_ROUND_BRACE
	| CLOSE_ROUND_BRACE
	| single_code_line single_code_line

Previous: , Up: Genparse File Syntax   [Contents][Index]