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)
30 xml_parser::~xml_parser()
34 const char *xml_parser::outcome_name(const outcome &to_name)
36 return common::outcome_name(to_name);
39 void xml_parser::reset(const astring &to_parse)
44 outcome xml_parser::header_callback(astring &header_name,
45 string_table &attributes)
47 if (!header_name || !attributes.symbols()) {}
52 outcome xml_parser::tag_open_callback(astring &tag_name,
53 string_table &attributes)
55 if (!tag_name || !attributes.symbols()) {}
59 outcome xml_parser::tag_close_callback(astring &tag_name)
65 outcome xml_parser::content_callback(astring &content)
71 outcome xml_parser::parse()
74 //phases: we are initially always seeking a bracket bounded tag of some sort.
76 // the first few constructs must be headers, especially the xml header.
78 // is it true that headers are the only valid thing to see before real tags
79 // start, or can there be raw content embedded in there?
80 // yes, it seems to be true in mozilla. you can't have bare content in
81 // between the headers and the real tags.
83 // actually, if we allow the file to not start with the xml header and
84 // version, then that's a bug.
86 // need function to accumulate the tag based on structure. do headers
87 // have to have a ? as part of the inner and outer structure?
89 // test against mozilla to ensure we are seeing the same things; get
90 // together some tasty sample files.
92 // count lines and chars so we can report where it tanked.
94 // back to phases, (not a precise grammar below)
95 // white_space ::= [ ' ' '\n' '\r' '\t' ] *
97 // text_phrase ::= not_white_space_nor_reserved not_reserved*
98 // name ::= text_phrase
99 // value ::= not_reserved *
103 // xml_file ::= header+ ws tagged_unit+ ws
104 // header ::= '<' '?' name ws attrib_list ws '?' '>' ws
105 // tagged_unit ::= open_tag content* close_tag ws
106 // content ::= [ tagged_unit | text_phrase ] + ws
107 // open_tag ::= '<' name ws attrib_list ws '>' ws
108 // attrib_list ::= ( attribute ws ) * ws
109 // attribute ::= name ws '=' ws quoted_string ws
110 // quoted_string ::= '"' not_lt_char_nor_quote '"' ws
111 // close_tag :: '<' '/' name ws '>' ws
113 //write a recursive descent parser on this grammar and spit out the
114 // productions as callbacks, at least for the major ones already listed.
116 return common::NOT_IMPLEMENTED;
119 /* callbacks to invoke.
120 outcome header_callback(astring &header_name, string_table &attributes)
121 outcome tag_open_callback(astring &tag_name, string_table &attributes)
122 outcome tag_close_callback(astring &tag_name)
123 outcome content_callback(astring &content)