// Copyright {Jagger Software Limited} 2003 #ifndef CSHARP_SOURCE_INCLUDED #define CSHARP_SOURCE_INCLUDED #include "csharp/lexical_grammar.hpp" #include "csharp/lexical_grammar_source_parser_visitor.hpp" #include "grammar_tools/tree_building_parseable_source.hpp" #include namespace ast { template class symbol; } namespace csharp { class source { public: // types class lexical_type { public: // types typedef ::std::vector container_type; typedef container_type::const_iterator iterator; typedef ::ast::symbol symbol_type; public: // attributes iterator begin() const; iterator end() const; iterator position() const; const symbol_type * input() const; private: // 'tors friend class source; template lexical_type(iterator start, iterator finish) : characters(start, finish) , tree(0) , parse_end_position() { // 9.3.1 Line terminators, paragraph 2, sentence 3 // // A carriage-return character (U+000D) is added to the end of the // source file if that source file is non-empty and if the last // character of the source file is not a carriage return (U+000D), // a line feed (U+000A), a line separator (U+2028), or a paragraph // separator (U+2029). if (!characters.empty() && characters.back() != '\r' && characters.back() != '\n') { characters.push_back('\r'); } grammar_tools::tree_building_parseable_source code(characters.begin(), characters.end()); csharp::lexical_grammar_source_parser_visitor code_visitor(code); const bool parsed = code.parse(lexical_grammar::instance().input, code_visitor); parse_end_position = code.position(); tree = code.extract_tree(); } ~lexical_type(); private: // inappropriate lexical_type(const lexical_type &); void operator=(const lexical_type &); private: // state container_type characters; const symbol_type * tree; iterator parse_end_position; }; class syntactic_type { public: // types typedef ::std::vector container_type; typedef container_type::const_iterator iterator; typedef ::ast::symbol symbol_type; public: // atributes iterator begin() const; iterator end() const; iterator position() const; const symbol_type * compilation_unit() const; private: // 'tors friend class source; explicit syntactic_type(const lexical_type::symbol_type * root); ~syntactic_type(); private: // inappropriate syntactic_type(const syntactic_type &); void operator=(const syntactic_type &); private: // state container_type tokens; const symbol_type * tree; iterator parse_end_position; }; public: // 'tors // TODO: add symbol_factory, pp-handler parameters template source(iterator start, iterator finish, const std::string & filename) : lexical_source(start, finish) , syntactic_source(lexical_source.input()) , filename(filename) { } ~source(); public: // attributes const lexical_type & lexical() const; const syntactic_type & syntactic() const; const std::string filename; private: // state lexical_type lexical_source; // ORDER syntactic_type syntactic_source; // DEPENDENCY }; } #endif