#ifndef _PARSE
#define _PARSE
#include "Error.h"

#define PARSE_MAXTYPES 50

typedef struct _Keywords
{
  char *word;
  Method parser;
} Keywords;

typedef struct _ParseData
{
  char *type;
  caddr_t data;
  struct _ParseData *next;
} ParseData;

typedef struct _ParseBlock
{
  char *blocktype;
  ParseData *data;
  struct _ParseBlock *child;
  struct _ParseBlock *next;
  struct _ParseBlock *parent;
} ParseBlock;

typedef struct _MasterBlock
{
  int numTypes;
  char *types[PARSE_MAXTYPES];
  Keywords *keywords[PARSE_MAXTYPES];
  ParseBlock *first;
  ParseBlock *current;
} MasterBlock;

#define Parse_CurrentBlock(b) (b->current)
#define Parse_CurrentBlockType(b) (b->current->blocktype)
#define Parse_SetCurrentBlock(mb, b) mb->current = b

extern Trap Parse_NewMasterBlock(MasterBlock **block);
extern Trap Parse_NewBlock(MasterBlock *mblock, char *type, ParseBlock **block);
extern Trap Parse_NewSubblock(MasterBlock *mblock, char *type, ParseBlock **block);
extern Trap Parse_RegisterKeywords(MasterBlock *block, char *type, Keywords *words);
extern Trap Parse_ParseLine(MasterBlock *block, char *line);
extern Trap Parse_ParseFile(MasterBlock *block, char *name);
extern Trap Parse_GetCurrentData(MasterBlock *block, char *type, caddr_t *data, int size);
extern Trap Parse_UpBlock(MasterBlock *block);
extern Trap Parse_NextBlock(MasterBlock *block);
extern Trap Parse_Subblock(MasterBlock *block);
#endif /* _PARSE */
