/* * Copyright 2001-2007 Adrian Thurston */ /* This file is part of Ragel. * * Ragel is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Ragel is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Ragel; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef _XMLPARSE_H #define _XMLPARSE_H #include "vector.h" #include "gendata.h" #include using std::ostream; struct AttrMarker { char *id; int idLen; char *value; int valueLen; }; struct Attribute { char *id; char *value; }; typedef Vector AttrMkList; typedef Vector AttrList; struct XMLTagHashPair; struct XMLTag { enum TagType { Open, Close }; XMLTag( XMLTagHashPair *tagId, TagType type ) : tagId(tagId), type(type), content(0), attrList(0) {} Attribute *findAttr( char *id ) { if ( attrList != 0 ) { for ( AttrList::Iter attr = *attrList; attr.lte(); attr++ ) { if ( strcmp( id, attr->id ) == 0 ) return attr; } } return 0; } XMLTagHashPair *tagId; TagType type; /* Content is associtated with closing tags. */ char *content; /* Attribute lists are associated with opening tags. */ AttrList *attrList; }; struct XMLTagHashPair { char *name; int id; }; struct Token { XMLTag *tag; InputLoc loc; }; struct InlineItem; struct InlineList; struct LmSwitchVect; struct LmSwitchAction; struct Parser { %%{ parser Parser; token TAG_unknown, TAG_ragel, TAG_ragel_def, TAG_host, TAG_state_list, TAG_state, TAG_trans_list, TAG_t, TAG_machine, TAG_start_state, TAG_error_state, TAG_action_list, TAG_action_table_list, TAG_action, TAG_action_table, TAG_alphtype, TAG_element, TAG_getkey, TAG_state_actions, TAG_entry_points, TAG_sub_action, TAG_cond_space_list, TAG_cond_space, TAG_cond_list, TAG_c, TAG_exports, TAG_ex; # Inline block tokens. token TAG_text, TAG_goto, TAG_call, TAG_next, TAG_goto_expr, TAG_call_expr, TAG_next_expr, TAG_ret, TAG_pchar, TAG_char, TAG_hold, TAG_exec, TAG_curs, TAG_targs, TAG_entry, TAG_data, TAG_lm_switch, TAG_init_act, TAG_set_act, TAG_set_tokend, TAG_get_tokend, TAG_init_tokstart, TAG_set_tokstart; token TAG_write, TAG_access, TAG_break, TAG_arg, TAG_cs_expr; token TAG_p_expr, TAG_pe_expr, TAG_cs_expr, TAG_top_expr, TAG_stack_expr, TAG_act_expr, TAG_tokstart_expr, TAG_tokend_expr, TAG_data_expr; }%% %% write instance_data; void init(); int parseLangEl( int type, const Token *token ); Parser( char *fileName, bool outputActive, bool wantComplete ) : fileName(fileName), sourceFileName(0), outStream(0), outputActive(outputActive), wantComplete(wantComplete), cgd(0) { } int token( int tokenId, Token &token ); int token( int tokenId, int col, int line ); int token( XMLTag *tag, int col, int line ); /* Report an error encountered by the parser. */ ostream &warning( const InputLoc &loc ); ostream &error(); ostream &error( const InputLoc &loc ); ostream &parser_error( int tokId, Token &token ); ostream &source_error( const InputLoc &loc ); /* The name of the root section, this does not change during an include. */ char *fileName; char *sourceFileName; ostream *outStream; bool outputActive; bool wantComplete; /* Collected during parsing. */ char *attrKey; char *attrValue; int curAction; int curActionTable; int curTrans; int curState; int curCondSpace; int curStateCond; CodeGenData *cgd; CodeGenMap codeGenMap; Vector writeOptions; }; %% write token_defs; int xml_parse( std::istream &input, char *fileName, bool outputActive, bool wantComplete ); #endif /* _XMLPARSE_H */