/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2021 Ola Rinta-Koski
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see .
*/
#ifndef MARKUP_PARSER_H
#define MARKUP_PARSER_H
#include
#include
#include
#include
#include
namespace MARKUP
{
using namespace tao::pegtl;
struct subscript;
struct superscript;
struct overbar;
struct NODE : parse_tree::basic_node
{
std::string asString() const;
std::string typeString() const;
bool isOverbar() const { return is_type(); }
bool isSubscript() const { return is_type(); }
bool isSuperscript() const { return is_type(); }
};
struct varPrefix : string<'$', '{'> {};
struct subPrefix : string<'_', '{'> {};
struct supPrefix : string<'^', '{'> {};
struct tildePrefix : string<'~', '{'> {};
struct closeBrace : string<'}'> {};
struct varName : plus>> {};
struct varNamespaceName : plus {};
struct varNamespace : seq> {};
struct variable : seq, varName, closeBrace> {};
/**
* anyString =
* a run of characters that do not start a command sequence, or if they do, they do not start
* a complete command prefix (command char + open brace)
*/
struct anyString : plus,
seq, string<'_'>>,
seq, string<'^'>>,
seq, string<'~'>>>> {};
struct prefixedSuperscript : seq {};
struct prefixedSubscript : seq {};
struct prefixedOverbar : seq {};
struct anyStringWithinBraces : plus>> {};
struct superscript : until> {};
struct subscript : until> {};
struct overbar : until> {};
/**
* Finally, the full grammar
*/
struct grammar : star> {};
template
using selector = parse_tree::selector< Rule,
parse_tree::store_content::on,
parse_tree::discard_empty::on>;
class MARKUP_PARSER
{
public:
MARKUP_PARSER( const std::string& source ) :
in( source, "from_input" )
{}
std::unique_ptr Parse();
private:
string_input<> in;
};
} // namespace MARKUP
#endif //MARKUP_PARSER_H