strumenta / pylasu Goto Github PK
View Code? Open in Web Editor NEWLicense: Apache License 2.0
License: Apache License 2.0
It could look similar to this:
class MyListener(ErrorListener):
issues: list[Issue]
issue_type: IssueType
def __init__(self, issues: list[Issue], issue_type: IssueType):
self.issues = issues
self.issue_type = issue_type
def syntaxError(self, recognizer, offendingSymbol, line, column, msg, e):
self.issues.append(Issue(message=str(msg),
type=self.issue_type, position=Position(start=Point(line=line, column=column),
end=Point(line=line, column=column))))
def reportAmbiguity(self, recognizer, dfa, startIndex, stopIndex, exact, ambigAlts, configs):
pass
def reportAttemptingFullContext(self, recognizer, dfa, startIndex, stopIndex, conflictingAlts, configs):
pass
def reportContextSensitivity(self, recognizer, dfa, startIndex, stopIndex, prediction, configs):
pass
class PylasuParser:
def __init__(lexer_class, parser_class):
self.lexer_class= lexer_class
self.parser_class = parser_class
def parse(self, code: str) -> Result:
issues = []
input = InputStream(code)
lexer = self.lexer_class(input)
lexer.removeErrorListeners()
lexer.addErrorListener(MyListener(issues, IssueType.LEXICAL))
token_stream = CommonTokenStream(lexer)
parser = self.parser_class(token_stream)
parser.removeErrorListeners()
parser.addErrorListener(MyListener(issues, IssueType.SYNTACTIC))
parse_tree = parser.root_rule() # I am not sure how we can invoke the root rule through reflection
ast = parse_tree.to_ast(issues)
ast.assign_parents()
return Result(root=ast, issues=issues)
The current Scope
class implementation does not support case-insensitive symbol lookup.
The current implementation in unserialize_result
expects the given JSON to contain an errors
field, which is outdated with respect to the current definition of ParsingResult
.
The current Scope
implementation does not support symbol storage and lookup for anonymous symbols, i.e. looking up symbols using features other than names. #5
Add basic support for symbol resolution, i.e. Symbol
and Scope
.
@dataclass
class Scope:
symbols: Dict[str, List[Symbol]] = field(default_factory=list)
parent: Optional['Scope'] = field(default=None)
def lookup(self, symbol_name: str, symbol_type: type = Symbol) -> Optional[Symbol]:
return next((symbol for symbol in self.symbols.get(symbol_name, []) if isinstance(symbol, symbol_type)),
self.parent.lookup(symbol_name, symbol_type) if self.parent is not None else None)
def add(self, symbol: Symbol):
self.symbols[symbol.name] = self.symbols.get(symbol.name, []) + [symbol]
The current implementation of ReferenceByName
does not support resolving the target. Analogously to what done in Kolasu, we should extend such class, port the resolution logic in tryToResolve
and all unit tests.
At least a test uses it: tests/transformation/test_ast_transformers.py
Requires #15
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.