lexy doesn't compile in Visual Studio 2022 #52
Answered
by
foonathan
Derailedzack
asked this question in
Q&A
-
#include"LangParser.h"
int main() {
LangParser* langparser = new LangParser();
langparser->ParseStr("#func", "!#");
} #pragma once
//TODO:Convert to lexy
#include<string>
#include<lexy/dsl.hpp>
#include<lexy/callback.hpp>
//#include<pegtl.hpp>
class LangParser
{
private:
static constexpr auto grammmer = [] {
auto funcdecl = lexy::dsl::must(lexy::dsl::ascii::alpha) + LEXY_LIT("func");
return lexy::dsl::identifier(funcdecl);
}();
static constexpr auto val = lexy::as_string<std::string>;
/*struct FunDecl : tao::pegtl::one<'func', 'fun'> {};
struct FunReturnType : tao::pegtl::alpha {};
struct FuncImpl : tao::pegtl::must<FunReturnType>, tao::pegtl::opt<FunDecl> {};
struct Grammer: tao::pegtl::must<tao::pegtl::must<tao::pegtl::shebang>,FunDecl>{};*/
public:
LangParser();
void ParseStr(std::string str_dat, std::string str_in);
void ParseFile(std::string path);
}; #include "LangParser.h"
#include <iostream>
LangParser::LangParser()
{
}
void LangParser::ParseStr(std::string str_dat, std::string str_in)
{
/*
try {
tao::pegtl::string_input str_input(str_dat, str_in);
tao::pegtl::parse<Grammer>(str_input);
std::cout << str_input.begin();
}
catch (tao::pegtl::parse_error e) {
std::cout << e.what() << std::endl;
}
*/
}
void LangParser::ParseFile(std::string path)
{
/*
tao::pegtl::file_input file_input(path);
*/
} |
Beta Was this translation helpful? Give feedback.
Answered by
foonathan
Feb 14, 2022
Replies: 1 comment 3 replies
-
The error message isn't great, but it's not a compiler bug:
I don't think your PEGTL grammar works, but this is code that parses a function declaration, maybe that helps: https://lexy.foonathan.net/playground/?id=dGGWMn37z&mode=tree |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
Derailedzack
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The error message isn't great, but it's not a compiler bug:
dsl::must(...)
isn't a rule, so can't be composed with one. Instead, it must be used in the formdsl::must(...).error<my_error>
: https://lexy.foonathan.net/reference/dsl/error/#mustdsl::identifier()
expects a character class, not another rule: https://lexy.foonathan.net/reference/dsl/identifier/#identifierrule
andvalue
member.dsl::must
in lexy in 99% of situations (and it does something completely different frompegtl::must
, maybe the name isn't ideal). Backtracking in lexy is controlled via>>
.I …