Syntax Tree Recovery Using AST Models for Real-Time Editing
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Existing technologies struggle to recover a correct abstract syntax tree (AST) after real-time user modifications, leading to parsing errors and temporary invalidation of code features.
Innovation Solution
A syntax tree recovery method using a trained AST recovery model to determine recovery operations based on context information and edit operations, rectifying errors in the AST to obtain a correct syntax tree.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Reliability
If code parsing is performed on modified code text, then code features can be obtained, but parsing errors occur when the code is in an incorrect intermediate state
Solution Approach 1:
The system performs preliminary parsing on the original correct AST before modifications occur. When a syntax error is detected during real-time editing, the recovery mechanism uses the pre-stored original AST as a baseline to guide correction, avoiding the need to parse from scratch and enabling faster recovery while maintaining reliability
Solution Approach 2:
The system implements a feedback loop where the parsed AST is continuously monitored for syntax errors. When errors are detected in the intermediate code state, the recovery mechanism provides corrective feedback by comparing against the original AST and applying recovery operations, allowing the system to self-correct and maintain parsing reliability during real-time modifications
2Reliability
If a correct AST is obtained after syntax errors, then code features remain valid, but traditional methods cannot recover from parsing errors
Solution Approach 1:
The system introduces an intermediary recovery mechanism that acts as a mediator between the erroneous parsed AST and the original correct AST. This intermediary component analyzes the syntax errors and generates recovery operations that transform the erroneous AST back to correctness, enabling AST recovery without requiring complete re-parsing
Solution Approach 2:
The recovery mechanism segments the error correction process into distinct operations (insertion, deletion, substitution) that can be applied individually to specific nodes in the AST. This segmentation allows the complex recovery task to be broken down into manageable steps, reducing the overall complexity of the error recovery mechanism
3Productivity
If real-time code modification is allowed, then user productivity improves, but syntax errors cause temporary invalidation of code features
Solution Approach 1:
The system maintains continuous code feature validity during real-time editing by implementing uninterrupted error recovery. When syntax errors occur during modification, the recovery mechanism continuously operates to restore the AST to a valid state, ensuring that code features remain available throughout the editing process without interruption or temporary invalidation
Data Source
AI summary
A method includes: obtaining a first abstract syntax tree corresponding to a first code text; obtaining a second code text based on an edit operation set of a user for the first code text, where a second abstract syntax tree corresponding to the second code text includes a first error, and the edit operation set includes N edit operations; determining at least one recovery operation based on a trained abstract syntax tree recovery model, the first abstract syntax tree, and the edit operation set; and modifying the first error in the second abstract syntax tree based on the at least one recovery operation, to obtain a third syntax tree.


