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
20using namespace basis;
21using namespace structures;
22
23namespace textual {
24
26{
27 _xml_stream = new astring;
28 if (!to_parse) {}
29}
30
34
35const char *xml_parser::outcome_name(const outcome &to_name)
36{
37 return common::outcome_name(to_name);
38}
39
40void xml_parser::reset(const astring &to_parse)
41{
42 if (!to_parse) {}
43}
44
46 string_table &attributes)
47{
48 if (!header_name || !attributes.symbols()) {}
49 return common::OKAY;
50}
51
52
54 string_table &attributes)
55{
56 if (!tag_name || !attributes.symbols()) {}
57 return OKAY;
58}
59
61{
62 if (!tag_name) {}
63 return OKAY;
64}
65
67{
68 if (!content) {}
69 return OKAY;
70}
71
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
117return common::NOT_IMPLEMENTED;
118}
119
120/* callbacks to invoke.
121outcome header_callback(astring &header_name, string_table &attributes)
122outcome tag_open_callback(astring &tag_name, string_table &attributes)
123outcome tag_close_callback(astring &tag_name)
124outcome 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.
int symbols() const
returns the number of symbols listed in the table.
virtual basis::outcome content_callback(basis::astring &content)
invoked when plain text content is found inside an opened tag.
virtual basis::outcome tag_open_callback(basis::astring &tag_name, structures::string_table &attributes)
an xml tag has been opened in the input stream.
void reset(const basis::astring &to_parse)
throws out any accumulated information and uses "to_parse" instead.
static const char * outcome_name(const basis::outcome &to_name)
reports the string version of "to_name".
virtual basis::outcome tag_close_callback(basis::astring &tag_name)
an xml tag was closed in the input stream.
basis::outcome parse()
starts the parsing process on the current string.
xml_parser(const basis::astring &to_parse)
virtual basis::outcome header_callback(basis::astring &header_name, structures::string_table &attributes)
invoked when a well-formed xml header is seen in the input stream.
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