mirror of
https://github.com/AdaCore/langkit.git
synced 2026-02-12 12:28:12 -08:00
diagnostics: add a Context class for reusable context managers
Change-Id: I43cea197b2b4dd0c21f3465dd70470bd0c1782a2 TN: P614-007
This commit is contained in:
@@ -80,6 +80,22 @@ def context(message, location):
|
||||
context_stack.pop()
|
||||
|
||||
|
||||
class Context(object):
|
||||
"""
|
||||
Like "context", but can be used more than once.
|
||||
"""
|
||||
|
||||
def __init__(self, message, location):
|
||||
self.message = message
|
||||
self.location = location
|
||||
|
||||
def __enter__(self):
|
||||
context_stack.append((self.message, self.location))
|
||||
|
||||
def __exit__(self, value, typ, traceback):
|
||||
context_stack.pop()
|
||||
|
||||
|
||||
class DiagnosticError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user