Exactly.
I don't think you should use SyntaxParsingContext
. Instead, SyntaxBuilder
would be the main part of the job. For example, the current Parser::parseExprArray
would be something like:
// expr-array -> '[' expr-array-element* ']'
SyntaxParserResult<ExprSyntax> SyntaxParser::parseExprArray() {
ArrayExprSyntaxBuilder builder;
// Parse '['.
builder.useLeftSquare(consumeToken(tok::l_square));
// Parse elements.
SyntaxParserResult<ArrayExprElementSyntax> elementsResult = parseExprArrayElementList();
if (elementsResult.isError()) {
// Error handling.
}
builder.useElements(elementsResult.get());
// Parse ']'.
if (Tok.isNot(tok::r_square)) {
// Error handling.
}
builder.useRightSquare(consumeToken(tok::l_square));
// Return successful result.
return makeSyntaxParserResult(builder.build());
}
And yes, this is definitely a huge and challenging job. You also need to modify AST
to point to libSyntax nodes for source informations (e.g. getStartLoc()
/getEndLoc()
). In your proposal, I expect you to plan what you will finish in the time frame, and what you will not.
We already have a serializer; try swift -frontend -emit-syntax source.swift
with the latest master build. For the deserializer, we are able to use LLVM YAML parser.