1 /*****************************************************************************\
4 * Author : Chris Koeritz *
6 *******************************************************************************
7 * Copyright (c) 2007-$now By Author. This program is free software; you can *
8 * redistribute it and/or modify it under the terms of the GNU General Public *
9 * License as published by the Free Software Foundation; either version 2 of *
10 * the License or (at your option) any later version. This is online at: *
11 * http://www.fsf.org/copyleft/gpl.html *
12 * Please send any updates to: fred@gruntose.com *
13 \*****************************************************************************/
15 #include "xml_parser.h"
17 #include <basis/astring.h>
18 #include <structures/string_table.h>
20 using namespace basis;
21 using namespace structures;
25 xml_parser::xml_parser(const astring &to_parse)
27 _xml_stream = new astring;
31 xml_parser::~xml_parser()
35 const char *xml_parser::outcome_name(const outcome &to_name)
37 return common::outcome_name(to_name);
40 void xml_parser::reset(const astring &to_parse)
45 outcome xml_parser::header_callback(astring &header_name,
46 string_table &attributes)
48 if (!header_name || !attributes.symbols()) {}
53 outcome xml_parser::tag_open_callback(astring &tag_name,
54 string_table &attributes)
56 if (!tag_name || !attributes.symbols()) {}
60 outcome xml_parser::tag_close_callback(astring &tag_name)
66 outcome xml_parser::content_callback(astring &content)
72 outcome xml_parser::parse()
75 //phases: we are initially always seeking a bracket bounded tag of some sort.
77 // the first few constructs must be headers, especially the xml header.
79 // is it true that headers are the only valid thing to see before real tags
80 // start, or can there be raw content embedded in there?
81 // yes, it seems to be true in mozilla. you can't have bare content in
82 // between the headers and the real tags.
84 // actually, if we allow the file to not start with the xml header and
85 // version, then that's a bug.
87 // need function to accumulate the tag based on structure. do headers
88 // have to have a ? as part of the inner and outer structure?
90 // test against mozilla to ensure we are seeing the same things; get
91 // together some tasty sample files.
93 // count lines and chars so we can report where it tanked.
95 // back to phases, (not a precise grammar below)
96 // white_space ::= [ ' ' '\n' '\r' '\t' ] *
98 // text_phrase ::= not_white_space_nor_reserved not_reserved*
99 // name ::= text_phrase
100 // value ::= not_reserved *
104 // xml_file ::= header+ ws tagged_unit+ ws
105 // header ::= '<' '?' name ws attrib_list ws '?' '>' ws
106 // tagged_unit ::= open_tag content* close_tag ws
107 // content ::= [ tagged_unit | text_phrase ] + ws
108 // open_tag ::= '<' name ws attrib_list ws '>' ws
109 // attrib_list ::= ( attribute ws ) * ws
110 // attribute ::= name ws '=' ws quoted_string ws
111 // quoted_string ::= '"' not_lt_char_nor_quote '"' ws
112 // close_tag :: '<' '/' name ws '>' ws
114 //write a recursive descent parser on this grammar and spit out the
115 // productions as callbacks, at least for the major ones already listed.
117 return common::NOT_IMPLEMENTED;
120 /* callbacks to invoke.
121 outcome header_callback(astring &header_name, string_table &attributes)
122 outcome tag_open_callback(astring &tag_name, string_table &attributes)
123 outcome tag_close_callback(astring &tag_name)
124 outcome content_callback(astring &content)