Implement a context stack for the parsing
Ed94 opened this issue · comments
Ed_ commented
Right now the parsing errors require a debugger.
Errors don't have a stack trace nor does the parser keep proper context of what relative area of the file its in.
The tokens need to keep track of the line and column. (The usual debug info)
A simple stack trace should not be too big of an ordeal to add.
Keeping track of what scope the the parser in will be necessary for the naive preprocessor parsing.
Could use Jai's scope context pattern:
// In gen.hpp?
struct ProcessContext
{
AllocatorInfo Allocator;
};
// In gen.cpp?
global List<ProcessContext> ContextStack;
void push_context( ProcessContext* context );
void pop_context();
template< typename ContextType>
ContextType* get_context();
// In gen.interface.parser.cpp?
struct ParseStackNode
{
Token TokStart; // Can show line, column, along with text on the line.
Token Name; // The name of the AST node (if parsed)
StrC ProcName; // The name of the procedure
};
struct ParserContext
{
Using_ProcessContext;
TokArray Tokens;
List<ParseStackNode> ScopeStack; // Reserve around 32 kb?
void scope_assign_name( StrC name );
void push_scope( StrC name );
};
// Inside an internal parse function:
{
get_context<ParserContext>()->push_scope( { name(__FUNCTION__) );
...
get_context<ParserContext>()->scope_assign_name( ast_name );
...
}
// Inside a user parse function:
{
push_context( make_parse_context() );
...
}
Ed_ commented
Implemented.
Didn't use the generic context, kept just a context for the parser as the rest of the library doesn't need it.