Question on the parser code

Hi,
I’m trying to understand the F18 parser and the parse tree code by creating some simple examples. I would like to create a simple parser and also create a parse tree programmatically, but I’m running into some problems.

For the first step, I added a constructor to ParseState that accepts a std::string (to avoid constructing a CookedSource object). The following code works:

#include “token-parsers.h”
using namespace Fortran::parser;
int main()
{
std::string test(“b”);
ParseState p(test);
auto p1 = “a”_ch;
auto res = p1.Parse(p);
std::cout << " res = " << res.value_or(“no result”) << std::endl;
return 0;
}

For the second step, I would like to create a parse tree programmatically and call unparse.
The first problem is I am unable to build a MainProgram with a minimal set of inputs.
So far, the code to create some of the elements is as follows:

SpecificationPart spec{std::list{},
std::list<Statement<Fortran::common::Indirection>>{} ,
std::list<Statement<Fortran::common::Indirection>>{},
ImplicitPart{std::list{}},
std::list{}};

ExecutionPart exec{std::list{}};

Statement end{Statement{std::nullopt, EndProgramStmt{std::nullopt}}};

The problem is constructing the tuple for the MainProgram - all these objects cause compile errors when placed in a tuple (“no matching constructor” errors). If anyone has better example code, or instructions on how to do this properly, I would appreciate it.

Thanks,
Mark Dewing

You can make a minimal MainProgram like this:

auto mainProgram{MainProgram{

std::optional<Statement>{},

SpecificationPart{

std::list{},

std::list<Statement<Indirection>>{},

std::list<Statement<Indirection>>{},

ImplicitPart{std::list{}},

std::list{}},

ExecutionPart{std::list{}},

std::optional{},

Statement{std::nullopt, EndProgramStmt{std::optional{}}}}};

Then make an empty Program and add the MainProgram to it:

auto program{Program{std::list{}}};

program.v.emplace_back(Indirection{std::move(mainProgram)});

Tim