nginxconfig
C++libraryforparsingandprintingnginx.conf
nginxconfig/parse_types.hpp
Go to the documentation of this file.
00001 
00012 #ifndef __NGINXCONFIG_PARSE_TYPES_HPP_INCLUDED__
00013 #define __NGINXCONFIG_PARSE_TYPES_HPP_INCLUDED__
00014 
00015 #include <nginxconfig/config.hpp>
00016 #include <nginxconfig/parse.hpp>
00017 
00018 #include <sstream>
00019 
00020 namespace nginxconfig
00021 {
00022 namespace parser
00023 {
00024 
00025 struct context
00026 {
00027 public:
00028     using size_type = std::string::size_type;
00029     
00030     std::istream& input;
00031     size_type     line_no           = 0;
00032     size_type     character_no      = 0;
00033     size_type     character_no_next = 0;
00034     std::string   current;
00035     
00036     explicit context(std::istream& input) :
00037             input(input)
00038     { }
00039     
00040     bool next();
00041     
00042     template <typename... T>
00043     parse_error create_parse_error(size_type column, T&&... message)
00044     {
00045         std::ostringstream stream;
00046         return create_parse_error_impl(stream, column, std::forward<T>(message)...);
00047     }
00048     
00049 private:
00050     parse_error create_parse_error_impl(std::ostringstream& stream, size_type column)
00051     {
00052         size_type real_char_no = character_no + (column == nginxconfig::parse_error::no_column ? 0 : column);
00053         return parse_error(line_no, column, real_char_no, stream.str());
00054     }
00055     
00056     template <typename T, typename... TRest>
00057     parse_error create_parse_error_impl(std::ostringstream& stream, size_type column, T&& current, TRest&&... rest)
00058     {
00059         stream << std::forward<T>(current);
00060         return create_parse_error_impl(stream, column, std::forward<TRest>(rest)...);
00061     }
00062 };
00063 
00064 enum class line_kind
00065 {
00066     simple,
00067     complex_start,
00068     complex_end,
00069     comment,
00070     unknown,
00071 };
00072 
00073 struct line_components
00074 {
00075     using attribute_list = ast_entry::attribute_list;
00076     
00077     static line_components create_from_line(const std::string& line);
00078     
00079     line_kind      category = line_kind::unknown;
00080     std::string    name;
00081     attribute_list attributes;
00082     std::string    comment;
00083 };
00084 
00085 }
00086 }
00087 
00088 #endif/*__NGINXCONFIG_PARSE_TYPES_HPP_INCLUDED__*/
 All Classes Files Functions Variables Friends Defines