File tree 6 files changed +38
-9
lines changed
testsuite/tests/properties/symbol
6 files changed +38
-9
lines changed Original file line number Diff line number Diff line change @@ -135,7 +135,11 @@ package body Langkit_Support.Symbols is
135
135
function Get_Symbol
136
136
(Self : Symbol_Table; TS : Thin_Symbol) return Symbol_Type is
137
137
begin
138
- return Self.Symbols.Get (Positive (TS));
138
+ if TS = No_Thin_Symbol then
139
+ return null ;
140
+ else
141
+ return Self.Symbols.Get (Positive (TS));
142
+ end if ;
139
143
end Get_Symbol ;
140
144
141
145
end Langkit_Support.Symbols ;
Original file line number Diff line number Diff line change
1
+ package body Pkg is
2
+
3
+ -- ----------------
4
+ -- Canonicalize --
5
+ -- ----------------
6
+
7
+ function Canonicalize (Name : Text_Type) return Symbolization_Result is
8
+ pragma Unreferenced (Name);
9
+ begin
10
+ return Create_Error (" no symbol allowed" );
11
+ end Canonicalize ;
12
+
13
+ end Pkg ;
Original file line number Diff line number Diff line change
1
+ with Langkit_Support.Text ; use Langkit_Support.Text;
2
+ with Libfoolang.Common ; use Libfoolang.Common;
3
+
4
+ package Pkg is
5
+
6
+ function Canonicalize (Name : Text_Type) return Symbolization_Result;
7
+
8
+ end Pkg ;
Original file line number Diff line number Diff line change 12
12
print (d )
13
13
sys .exit (1 )
14
14
15
- try :
16
- result = u . root . p_prop ( None )
17
- except libfoolang . PropertyError as exc :
18
- result = '<{}: {}>' . format ( type ( exc ). __name__ , exc )
19
-
20
- print ('p_prop(None ) = {}' .format (result ))
15
+ for n in ( None , u . root ) :
16
+ try :
17
+ result = libfoolang . _py2to3 . text_repr ( u . root . p_prop ( n ))
18
+ except libfoolang . PropertyError as exc :
19
+ result = '<{}: {}>' . format ( type ( exc ). __name__ , exc )
20
+ print ('p_prop({} ) = {}' .format (n , result ))
21
21
22
22
print ('main.py: Done.' )
Original file line number Diff line number Diff line change 1
1
main.py: Running...
2
2
p_prop(None) = <PropertyError: cannot get the symbol of a null node>
3
+ p_prop(<Example main.txt:1:1-1:8>) = ''
3
4
main.py: Done.
4
5
Done
Original file line number Diff line number Diff line change 1
1
"""
2
- Test that ".symbol" raises a property error on null nodes.
2
+ Test that ".symbol" raises a property error on null nodes or when symbol
3
+ canonicalization fails.
3
4
"""
4
5
6
+ from langkit .compile_context import LibraryEntity
5
7
from langkit .dsl import ASTNode , T
6
8
from langkit .expressions import langkit_property
7
9
@@ -19,5 +21,6 @@ class Example(FooNode):
19
21
token_node = True
20
22
21
23
22
- build_and_run (lkt_file = 'expected_concrete_syntax.lkt' , py_script = 'main.py' )
24
+ build_and_run (lkt_file = 'expected_concrete_syntax.lkt' , py_script = 'main.py' ,
25
+ symbol_canonicalizer = LibraryEntity ('Pkg' , 'Canonicalize' ))
23
26
print ('Done' )
You can’t perform that action at this time.
0 commit comments