33 * SPDX-License-Identifier: GPL-2.0-only */
44package de .uka .ilkd .key .scripts ;
55
6- import java .util .Collections ;
7- import java .util .List ;
8- import java .util .Map ;
9- import java .util .Objects ;
10-
116import de .uka .ilkd .key .parser .Location ;
12-
7+ import org . antlr . v4 . runtime . CharStream ;
138import org .antlr .v4 .runtime .ParserRuleContext ;
149import org .jspecify .annotations .NullMarked ;
1510import org .jspecify .annotations .Nullable ;
1611
12+ import java .util .Collections ;
13+ import java .util .List ;
14+ import java .util .Map ;
15+ import java .util .Objects ;
16+
1717import static java .util .stream .Collectors .joining ;
1818
1919/// This class represents is the AST of a proof script command.
2020///
2121/// It is an abstraction to the commands of following structure:
2222/// ```
23- /// <commandName> key_1= value_1 ... key_m= value_m positionalArgs_1 ... positionalArgs_n {
23+ /// <commandName> key_1: value_1 ... key_m: value_m positionalArgs_1 ... positionalArgs_n {
2424/// commands_0; ...; commands_k;
25- /// }
26- /// ```
25+ ///}
26+ ///```
2727///
28- /// @param commandName the name of the command, e.g., "macro" for `macro auto;`
29- /// @param namedArgs a map of the given named arguments and values.
30- /// If a named argument is not given, the entry should be missing in the map. Null-values are not
31- /// allowed.
28+ /// @param commandName the name of the command, e.g., "macro" for `macro auto;`
29+ /// @param namedArgs a map of the given named arguments and values.
30+ /// If a named argument is not given, the entry should be missing in the map. Null-values are not
31+ /// allowed.
3232/// @param positionalArgs the list of given positional arguments
33- /// @param commands a nullable block of proof script arguments (represents "higher-order proof
34- /// scripts").
35- /// If null, the block was omitted syntactically in contrast to an empty list.
36- /// @param location the location of this command for error reporting.
33+ /// @param commands a nullable block of proof script arguments (represents "higher-order proof
34+ /// scripts").
35+ /// If null, the block was omitted syntactically in contrast to an empty list.
36+ /// @param location the location of this command for error reporting.
3737/// @author Alexander Weigl
3838/// @version 1 (14.03.25)
3939@ NullMarked
@@ -45,26 +45,30 @@ public record ScriptCommandAst(
4545 @ Nullable Location location ) {
4646
4747 public ScriptCommandAst (String commandName , Map <String , Object > namedArgs ,
48- List <Object > positionalArgs ) {
48+ List <Object > positionalArgs ) {
4949 this (commandName , namedArgs , positionalArgs , Collections .emptyList (), null );
5050 }
5151
52+ /// Renders this command a parsable string representation. The order of the arguments is as follows:
53+ /// key-value arguments, positional arguments and the additional script block.
54+ ///
55+ /// @see de.uka.ilkd.key.nparser.ParsingFacade#parseScript(CharStream)
5256 public String asCommandLine () {
5357 return commandName + ' ' +
5458 namedArgs .entrySet ().stream ()
55- .map (it -> it .getKey () + ": " + humanString (it .getValue ()))
59+ .map (it -> it .getKey () + ": " + asReadableString (it .getValue ()))
5660 .collect (joining (" " ))
5761 + ' '
58- + positionalArgs .stream ().map (ScriptCommandAst ::humanString ).collect (joining (" " ))
62+ + positionalArgs .stream ().map (ScriptCommandAst ::asReadableString ).collect (joining (" " ))
5963 + (commands != null
60- ? " {"
61- + commands .stream ().map (ScriptCommandAst ::asCommandLine )
62- .collect (joining ("\n " ))
63- + "\n }"
64- : ";" );
64+ ? " {"
65+ + commands .stream ().map (ScriptCommandAst ::asCommandLine )
66+ .collect (joining ("\n " ))
67+ + "\n }"
68+ : ";" );
6569 }
6670
67- public static String humanString (Object value ) {
71+ public static String asReadableString (Object value ) {
6872 if (value instanceof ParserRuleContext ctx ) {
6973 return ctx .getText ();
7074 }
0 commit comments