Skip to content

Commit 94e4e62

Browse files
committed
Merge branch 'topic/refactor' into 'master'
Introduce the lkql refactor command Closes #262 See merge request eng/libadalang/langkit-query-language!305
2 parents de5959c + 0c70917 commit 94e4e62

File tree

30 files changed

+479
-43
lines changed

30 files changed

+479
-43
lines changed

lkql/build/railroad-diagrams/pattern_arg.svg

Lines changed: 11 additions & 11 deletions
Loading

lkql/language/parser.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -927,19 +927,28 @@ class NodeKindPattern(NodePattern):
927927
kind_name = Field(type=Identifier)
928928

929929

930+
class PatternDetailDelimiter(LkqlNode):
931+
"""
932+
Pattern detail delimiter, either 'is' (old syntax) or ':' (new syntax).
933+
"""
934+
enum_node = True
935+
alternatives = ['is', 'colon']
936+
937+
930938
@abstract
931939
class NodePatternDetail(LkqlNode):
932940
"""
933941
Access to a field, property or selector inside a node pattern.
934942
"""
935-
pass
943+
pattern_detail_delimiter = AbstractField(type=PatternDetailDelimiter)
936944

937945

938946
class NodePatternField(NodePatternDetail):
939947
"""
940948
Access to a field in a node pattern.
941949
"""
942950
identifier = Field(type=Identifier)
951+
pattern_detail_delimiter = Field(type=PatternDetailDelimiter)
943952
expected_value = Field(type=BasePattern)
944953

945954

@@ -948,6 +957,7 @@ class NodePatternProperty(NodePatternDetail):
948957
Access to a property in a node pattern.
949958
"""
950959
call = Field(type=FunCall)
960+
pattern_detail_delimiter = Field(type=PatternDetailDelimiter)
951961
expected_value = Field(type=BasePattern)
952962

953963

@@ -956,18 +966,19 @@ class NodePatternSelector(NodePatternDetail):
956966
Use of a selector in a node pattern
957967
"""
958968
call = Field(type=SelectorCall)
969+
pattern_detail_delimiter = Field(type=PatternDetailDelimiter)
959970
pattern = Field(type=BasePattern)
960971

961972

962973
class ExtendedNodePattern(NodePattern):
963974
"""
964975
Node pattern of the form:
965976
966-
``KindName(field=val, prop() is val, any selector is Pattern)``
977+
``KindName(field: Pattern, prop(): Pattern, any selector: Pattern)``
967978
968979
For instance::
969980
970-
ObjectDecl(children: AspectAssoc)
981+
ObjectDecl(any children: AspectAssoc)
971982
"""
972983
node_pattern = Field(type=ValuePattern)
973984
details = Field(type=NodePatternDetail.list)
@@ -1114,10 +1125,21 @@ class Tuple(Expr):
11141125
),
11151126
tuple_pattern=TuplePattern("(", List(G.value_pattern, sep=","), ")"),
11161127

1128+
pattern_detail_delimiter=Or(
1129+
PatternDetailDelimiter.alt_is("is"),
1130+
PatternDetailDelimiter.alt_colon(":"),
1131+
),
1132+
11171133
pattern_arg=Or(
1118-
NodePatternSelector(G.selector_call, ":", G.or_pattern),
1119-
NodePatternField(G.id, ":", c(), G.or_pattern),
1120-
NodePatternProperty(G.fun_call, ":", c(), G.or_pattern)
1134+
NodePatternSelector(
1135+
G.selector_call, G.pattern_detail_delimiter, G.or_pattern
1136+
),
1137+
NodePatternField(
1138+
G.id, G.pattern_detail_delimiter, c(), G.or_pattern
1139+
),
1140+
NodePatternProperty(
1141+
G.fun_call, G.pattern_detail_delimiter, c(), G.or_pattern
1142+
)
11211143
),
11221144

11231145
selector_call=SelectorCall(

lkql_checker/src/gnatcheck-compiler.adb

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ package body Gnatcheck.Compiler is
293293
-- We assume the following format of the message:
294294
-- filename:line:column: <message body>
295295
--
296-
-- If this format is violated we display the line as unparasable.
296+
-- If this format is violated we display the line as unparsable.
297297

298298
-- Try to match the diagnostic to extract information
299299
Match (Match_Diagnosis, Msg, Matches);
@@ -302,6 +302,9 @@ package body Gnatcheck.Compiler is
302302
return;
303303
end if;
304304

305+
Msg_Start := Matches (5).First;
306+
Msg_End := Matches (5).Last;
307+
305308
SF := File_Find
306309
(Msg (Matches (1).First .. Matches (1).Last),
307310
Use_Short_Name => True);
@@ -310,8 +313,18 @@ package body Gnatcheck.Compiler is
310313
Sloc.Column := Column_Number'Value
311314
(Msg (Matches (4).First .. Matches (4).Last));
312315

313-
Msg_Start := Matches (5).First;
314-
Msg_End := Matches (5).Last;
316+
-- Handle internal warnings before any other kind of error, because
317+
-- they don't have an Ada source location
318+
--
319+
-- TODO: We want to refactor this logic and make the logic of
320+
-- handling internal errors more general.
321+
if Msg_End - Msg_Start > 22
322+
and then Msg
323+
(Msg_Start .. Msg_Start + 22) = "warning: internal issue"
324+
then
325+
Warning (Msg (Msg_Start + 27 .. Msg_End));
326+
return;
327+
end if;
315328

316329
-- Test if the provided sources is present and is not ignored
317330
if not Present (SF) or else Source_Info (SF) = Ignore_Unit then
@@ -374,7 +387,7 @@ package body Gnatcheck.Compiler is
374387

375388
if Msg_End - Msg_Start > 21
376389
and then Msg
377-
(Msg_Start + 7 .. Msg_Start + 20) = "internal error"
390+
(Msg_Start + 7 .. Msg_Start + 20) = "internal issue"
378391
then
379392
Kind := Internal_Error;
380393
else

lkql_jit/cli/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@
122122
<artifactId>launcher-common</artifactId>
123123
<version>${graalvm.version}</version>
124124
</dependency>
125+
<dependency>
126+
<groupId>com.adacore</groupId>
127+
<artifactId>liblkqllang</artifactId>
128+
<version>0.1</version>
129+
</dependency>
125130
</dependencies>
126131

127132
</project>

lkql_jit/cli/src/main/java/com/adacore/lkql_jit/LKQLMain.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
LKQLLauncher.LKQLRun.class,
1818
LKQLChecker.Args.class,
1919
GNATCheckWorker.Args.class,
20-
LKQLDoc.class
20+
LKQLDoc.class,
21+
LKQLRefactor.class
2122
},
2223
description =
2324
"Unified driver for LKQL (Langkit query language). Allows you to run LKQL "

0 commit comments

Comments
 (0)