2009-06-04 Vladimir Serbinenko <phcoder@gmail.com>

Script fixes

	* include/grub/script_sh.h (grub_script_cmdline): remove cmdline
	(grub_lexer_param): add tokenonhold
	(grub_script_create_cmdline): remove cmdline. All callers updated
	(grub_script_function_create): make functionname
	grub_script_arg. All callers updated
	(grub_script_execute_argument_to_string): new prototype
	* kern/parser.c (state_transitions): reorder
	(grub_parser_cmdline_state): fix a bug and make more compact
	* script/sh/execute.c (grub_script_execute_argument_to_string): 
	make global
	(grub_script_execute_cmdline): use new format
	* script/sh/function.c (grub_script_function_create): make functionname
	grub_script_arg. All callers updated
	* script/sh/lexer.c (grub_script_lexer_init): initilaize tokenonhold
	(grub_script_yylex): remove
	(grub_script_yylex2): renamed to ...
	(grub_script_yylex): ...renamed
	parse the expressions like a${b}c
	* script/sh/parser.y (GRUB_PARSER_TOKEN_ARG): new typed terminal
	(GRUB_PARSER_TOKEN_VAR): remove
	(GRUB_PARSER_TOKEN_NAME): likewise
	("if"): declare as typeless
	("while"): likewise
	("function"): likewise
	("else"): likewise
	("then"): likewise
	("fi"): likewise
	(text): remove
	(argument): likewise
	(script): accept empty scripts and make exit on error
	(arguments): use GRUB_PARSER_TOKEN_ARG
	(function): likewise
	(command): move error handling to script
	(menuentry): move grub_script_lexer_ref before
	* script/sh/script.c (grub_script_create_cmdline): remove cmdline 
	argument. All callers updated
This commit is contained in:
phcoder 2009-06-04 16:18:35 +00:00
parent f4448a0792
commit fda6cb987f
8 changed files with 304 additions and 280 deletions

View file

@ -42,13 +42,10 @@
%token GRUB_PARSER_TOKEN_ELSE "else"
%token GRUB_PARSER_TOKEN_THEN "then"
%token GRUB_PARSER_TOKEN_FI "fi"
%token GRUB_PARSER_TOKEN_NAME
%token GRUB_PARSER_TOKEN_VAR
%token GRUB_PARSER_TOKEN_ARG
%type <cmd> script_init script grubcmd command commands commandblock menuentry if
%type <arglist> arguments;
%type <arg> argument;
%type <string> "if" "while" "function" "else" "then" "fi"
%type <string> text GRUB_PARSER_TOKEN_NAME GRUB_PARSER_TOKEN_VAR
%type <arg> GRUB_PARSER_TOKEN_ARG;
%pure-parser
%lex-param { struct grub_parser_param *state };
@ -62,9 +59,18 @@ script_init: { state->err = 0; } script
}
;
script: commands { $$ = $1; }
script: { $$ = 0; }
| '\n' { $$ = 0; }
| commands { $$ = $1; }
| function '\n' { $$ = 0; }
| menuentry '\n' { $$ = $1; }
| error
{
$$ = 0;
yyerror (state, "Incorrect command");
state->err = 1;
yyerrok;
}
;
delimiter: '\n'
@ -76,61 +82,21 @@ newlines: /* Empty */
| newlines '\n'
;
/* Some tokens are both used as token or as plain text. XXX: Add all
tokens without causing conflicts. */
text: GRUB_PARSER_TOKEN_NAME
{
$$ = $1;
}
| "if"
{
$$ = $1;
}
| "while"
{
$$ = $1;
}
;
/* An argument can consist of some static text mixed with variables,
for example: `foo${bar}baz'. */
argument: GRUB_PARSER_TOKEN_VAR
{
$$ = grub_script_arg_add (state, 0, GRUB_SCRIPT_ARG_TYPE_VAR, $1);
}
| text
{
$$ = grub_script_arg_add (state, 0, GRUB_SCRIPT_ARG_TYPE_STR, $1);
}
/* XXX: Currently disabled to simplify the parser. This should be
parsed by yet another parser for readability. */
/* | argument GRUB_PARSER_TOKEN_VAR */
/* { */
/* $$ = grub_script_arg_add ($1, GRUB_SCRIPT_ARG_TYPE_VAR, $2); */
/* } */
/* | argument text */
/* { */
/* $$ = grub_script_arg_add ($1, GRUB_SCRIPT_ARG_TYPE_STR, $2); */
/* } */
;
arguments: argument
arguments: GRUB_PARSER_TOKEN_ARG
{
$$ = grub_script_add_arglist (state, 0, $1);
}
| arguments argument
| arguments GRUB_PARSER_TOKEN_ARG
{
$$ = grub_script_add_arglist (state, $1, $2);
}
;
grubcmd: GRUB_PARSER_TOKEN_NAME arguments
grubcmd: arguments
{
$$ = grub_script_create_cmdline (state, $1, $2);
}
| GRUB_PARSER_TOKEN_NAME
{
$$ = grub_script_create_cmdline (state, $1, 0);
$$ = grub_script_create_cmdline (state, $1);
}
;
@ -138,13 +104,6 @@ grubcmd: GRUB_PARSER_TOKEN_NAME arguments
command: grubcmd delimiter { $$ = $1; }
| if delimiter { $$ = $1; }
| commandblock delimiter { $$ = $1; }
| error delimiter
{
$$ = 0;
yyerror (state, "Incorrect command");
state->err = 1;
yyerrok;
}
;
/* A block of commands. */
@ -166,7 +125,7 @@ commands: command
executed on the right moment. So the `commands' rule should be
recognized after executing the `grub_script_mem_record; and before
`grub_script_mem_record_stop'. */
function: "function" GRUB_PARSER_TOKEN_NAME
function: "function" GRUB_PARSER_TOKEN_ARG
{
grub_script_lexer_ref (state->lexerstate);
} newlines '{'
@ -204,10 +163,10 @@ commandblock: '{'
;
/* A menu entry. Carefully save the memory that is allocated. */
menuentry: "menuentry" arguments
menuentry: "menuentry"
{
grub_script_lexer_ref (state->lexerstate);
} newlines '{'
} arguments newlines '{'
{
grub_script_lexer_record_start (state->lexerstate);
} newlines commands '}'
@ -215,7 +174,7 @@ menuentry: "menuentry" arguments
char *menu_entry;
menu_entry = grub_script_lexer_record_stop (state->lexerstate);
grub_script_lexer_deref (state->lexerstate);
$$ = grub_script_create_cmdmenu (state, $2, menu_entry, 0);
$$ = grub_script_create_cmdmenu (state, $3, menu_entry, 0);
}
;