forked from AdaCore/langkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Python API: fix bindings when assertions are disabled
Python's -O command-line option disableds the execution of "assert" statements. In order for the generated Python bindings to work in such a mode, we need to keep assertion logic only in "assert" statements. This commit fixes statements that currently don't respect this principle. Fixes GitHub issue AdaCore#485 TN: U326-020
- Loading branch information
Showing
7 changed files
with
82 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
testsuite/tests/python_api/asserts/expected_concrete_syntax.lkt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import lexer_example | ||
@with_lexer(foo_lexer) | ||
grammar foo_grammar { | ||
@main_rule main_rule <- list+(Example("example")) | ||
|
||
} | ||
|
||
@abstract class FooNode : Node { | ||
} | ||
|
||
class Example : FooNode implements TokenNode { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import libfoolang | ||
|
||
|
||
print('main.py: Running...') | ||
|
||
ctx = libfoolang.AnalysisContext() | ||
u = ctx.get_from_buffer('foo.txt', b'{example example') | ||
|
||
print("Diagnostics:") | ||
for d in u.diagnostics: | ||
print(d) | ||
print("") | ||
|
||
print("Token range:") | ||
text_range = libfoolang.Token.text_range(u.first_token, u.last_token) | ||
print(libfoolang._py2to3.text_repr(text_range)) | ||
print("") | ||
|
||
print('main.py: Done.') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
main.py: Running... | ||
Diagnostics: | ||
1:1-1:2: Expected 'example', got '{' | ||
|
||
Token range: | ||
'{example example' | ||
|
||
main.py: Done. | ||
Done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
""" | ||
Regression test: check that getting the list of diagnostics and the range of | ||
text between two tokens works when Python assertions are disabled. This used | ||
not to work because "operational" code was in assert statements in the Python | ||
bindings. | ||
""" | ||
|
||
from langkit.dsl import ASTNode | ||
|
||
from utils import build_and_run | ||
|
||
|
||
class FooNode(ASTNode): | ||
pass | ||
|
||
|
||
class Example(FooNode): | ||
token_node = True | ||
|
||
|
||
build_and_run( | ||
lkt_file='expected_concrete_syntax.lkt', | ||
py_script='main.py', | ||
python_args=["-O"], | ||
) | ||
print('Done') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
driver: python |