Skip to content

Commit

Permalink
XX
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Ballance <matt.ballance@gmail.com>
  • Loading branch information
mballance committed Nov 3, 2024
1 parent 5153b12 commit 514c519
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ast/coretypes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ classes:
super: Scope
data:
- fileid: int32_t
- filename:
- type: string
- is_ctor: false

- NamedScope:
super: Scope
Expand Down
3 changes: 3 additions & 0 deletions ast/linking.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ classes:
- units:
- type: list<UP<GlobalScope>>
- is_ctor: false
- filenames:
- type: map<int32_t,string>
- is_ctor: false

- SymbolEnumScope:
super: SymbolScope
Expand Down
1 change: 1 addition & 0 deletions python/zsp_parser/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import os
from .parser import Parser

def get_deps():
return []
Expand Down
70 changes: 70 additions & 0 deletions python/zsp_parser/parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import zsp_parser.ast as zsp_ast
import zsp_parser.core as zspp
from typing import Dict, List, Tuple, TextIO

class ParseException(Exception):
pass

class Parser(object):

def __init__(self):
self.ast_f = zsp_ast.Factory.inst()
self.parser_f = zspp.Factory.inst()
self._root = None
self._filenames : Dict[int,str] = {}
self._files : List[zsp_ast.GlobalScope] = []
pass

def parse(self, files : List[str]) -> bool:
marker_l = self.parser_f.mkMarkerCollector()
builder = self.parser_f.mkAstBuilder(marker_l)

if len(self._files) == 0:
stdlib = self.ast_f.mkGlobalScope(-1)
self.parser_f.loadStandardLibrary(builder, stdlib)
self._files.append(stdlib)

for f in files:
id = len(self._files)
self._filenames[id] = f
with open(f, "r") as fp:
ast = self.ast_f.mkGlobalScope(id)
builder.build(ast, fp)

if marker_l.hasSeverity(zspp.MarkerSeverityE.Error):
err = self._mkErrorMessage(marker_l)
raise ParseException(err)

self._files.append(ast)

return True

def parse_s(self, files : List[Tuple[str, TextIO]]) -> bool:
marker_l = self.parser_f.mkMarkerCollector()
builder = self.parser_f.mkAstBuilder(marker_l)

if len(self._files) == 0:
stdlib = self.ast_f.mkGlobalScope(-1)
self.parser_f.loadStandardLibrary(builder, stdlib)
self._files.append(stdlib)

for f,sin in files:
id = len(self._files)
self._filenames[id] = f
ast = self.ast_f.mkGlobalScope(id)
builder.build(ast, sin)

if marker_l.hasSeverity(zspp.MarkerSeverityE.Error):
err = self._mkErrorMessage(marker_l)
raise ParseException(err)

self._files.append(ast)

return True

def _mkErrorMessage(self, marker_l):
pass

@property
def root(self) -> zsp_ast.RootSymbolScope:
return self._root
6 changes: 6 additions & 0 deletions src/TaskBuildSymbolTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ ast::IRootSymbolScope *TaskBuildSymbolTree::build(
for (std::vector<ast::IGlobalScope *>::const_iterator
it=roots.begin();
it!=roots.end(); it++) {
if ((*it)->getFileid() != -1) {
root->getFilenames().insert({
(*it)->getFileid(),
(*it)->getFilename()
});
}
for (std::vector<ast::IScopeChildUP>::const_iterator
c_it=(*it)->getChildren().begin();
c_it!=(*it)->getChildren().end(); c_it++) {
Expand Down

0 comments on commit 514c519

Please sign in to comment.