Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing Design Changes #53

Open
Ed94 opened this issue Nov 22, 2023 · 0 comments
Open

Parsing Design Changes #53

Ed94 opened this issue Nov 22, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@Ed94
Copy link
Owner

Ed94 commented Nov 22, 2023

Extension of #35

The following will be introduced to the parsing API:

namespace parser {
	struct StackNode
	{
		StackNode* Prev;

		Token Start;
		Token Name;       // The name of the AST node (if parsed)
		StrC    FailedProc; // The name of the procedure that failed
	};
	// Stack nodes are allocated the error's allocator

	struct Error
	{
		String     message;
		StackNode* context_stack;
	};
}

struct ParseInfo

	Arena FileMem;
	Arena TokMem;
	Arena CodeMem;

	FileContents         FileContent;
	Array<parser::Token> Tokens;
	Array<parser::Error> Errors;
	// Errors are allocated to a dedicated general arena.
;

CodeBody parse_file( StrC path );

Every time a parse action is completed a parse info will be provided to the user implicitly with the resulting Code AST.
This means the root node AST will always be provided it just may be invalid.
The Code node will have itself distinguished with flag specified in its code flags with CodeFlag_HasParseInfo
The parse info will be a header struct to an allocation that happens initially when using one of the API's parsing functions.

To retrieve the ParseInfo header, a get_parse_info will provide an ease of use to receive it's pointer.=

Code parse_code( StrC content ) {
  ParseInfo* parse_info = rcast( ParseInfo*, alloc( GlobalAllocator, sizeof( ParseInfo )) + sizeof(AST*) );
  AST* ast = rcast( AST* , parse_info + 1 );
  ...
  return Code{ ast };
}

ParseResult* get_parse_info( Code code ) {
  return rcast( ParseInfo*, code.ast) - 1;
}

If any portion of the code content fails to parse, that section of the string will fail and get shelved into an untyped code string. The parser functions will cascade invalidate the relevant context stack with the untyped code string into a untyped AST node. The error message will be stored in the error list while also logging the failure. And, the context stack will be saved to retrieve for later inspection.

All memory arenas used for the file content, tokens, & code will be within the parse info incase the user wants to free related memory. A utility function will be provided for ease of use:

bool free_parse_allocations( ParseInfo* info );
@Ed94 Ed94 added the enhancement New feature or request label Nov 22, 2023
@Ed94 Ed94 added this to the Core Feature Complete milestone Nov 22, 2023
@Ed94 Ed94 moved this to In Progress in gencpp roadmap Nov 22, 2023
@Ed94 Ed94 self-assigned this Nov 22, 2023
@Ed94 Ed94 moved this from In Progress to Todo in gencpp roadmap Oct 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Todo
Development

No branches or pull requests

1 participant