Syntax Tree Recovery Using AST Models for Real-Time Editing

Resolve Bottlenecks,
Find Innovative Solutions
Generate 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

VSEngineering 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

Engineering Contradiction:
Improveparsing reliabilityVSAvoidreal-time code modification capability
Core Design Contradiction:
ReliabilityVSProductivity

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

Inventive Principle:
Principle #10Preliminary action

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

Inventive Principle:
Principle #23Feedback

2Reliability

If a correct AST is obtained after syntax errors, then code features remain valid, but traditional methods cannot recover from parsing errors

Engineering Contradiction:
ImproveAST correctnessVSAvoiderror recovery mechanism complexity
Core Design Contradiction:
ReliabilityVSDevice complexity

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

Inventive Principle:
Principle #24Intermediary (Mediator)

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

Inventive Principle:
Principle #1Segmentation

3Productivity

If real-time code modification is allowed, then user productivity improves, but syntax errors cause temporary invalidation of code features

Engineering Contradiction:
Improvereal-time code editing efficiencyVSAvoidcode feature validity
Core Design Contradiction:
ProductivityVSReliability

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

Inventive Principle:
Principle #20Continuity of useful action

Data Source

PatentUS20250272087A1Syntax Tree Recovery Method and Related Apparatus
Publication Date: 2025.08.28 HUAWEI CLOUD COMPUTING TECHNOLOGIES CO LTD
  • US20250272087A1 patent drawing
  • US20250272087A1 patent drawing
  • US20250272087A1 patent drawing

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.