Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/BalaM314/soodocode
Browse files Browse the repository at this point in the history
  • Loading branch information
BalaM314 committed Nov 28, 2023
2 parents 016bebc + 2110b64 commit 75c4d8f
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ export type TokenMatcher = (TokenType | ".*" | ".+" | "expr+");

export type ProgramAST = ProgramASTNode[];
export type ProgramASTLeafNode = Statement;
export type ProgramASTNode = ProgramASTLeafNode | ProgramASTTreeNode;
export type ProgramASTNode = ProgramASTLeafNode | ProgramASTTreeNode | ProgramASTMultiTreeNode;
export type ProgramASTTreeNode = {
startStatement: Statement;
endStatement: Statement;
type: ProgramASTTreeNodeType;
nodes: ProgramASTNode[];
controlStatements: Statement[];
nodeGroups: ProgramASTNode[][];
}
//not necessary
//export type UnfinishedProgramASTTreeNode = Partial<ProgramASTTreeNode> & Omit<ProgramASTTreeNode, "endStatement">;
Expand Down Expand Up @@ -72,18 +71,18 @@ export function parse(tokens:Token[]):ProgramAST {
const statements = lines.map(parseStatement);
const program:ProgramAST = [];
function getActiveBuffer(){
if(blockStack.length == 0) return program; else return blockStack.at(-1)!.nodes;
if(blockStack.length == 0) return program;
else return blockStack.at(-1)!.nodeGroups.at(-1)!;
}
const blockStack:ProgramASTTreeNode[] = [];
for(const statement of statements){
if(statement.category == "normal"){
getActiveBuffer().push(statement);
} else if(statement.category == "block"){
const node:ProgramASTTreeNode = {
startStatement: statement,
endStatement: null!, //null! goes brr
controlStatements: [statement],
type: statement.stype as ProgramASTTreeNodeType,
nodes: []
nodeGroups: [[]]
};
getActiveBuffer().push(node);
blockStack.push(node);
Expand Down

0 comments on commit 75c4d8f

Please sign in to comment.