Description
The parser needs a review both for updating the algo's documentation and to reduce repetitive code.
As of 868b93c much of the parser is littered with manual look-ahead loops to resolve contextual ambiguities:
gencpp/base/components/parser.cpp
Lines 2488 to 2524 in 868b93c
for example, the above uses raw iteration through the lexed tokens to resolve if after thee macro argument is a comma.
We need to setup utilizing a slice for a set of tokens to look ahead that will behave as a sub-slice of the full lexed slice:
struct LexSlice
{
Token* Ptr;
s32 Len;
s32 Idx;
};
Like with the regular tokens array, it needs a simple interface to navigate with it (could probably just recycle the current one with TokArray and just change it to take a slice instead.
This sort of iteration is used throughout the parser for aggregating tokens the parser cannot parse:
eat( Tok_Capture_Start );
s32 level = 0;
while ( left && ( currtok.Type != Tok_Capture_End || level > 0 ) )
{
if ( currtok.Type == Tok_Capture_Start )
level++;
else if ( currtok.Type == Tok_Capture_End && level > 0 )
level--;
eat( currtok.Type );
}
eat( Tok_Capture_End );
It can be generalized for both consumption and look-ahead.
Metadata
Assignees
Labels
Projects
Status
No status