Skip to content

AST for KeY Scripts#3587

Merged
wadoon merged 3 commits intomainfrom
weigl/psg4-scriptast
Sep 7, 2025
Merged

AST for KeY Scripts#3587
wadoon merged 3 commits intomainfrom
weigl/psg4-scriptast

Conversation

@wadoon
Copy link
Member

@wadoon wadoon commented Mar 29, 2025

Synopsis

JMLScripts and KeY scripts use the same backend, but the ProofScriptEngine is currently bound to the KeY language's parser. This PR introduces a simple AST class to abstract the source of a script, which is a simple record containing the command name, positional and keyword arguments, sub-commands, and positional information.

classDiagram
  direction TB

  class ScriptCommandAst { 
  name : String 
  positionalArgs : List<Object>
  keywordArgs    : Map<String,Object>
  loc            : Location
 }

ScriptCommandAst "*" <-- ScriptCommandAst : sub-commands
Loading

Along the road, the interface of script commands is simplified: There is no need for preparing the parameter class instance anymore. Instead, execute(..) is called directly, and any command implementation can deal with the AST as they like.

classDiagram 
  direction TB

   class ProofScriptCommand {
    execute(uiControl, cmdAst, engineState) 

    getArguments() : List<ProofScriptArgument>
    getName() : String
    getAlias() : List<String>
    getDocumentation()
  }
Loading

Also, proof script commands can announce a list of aliases. This allows the implementation of multiple (similar) commands with one implementation. The implementation can adapt its behavior using the given AST representation. For example, the let command is also callable via letf, the latter forces/overwrites the abbreviation.

Using List<Object> and Map<String,Object> for the representation inside of the AST allows the use within JML scripts, as custom objects can be provided within the AST. Later, the ValueInjector should know the conversion rules to get from the custom object to the required types, e.g., how to come from a JMLTerm to a JTerm.

Builds upon: #3021

Intended Change

ProofScriptEngine is free of ANTLR classes.
An AST for the execution of proof scripts exists, which is useable

Plan

  • Do it.
  • Test it.
  • Ship it.

Type of pull request

  • Refactoring (behaviour should not change or only minimally change)

    • Breaking change:
      breaks the internal API of proof script execution, and script commands.
  • There are changes to the (Java) code

Ensuring quality

  • I made sure that introduced/changed code is well documented (javadoc and inline comments).
  • I made sure that new/changed end-user features are well documented (https://github.com/KeYProject/key-docs).
  • I added new test case(s) for new functionality.
  • I have tested the feature as follows: ...
  • I have checked that runtime performance has not deteriorated.

@wadoon wadoon added this to the v2.12.4 milestone Mar 29, 2025
@wadoon wadoon self-assigned this Mar 29, 2025
@wadoon wadoon force-pushed the weigl/psg4-scriptast branch 2 times, most recently from d0aaa94 to 60e56c8 Compare April 13, 2025 16:30
@wadoon wadoon changed the base branch from main to weigl/psg4 April 14, 2025 12:50
@wadoon wadoon changed the base branch from weigl/psg4 to main April 15, 2025 10:48
@wadoon wadoon force-pushed the weigl/psg4-scriptast branch from 60e56c8 to a24ce7b Compare April 15, 2025 17:44
@wadoon wadoon force-pushed the weigl/psg4-scriptast branch 2 times, most recently from 44b2192 to 9b39f3d Compare May 10, 2025 14:02
@wadoon wadoon force-pushed the weigl/psg4-scriptast branch from a1f35a3 to 2aae43e Compare May 27, 2025 21:32
@wadoon wadoon force-pushed the weigl/psg4-scriptast branch 2 times, most recently from dd85e29 to 00a231d Compare June 8, 2025 13:59
@wadoon wadoon force-pushed the weigl/psg4-scriptast branch 2 times, most recently from c263c90 to dbe8815 Compare June 14, 2025 15:51
@wadoon wadoon force-pushed the weigl/psg4-scriptast branch from dbe8815 to 9eaa0f8 Compare June 29, 2025 22:46
@wadoon wadoon force-pushed the weigl/psg4-scriptast branch 2 times, most recently from 8d2ad1f to a8c4314 Compare August 2, 2025 19:56
@wadoon wadoon force-pushed the weigl/psg4-scriptast branch 2 times, most recently from a530560 to 2459cc9 Compare August 15, 2025 22:28
@wadoon wadoon requested a review from mattulbrich August 15, 2025 23:58
@wadoon wadoon force-pushed the weigl/psg4-scriptast branch 2 times, most recently from ce6e704 to f5b19b3 Compare August 16, 2025 00:26
@wadoon wadoon marked this pull request as ready for review August 16, 2025 00:27
@wadoon wadoon force-pushed the weigl/psg4-scriptast branch from f5b19b3 to 8b9c5c2 Compare August 16, 2025 06:14
@wadoon wadoon force-pushed the weigl/psg4-scriptast branch from 8b9c5c2 to aeb13df Compare September 2, 2025 00:54
Copy link
Member

@mattulbrich mattulbrich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

Thanks for the comments. Appreciate that.
Made a few suggestions. Mostly on naming and documentation.

Have not actually run it, but since we plan to extend this to JML scripts, it will be tested thoroughly soon.

@wadoon wadoon force-pushed the weigl/psg4-scriptast branch 2 times, most recently from b1e0bec to f8ac039 Compare September 7, 2025 02:45
@wadoon wadoon enabled auto-merge September 7, 2025 02:46
@wadoon
Copy link
Member Author

wadoon commented Sep 7, 2025

Removed the merge commit and rebased on main. Reviewer comments addressed.

@wadoon wadoon force-pushed the weigl/psg4-scriptast branch from f8ac039 to 559f4f3 Compare September 7, 2025 02:47
@wadoon wadoon added this pull request to the merge queue Sep 7, 2025
Merged via the queue into main with commit 3f35bf9 Sep 7, 2025
35 checks passed
@wadoon wadoon deleted the weigl/psg4-scriptast branch September 7, 2025 14:12
@mattulbrich mattulbrich mentioned this pull request Sep 8, 2025
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants