KiCad PCB EDA Suite
Loading...
Searching...
No Matches
markup_parser.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2021 Ola Rinta-Koski
5 * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21
22#include <markup_parser.h>
23#include <sstream>
24#include <string_utils.h>
25
26using namespace MARKUP;
27
28
29std::unique_ptr<NODE> MARKUP_PARSER::Parse()
30{
31 try
32 {
33 std::unique_ptr<NODE> root;
34
35 if( mem_in )
36 root = parse_tree::parse<MARKUP::grammar, MARKUP::NODE, MARKUP::selector>( *mem_in );
37 else
38 root = parse_tree::parse<MARKUP::grammar, MARKUP::NODE, MARKUP::selector>( *in );
39
40 return root;
41 }
42 catch ( tao::pegtl::parse_error& )
43 {
44 // couldn't parse text item
45 // TODO message to user?
46 return nullptr;
47 }
48}
49
50
51std::string NODE::typeString() const
52{
53 std::stringstream os;
54
55 if( is_type<MARKUP::subscript>() ) os << "SUBSCRIPT";
56 else if( is_type<MARKUP::superscript>() ) os << "SUPERSCRIPT";
57 else if( is_type<MARKUP::overbar>() ) os << "OVERBAR";
58 else if( is_type<MARKUP::anyString>() ) os << "ANYSTRING";
59 else if( is_type<MARKUP::anyStringWithinBraces>() ) os << "ANYSTRINGWITHINBRACES";
60 else os << "other";
61
62 return os.str();
63}
64
65
66wxString NODE::asWxString() const
67{
68 return From_UTF8( string().c_str() );
69}
70
71
72std::string NODE::asString() const
73{
74 std::stringstream os;
75
76 os << type;
77
78 if( has_content() )
79 os << " \"" << string() << "\"";
80
81 return os.str();
82}
std::unique_ptr< string_input<> > in
std::unique_ptr< NODE > Parse()
std::unique_ptr< memory_input<> > mem_in
wxString From_UTF8(const char *cstring)
std::string asString() const
wxString asWxString() const
std::string typeString() const