feisty meow concerns codebase  2.140
xml_parser.cpp
Go to the documentation of this file.
1 /*****************************************************************************\
2 * *
3 * Name : xml_parser *
4 * Author : Chris Koeritz *
5 * *
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 \*****************************************************************************/
14 
15 #include "xml_parser.h"
16 
17 #include <basis/astring.h>
19 
20 using namespace basis;
21 using namespace structures;
22 
23 namespace textual {
24 
25 xml_parser::xml_parser(const astring &to_parse)
26 {
27  _xml_stream = new astring;
28  if (!to_parse) {}
29 }
30 
31 xml_parser::~xml_parser()
32 {
33 }
34 
35 const char *xml_parser::outcome_name(const outcome &to_name)
36 {
37  return common::outcome_name(to_name);
38 }
39 
40 void xml_parser::reset(const astring &to_parse)
41 {
42  if (!to_parse) {}
43 }
44 
45 outcome xml_parser::header_callback(astring &header_name,
46  string_table &attributes)
47 {
48  if (!header_name || !attributes.symbols()) {}
49  return common::OKAY;
50 }
51 
52 
53 outcome xml_parser::tag_open_callback(astring &tag_name,
54  string_table &attributes)
55 {
56  if (!tag_name || !attributes.symbols()) {}
57  return OKAY;
58 }
59 
60 outcome xml_parser::tag_close_callback(astring &tag_name)
61 {
62  if (!tag_name) {}
63  return OKAY;
64 }
65 
66 outcome xml_parser::content_callback(astring &content)
67 {
68  if (!content) {}
69  return OKAY;
70 }
71 
72 outcome xml_parser::parse()
73 {
74 
75 //phases: we are initially always seeking a bracket bounded tag of some sort.
76 
77 // the first few constructs must be headers, especially the xml header.
78 
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.
83 
84 // actually, if we allow the file to not start with the xml header and
85 // version, then that's a bug.
86 
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?
89 
90 // test against mozilla to ensure we are seeing the same things; get
91 // together some tasty sample files.
92 
93 // count lines and chars so we can report where it tanked.
94 
95 // back to phases, (not a precise grammar below)
96 // white_space ::= [ ' ' '\n' '\r' '\t' ] *
97 // ws ::= white_space
98 // text_phrase ::= not_white_space_nor_reserved not_reserved*
99 // name ::= text_phrase
100 // value ::= not_reserved *
101 // lt_char ::= '<'
102 // quote ::= '"'
103 
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
113 
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.
116 
117 return common::NOT_IMPLEMENTED;
118 }
119 
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)
125 */
126 
127 } //namespace.
128 
Provides a dynamically resizable ASCII character string.
Definition: astring.h:35
static const char * outcome_name(const outcome &to_name)
Returns a string representation of the outcome "to_name".
Outcomes describe the state of completion for an operation.
Definition: outcome.h:31
Provides a symbol_table that holds strings as the content.
Definition: string_table.h:32
int symbols() const
returns the number of symbols listed in the table.
Definition: symbol_table.h:241
The guards collection helps in testing preconditions and reporting errors.
Definition: array.h:30
A dynamic container class that holds any kind of object via pointers.
Definition: amorph.h:55