21#include <fmt/format.h>
22#include <pegtl/contrib/parse_tree.hpp>
28#include <boost/locale/boundary/types.hpp>
48template <
typename Rule>
86 template <
typename ActionInput>
98 template <
typename ActionInput>
102 wxCHECK2( in.string().size() >= 2,
return );
103 *s.
target_string = in.string().substr( 1, in.string().size() - 2 );
108#define DEFINE_STRING_ACTION( Rule, StateVariable ) \
110struct LIBRARY_TABLE_PARSER_ACTION<Rule> \
112 static void apply0( LIBRARY_TABLE_PARSER_STATE& s ) \
114 s.target_string = &s.StateVariable; \
126#define DEFINE_FLAG_ACTION( Rule, StateVariable ) \
128struct LIBRARY_TABLE_PARSER_ACTION<Rule> \
130 static void apply0( LIBRARY_TABLE_PARSER_STATE& s ) \
132 s.StateVariable = true; \
157 const std::filesystem::path& aPath )
161 file_input in( aPath );
164 wxLogTrace(
traceLibraries,
"LIBRARY_TABLE_PARSER::Parse %s", aPath.string().c_str() );
172 wxString::Format(
_(
"An unexpected error occurred while reading library table %s "),
173 aPath.string().c_str() );
177 catch(
const parse_error& e )
179 const auto& p = e.positions().front();
180 std::string msg = fmt::format(
"Error at line {}, column {}:\n{}\n{:>{}}\n{}",
181 p.line, p.column, in.line_at( p ),
"^", p.column,
186 wxString description = wxString::Format(
_(
"Syntax error at line %zu, column %zu" ),
190 .description = description,
198 catch( std::filesystem::filesystem_error& e )
200 wxLogTrace(
traceLibraries,
"LIBRARY_TABLE_PARSER::Parse loading '%s' error: %s",
201 aPath.string(), e.what() );
203 .description = e.what()
210 const std::string& aBuffer )
212 memory_input in( aBuffer,
"" );
214 wxLogTrace(
traceLibraries,
"LIBRARY_TABLE_PARSER::Parse from string buffer" );
222 wxString::Format(
_(
"An unexpected error occurred while reading library table") );
226 catch(
const parse_error& e )
228 const auto& p = e.positions().front();
229 std::string msg = fmt::format(
"Error at line {}, column {}:\n{}\n{:>{}}\n{}",
230 p.line, p.column, in.line_at( p ),
"^", p.column,
235 wxString description = wxString::Format(
_(
"Syntax error at line %zu, column %zu" ),
239 .description = description,
tl::expected< LIBRARY_TABLE_IR, LIBRARY_PARSE_ERROR > ParseBuffer(const std::string &aBuffer)
tl::expected< LIBRARY_TABLE_IR, LIBRARY_PARSE_ERROR > Parse(const std::filesystem::path &aPath)
const wxChar *const traceLibraries
Flag to enable library table and library manager tracing.
#define DEFINE_FLAG_ACTION(Rule, StateVariable)
#define DEFINE_STRING_ACTION(Rule, StateVariable)
The intermediate representation that a library table is parsed into.
std::vector< LIBRARY_TABLE_ROW_IR > rows
static void apply0(LIBRARY_TABLE_PARSER_STATE &s)
static void apply0(LIBRARY_TABLE_PARSER_STATE &s)
static void apply0(LIBRARY_TABLE_PARSER_STATE &s)
static void apply0(LIBRARY_TABLE_PARSER_STATE &s)
static void apply(const ActionInput &in, LIBRARY_TABLE_PARSER_STATE &s)
static void apply(const ActionInput &in, LIBRARY_TABLE_PARSER_STATE &s)
std::string * target_string
LIBRARY_TABLE_ROW_IR current_row_model
LIBRARY_TABLE_PARSER_STATE()
wxLogTrace helper definitions.