2006-17-04 Marco Gerards <marco@gnu.org>
* include/grub/script.h: Include <grub/parser.h> and "grub_script.tab.h". (struct grub_lexer_param): New struct. (struct grub_parser_param): Likewise. (grub_script_create_arglist): Pass the state in an argument. (grub_script_add_arglist): Likewise. (grub_script_create_cmdline): Likewise. (grub_script_create_cmdblock): Likewise. (grub_script_create_cmdif): Likewise. (grub_script_create_cmdmenu): Likewise. (grub_script_add_cmd): Likewise. (grub_script_arg_add): Likewise. (grub_script_lexer_ref): Likewise. (grub_script_lexer_deref): Likewise. (grub_script_lexer_record_start): Likewise. (grub_script_lexer_record_stop): Likewise. (grub_script_mem_record): Likewise. (grub_script_mem_record_stop): Likewise. (grub_script_malloc): Likewise. (grub_script_yylex): Likewise. (grub_script_yyparse): Likewise. (grub_script_yyerror): Likewise. (grub_script_yylex): Likewise. (grub_script_lexer_init): Return the state. * normal/lexer.c (grub_script_lexer_state): Removed variable. (grub_script_lexer_done): Likewise. (grub_script_lexer_getline): Likewise. (grub_script_lexer_refs): Likewise. (script): Likewise. (newscript): Likewise. (record): Likewise. (recording): Likewise. (recordpos): Likewise. (recordlen): Likewise. (grub_script_lexer_init): Return the state instead of setting global variables. (grub_script_lexer_ref): Use the newly added argument for state instead of globals. (grub_script_lexer_deref): Likewise. (grub_script_lexer_record_start): Likewise. (grub_script_lexer_record_stop): Likewise. (recordchar): Likewise. (nextchar): Likewise. (grub_script_yylex2): Likewise. (grub_script_yylex): Likewise. (grub_script_yyerror): Likewise. * normal/parser.y (func_mem): Removed variable. (menu_entry): Likewise. (err): Likewise. (%lex-param): New parser option. (%parse-param): Likewise. (script): Always return the AST. (argument): Pass the state around. (arguments): Likewise. (grubcmd): Likewise. (commands): Likewise. (function): Likewise. (menuentry): Likewise. (if_statement): Likewise. (if): Likewise. * normal/script.c (grub_script_memused): Removed variable. (grub_script_parsed): Likewise. (grub_script_malloc): Added a state argument. Use that instead of global variables. (grub_script_mem_record): Likewise. (grub_script_mem_record_stop): Likewise. (grub_script_arg_add): Likewise. (grub_script_add_arglist): Likewise. (grub_script_create_cmdline): Likewise. (grub_script_create_cmdif): Likewise. (grub_script_create_cmdmenu): Likewise. (grub_script_add_cmd): Likewise. (grub_script_parse): Setup the state before calling the parser.
This commit is contained in:
parent
6de2ee9903
commit
bfa2bd9efb
5 changed files with 369 additions and 197 deletions
|
@ -23,6 +23,8 @@
|
|||
|
||||
#include <grub/types.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/parser.h>
|
||||
#include "grub_script.tab.h"
|
||||
|
||||
struct grub_script_mem;
|
||||
|
||||
|
@ -123,33 +125,98 @@ struct grub_script_cmd_menuentry
|
|||
int options;
|
||||
};
|
||||
|
||||
struct grub_script_arglist *
|
||||
grub_script_create_arglist (void);
|
||||
/* State of the lexer as passed to the lexer. */
|
||||
struct grub_lexer_param
|
||||
{
|
||||
/* Set to 0 when the lexer is done. */
|
||||
int done;
|
||||
|
||||
/* State of the state machine. */
|
||||
grub_parser_state_t state;
|
||||
|
||||
/* Function used by the lexer to get a new line when more input is
|
||||
expected, but not available. */
|
||||
grub_err_t (*getline) (char **);
|
||||
|
||||
/* A reference counter. If this is >0 it means that the parser
|
||||
expects more tokens and `getline' should be called to fetch more.
|
||||
Otherwise the lexer can stop processing if the current buffer is
|
||||
depleted. */
|
||||
int refs;
|
||||
|
||||
/* The character stream that has to be parsed. */
|
||||
char *script;
|
||||
char *newscript; /* XXX */
|
||||
|
||||
/* While walking through the databuffer, `record' the characters to
|
||||
this other buffer. It can be used to edit the menu entry at a
|
||||
later moment. */
|
||||
|
||||
/* If true, recording is enabled. */
|
||||
int record;
|
||||
|
||||
/* Points to the recording. */
|
||||
char *recording;
|
||||
|
||||
/* index in the RECORDING. */
|
||||
int recordpos;
|
||||
|
||||
/* Size of RECORDING. */
|
||||
int recordlen;
|
||||
};
|
||||
|
||||
/* State of the parser as passes to the parser. */
|
||||
struct grub_parser_param
|
||||
{
|
||||
/* Keep track of the memory allocated for this specific
|
||||
function. */
|
||||
struct grub_script_mem *func_mem;
|
||||
|
||||
/* When set to 0, no errors have occured during parsing. */
|
||||
int err;
|
||||
|
||||
/* The memory that was used while parsing and scanning. */
|
||||
struct grub_script_mem *memused;
|
||||
|
||||
/* The result of the parser. */
|
||||
struct grub_script_cmd *parsed;
|
||||
|
||||
struct grub_lexer_param *lexerstate;
|
||||
};
|
||||
|
||||
struct grub_script_arglist *
|
||||
grub_script_add_arglist (struct grub_script_arglist *list,
|
||||
grub_script_create_arglist (struct grub_parser_param *state);
|
||||
|
||||
struct grub_script_arglist *
|
||||
grub_script_add_arglist (struct grub_parser_param *state,
|
||||
struct grub_script_arglist *list,
|
||||
struct grub_script_arg *arg);
|
||||
struct grub_script_cmd *
|
||||
grub_script_create_cmdline (char *cmdname,
|
||||
grub_script_create_cmdline (struct grub_parser_param *state,
|
||||
char *cmdname,
|
||||
struct grub_script_arglist *arglist);
|
||||
struct grub_script_cmd *
|
||||
grub_script_create_cmdblock (void);
|
||||
grub_script_create_cmdblock (struct grub_parser_param *state);
|
||||
|
||||
struct grub_script_cmd *
|
||||
grub_script_create_cmdif (struct grub_script_cmd *bool,
|
||||
grub_script_create_cmdif (struct grub_parser_param *state,
|
||||
struct grub_script_cmd *bool,
|
||||
struct grub_script_cmd *true,
|
||||
struct grub_script_cmd *false);
|
||||
|
||||
struct grub_script_cmd *
|
||||
grub_script_create_cmdmenu (struct grub_script_arg *title,
|
||||
grub_script_create_cmdmenu (struct grub_parser_param *state,
|
||||
struct grub_script_arg *title,
|
||||
char *sourcecode,
|
||||
int options);
|
||||
|
||||
struct grub_script_cmd *
|
||||
grub_script_add_cmd (struct grub_script_cmdblock *cmdblock,
|
||||
grub_script_add_cmd (struct grub_parser_param *state,
|
||||
struct grub_script_cmdblock *cmdblock,
|
||||
struct grub_script_cmd *cmd);
|
||||
struct grub_script_arg *
|
||||
grub_script_arg_add (struct grub_script_arg *arg,
|
||||
grub_script_arg_add (struct grub_parser_param *state,
|
||||
struct grub_script_arg *arg,
|
||||
grub_script_arg_type_t type, char *str);
|
||||
|
||||
struct grub_script *grub_script_parse (char *script,
|
||||
|
@ -158,21 +225,23 @@ void grub_script_free (struct grub_script *script);
|
|||
struct grub_script *grub_script_create (struct grub_script_cmd *cmd,
|
||||
struct grub_script_mem *mem);
|
||||
|
||||
void grub_script_lexer_init (char *s, grub_err_t (*getline) (char **));
|
||||
void grub_script_lexer_ref (void);
|
||||
void grub_script_lexer_deref (void);
|
||||
void grub_script_lexer_record_start (void);
|
||||
char *grub_script_lexer_record_stop (void);
|
||||
struct grub_lexer_param *grub_script_lexer_init (char *s,
|
||||
grub_err_t (*getline) (char **));
|
||||
void grub_script_lexer_ref (struct grub_lexer_param *);
|
||||
void grub_script_lexer_deref (struct grub_lexer_param *);
|
||||
void grub_script_lexer_record_start (struct grub_lexer_param *);
|
||||
char *grub_script_lexer_record_stop (struct grub_lexer_param *);
|
||||
|
||||
/* Functions to track allocated memory. */
|
||||
void *grub_script_malloc (grub_size_t size);
|
||||
struct grub_script_mem *grub_script_mem_record (void);
|
||||
struct grub_script_mem *grub_script_mem_record_stop (struct grub_script_mem *restore);
|
||||
struct grub_script_mem *grub_script_mem_record (struct grub_parser_param *state);
|
||||
struct grub_script_mem *grub_script_mem_record_stop (struct grub_parser_param *state,
|
||||
struct grub_script_mem *restore);
|
||||
void *grub_script_malloc (struct grub_parser_param *state, grub_size_t size);
|
||||
|
||||
/* Functions used by bison. */
|
||||
int grub_script_yylex (void);
|
||||
int grub_script_yyparse (void);
|
||||
void grub_script_yyerror (char const *err);
|
||||
int grub_script_yylex (YYSTYPE *, struct grub_parser_param *);
|
||||
int grub_script_yyparse (struct grub_parser_param *);
|
||||
void grub_script_yyerror (struct grub_parser_param *, char const *);
|
||||
|
||||
/* Commands to execute, don't use these directly. */
|
||||
grub_err_t grub_script_execute_cmdline (struct grub_script_cmd *cmd);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue