CN117632106A - Code complement method, device, equipment and storage medium - Google Patents

Code complement method, device, equipment and storage medium Download PDF

Info

Publication number
CN117632106A
CN117632106A CN202311561704.1A CN202311561704A CN117632106A CN 117632106 A CN117632106 A CN 117632106A CN 202311561704 A CN202311561704 A CN 202311561704A CN 117632106 A CN117632106 A CN 117632106A
Authority
CN
China
Prior art keywords
current
node
current input
input position
code
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202311561704.1A
Other languages
Chinese (zh)
Inventor
周立功
王俊圣
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Guangzhou Zhiyuan Electronics Co Ltd
Original Assignee
Guangzhou Zhiyuan Electronics Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Guangzhou Zhiyuan Electronics Co Ltd filed Critical Guangzhou Zhiyuan Electronics Co Ltd
Priority to CN202311561704.1A priority Critical patent/CN117632106A/en
Publication of CN117632106A publication Critical patent/CN117632106A/en
Pending legal-status Critical Current

Links

Classifications

    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Stored Programmes (AREA)

Abstract

The embodiment of the application provides a code complement method, a device, equipment and a storage medium, wherein the method comprises the following steps: acquiring current code data of a code editing interface; analyzing the current code data and generating a fault-tolerant grammar tree; acquiring a complement recommendation list corresponding to the current input content according to the fault-tolerant grammar tree and the current input position; determining a current node corresponding to the current input position in the fault-tolerant grammar tree, and determining that the current input position is positioned at the statement position of the current compiling block according to the associated node information of the current node; under the condition that the current input position meets the set sentence head position condition, adding an assignment symbol to the recommended completion variable in the completion recommendation list to obtain a target completion variable; and displaying the target completion variable corresponding to the current input position. The method and the device have the advantages that assignment symbols are not required to be manually input by a developer, and coding efficiency is improved.

Description

Code complement method, device, equipment and storage medium
Technical Field
The embodiment of the application relates to the technical field of computers, in particular to a code complement method, a device, equipment and a storage medium.
Background
Code completion is a programming tool or function that is intended to help developers write code faster. It is typically implemented in an integrated development environment or code editor. Code completion may improve coding efficiency by automatically completing the code, providing suggestions, or popup documents, etc. When a developer enters a portion of the code, the code patch automatically displays possible options. The developer can select the desired option without typing the entire word or phrase.
However, the existing code editor generally performs variable complement only for user input, has single function, and is easy to cause inconvenience to developers, so that coding efficiency is low.
Disclosure of Invention
The embodiment of the application provides a code completion method, a device, equipment and a storage medium, which solve the problems that the existing code editor only carries out variable completion on user input, has single function, is easy to cause inconvenience of developers and low coding efficiency, and realizes the purposes of effectively determining the code compiling position of the current input position by analyzing a fault-tolerant grammar tree generated by current code data, accurately judging whether the current input position is positioned at the head of a compiling block by combining the associated node information of the current input position mapped to the fault-tolerant grammar tree, thereby reasonably carrying out the completion of a value-assigned symbol of a recommended variable, avoiding the manual input of the value-assigned symbol by the developer and improving the coding efficiency.
In a first aspect, an embodiment of the present application provides a code complement method, including:
acquiring current code data of a code editing interface;
analyzing the current code data and generating a fault-tolerant grammar tree;
acquiring a complement recommendation list corresponding to the current input content according to the fault-tolerant grammar tree and the current input position;
determining a current node corresponding to the current input position in the fault-tolerant grammar tree, and determining the statement position of the current input position in the current compiling block according to the associated node information of the current node;
under the condition that the current input position meets the set sentence head position condition, adding an assignment symbol to the recommended completion variable in the completion recommendation list to obtain a target completion variable;
and displaying the target completion variable corresponding to the current input position.
Optionally, the complement recommendation list includes a function name and a code variable;
after the obtaining of the complement recommendation list corresponding to the current input content, the method further comprises:
and removing the function name and the structural body variable in the code variable by traversing the complement recommendation list to obtain a new complement recommendation list, wherein the new complement recommendation list comprises a recommendation complement variable.
Optionally, the determining, according to the associated node information of the current node, that the current input position is located at the sentence position of the current compiling block includes:
determining that the current input position is positioned at the statement position of the current compiling block based on the type of the father node of the current node under the condition that the current node does not have a front brother node;
and determining that the current input position is positioned at the statement position of the current compiling block based on the type of the father node of the current node and the number and the type of the front brother nodes under the condition that the front brother nodes exist in the current node.
Optionally, the determining, based on the type of the parent node of the current node, that the current input position is located at the sentence position of the current compiled block includes:
if the father node of the current node does not belong to the first key type, determining that the current input position is positioned at the sentence head position of the current compiling block;
and if the father node of the current node belongs to the first key type, determining that the current input position is positioned at the non-period position of the current compiling block.
Optionally, the determining, based on the type of the parent node of the current node and the number and types of the leading sibling nodes, that the current input position is located at the sentence position of the current compiled block includes:
if the father node of the current node belongs to the second key type, determining that the current input position is positioned at the statement position of the current compiling block based on the number of the leading brother nodes and the symbol type;
and if the father node of the current node does not belong to the second key type, determining that the current input position is positioned at the non-period position of the current compiling block.
Optionally, the determining, based on the number of the leading sibling nodes and the symbol type, that the current input position is located at the sentence position of the current compiled block includes:
if the number of the front brother nodes is smaller than a first threshold value, determining that the current input position is located at the sentence head position of the current compiling block;
and if the number of the leading brother nodes is greater than or equal to a first threshold value and a first preset symbol exists in the leading brother nodes, determining that the current input position is positioned at the sentence head position of the current compiling block.
Optionally, in the case that the current node has a leading sibling node, the method further includes:
if the front brother node is provided with the child node, the child node at the tail position is taken as a target brother node;
determining that the current input position is positioned at the sentence head position of the current compiling block under the condition that the target brother node belongs to a third key type;
and under the condition that the target brother node does not belong to the third key type, determining that the current input position is positioned at the non-period position of the current compiling block.
In a second aspect, an embodiment of the present application further provides a code complement apparatus, where the code complement apparatus includes:
an acquisition unit configured to acquire current code data of a code editing interface;
the grammar tree generating unit is configured to analyze the current code data and generate a fault-tolerant grammar tree;
the recommendation list acquisition unit is configured to acquire a complement recommendation list corresponding to the current input content according to the fault-tolerant grammar tree and the current input position;
an input position determining unit, configured to determine a current node corresponding to the current input position in the fault-tolerant syntax tree, and determine, according to associated node information of the current node, that the current input position is located at a sentence position of a current compiling block;
the assignment symbol completion unit is configured to add assignment symbols to recommended completion variables in the completion recommendation list to obtain target completion variables under the condition that the current input position meets the set sentence head position condition;
and the variable display unit is configured to display the target complement variable corresponding to the current input position.
Optionally, the complement recommendation list includes a function name and a code variable, and the code complement device further includes:
and the variable removing unit is configured to remove the function name and the structural body variable in the code variable through traversing the complement recommendation list to obtain a new complement recommendation list, wherein the new complement recommendation list comprises the recommended complement variable.
Optionally, the input position determining unit includes:
the first position determining module is configured to determine that the current input position is positioned at the statement position of the current compiling block based on the type of the father node of the current node under the condition that the current node does not have the front brother node;
and the second position determining module is configured to determine that the current input position is positioned at the statement position of the current compiling block based on the type of the father node of the current node and the number and the type of the front brother nodes when the front brother nodes exist in the current node.
Optionally, the first location determining module is specifically configured to:
if the father node of the current node does not belong to the first key type, determining that the current input position is positioned at the sentence head position of the current compiling block;
and if the father node of the current node belongs to the first key type, determining that the current input position is positioned at the non-sentence head position of the current compiling block.
Optionally, the second location determining module is specifically configured to:
if the father node of the current node belongs to the second key type, determining that the current input position is positioned at the statement position of the current compiling block based on the number of the preposed brother nodes and the symbol type;
if the father node of the current node does not belong to the second key type, determining that the current input position is positioned at the non-period position of the current compiling block.
Optionally, the second location determining module is specifically configured to:
if the number of the front brother nodes is smaller than a first threshold value, determining that the current input position is positioned at the sentence head position of the current compiling block;
if the number of the leading brother nodes is greater than or equal to a first threshold value, and a first preset symbol exists in the leading brother nodes, determining that the current input position is positioned at the sentence head position of the current compiling block.
Optionally, the second location determination module is specifically configured to
If the front brother node is provided with the child node, the child node at the tail position is taken as the target brother node;
under the condition that the target brother node belongs to the third key type, determining that the current input position is positioned at the sentence head position of the current compiling block;
and under the condition that the target brother node does not belong to the third key type, determining that the current input position is positioned at the non-sentence head position of the current compiling block.
In a third aspect, an embodiment of the present application further provides a code complement apparatus, including: one or more processors; and the storage device is configured to store one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors are enabled to implement the code complement method disclosed by the embodiment of the application.
In a fourth aspect, embodiments of the present application also provide a non-volatile storage medium storing computer-executable instructions that, when executed by a computer processor, are configured to perform the code complement method described in embodiments of the present application.
In the embodiment of the application, the current code data of the code editing interface is obtained; analyzing the current code data and generating a fault-tolerant grammar tree; acquiring a complement recommendation list corresponding to the current input content according to the fault-tolerant grammar tree and the current input position; determining a current node corresponding to the current input position in the fault-tolerant grammar tree, and determining that the current input position is positioned at the statement position of the current compiling block according to the associated node information of the current node; under the condition that the current input position meets the set sentence head position condition, adding an assignment symbol to the recommended completion variable in the completion recommendation list to obtain a target completion variable; and displaying the target completion variable corresponding to the current input position. The method and the device have the advantages that the fault-tolerant grammar tree generated by analyzing the current code data is realized, the code compiling position of the current input position is effectively determined, whether the current input position is positioned at the sentence head of the compiling block is accurately judged by combining the associated node information of the current input position mapped to the fault-tolerant grammar tree, so that the completion of the assignment symbol of the recommended variable is reasonably carried out, the manual input of the assignment symbol by a developer is not required, and the coding efficiency is improved.
Drawings
Fig. 1 is a flowchart of a code complement method provided in an embodiment of the present application;
FIG. 2 is a flowchart of a method for determining a sentence position of a current input position according to an embodiment of the present application;
FIG. 3 is a flowchart of a method for determining whether a current input position is at a period position according to an embodiment of the present application;
FIG. 4 is a flowchart of another method for determining a sentence position of a current input position according to an embodiment of the present application;
FIG. 5 is a flowchart of another method for determining whether a current input position is at a period position according to an embodiment of the present application;
FIG. 6 is a flowchart of another method for determining a sentence position of a current input position according to an embodiment of the present application;
fig. 7 is a block diagram of a code complement device according to an embodiment of the present application;
fig. 8 is a schematic structural diagram of a code complement device according to an embodiment of the present application.
Detailed Description
Embodiments of the present application are described in further detail below with reference to the accompanying drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the embodiments of the application and are not limiting of the embodiments of the application. It should be further noted that, for convenience of description, only some, but not all of the structures related to the embodiments of the present application are shown in the drawings.
The terms first, second and the like in the description and in the claims, are used for distinguishing between similar objects and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used may be interchanged, as appropriate, such that embodiments of the present application may be implemented in sequences other than those illustrated or described herein, and that the objects identified by "first," "second," etc. are generally of a type and not limited to the number of objects, e.g., the first object may be one or more. Furthermore, in the description and claims, "and/or" means at least one of the connected objects, and the character "/", generally means that the associated object is an "or" relationship.
In the code completion method provided in the embodiment of the present application, the execution body of each step may be a computer device, where the computer device refers to any electronic device having data computing, processing and storage capabilities, for example, a terminal device such as a PC (Personal Computer ) or a device such as a server, which is not limited in this embodiment of the present application.
Fig. 1 is a flowchart of a code complement method provided in an embodiment of the present application, where the code complement method may be implemented by using a code complement device as an execution body. As shown in fig. 1, the code complement method specifically includes the following steps:
step S101, current code data of a code editing interface are obtained.
The code editing interface may be a user interface of a software tool for writing, editing and managing computer code, on which a developer may perform code editing, and the current code data may be a code portion of the code editing interface in which the developer is in an editing state.
And S102, analyzing the current code data and generating a fault-tolerant grammar tree.
The parsing of the current code data may include lexical analysis, which may be dividing the current code data into a series of lexical units, such as identifiers, keywords, operators, and constants, and syntax analysis, which may be organizing the lexical units into a syntax structure according to a syntax rule of a programming language, which in the embodiment of the present application may be a formal representation of a fault-tolerant syntax tree, wherein each node represents one syntax unit, such as a sentence, expression, operator, etc., and a sub-node represents its sub-structure. It should be noted that the fault tolerant syntax tree may allow a certain degree of syntax error in the syntax analysis stage and still generate an effective syntax tree, so that the code editing is more flexible, and some common errors can be handled without causing failure of the whole parsing process due to a small error.
And step S103, acquiring a complement recommendation list corresponding to the current input content according to the fault-tolerant grammar tree and the current input position.
The current input position can be a cursor position input in the code editing interface, and is realized by monitoring a cursor movement event of a user or inquiring the current cursor position of the code editor. In combination with the fault tolerant syntax tree, the code context where the current input position is located, including the function, class, code block, etc. where the current input position is located, can be analyzed. Based on the context information, language specifications, library, and other reference information, a full recommendation list may be obtained, including keywords, function names, variable names, and the like.
Optionally, the complement recommendation list includes function names and code variables, and for the scene of variable assignment by the user, no assignment symbol is required to be added to the function names, so that deletion can be performed, and the subsequent data processing efficiency is improved. Specifically, after obtaining the complement recommendation list corresponding to the current input content, the method further includes:
and removing the function names and the structural body variables in the code variables by traversing the complement recommendation list to obtain a new complement recommendation list, wherein the new complement recommendation list comprises recommended complement variables.
Therefore, the complement recommendation list can be simplified, the requirement of a developer on adding assignment symbols to the variables is effectively met, and the processing efficiency is improved.
Step S104, determining a current node corresponding to the current input position in the fault-tolerant grammar tree, and determining that the current input position is positioned at the statement position of the current compiling block according to the associated node information of the current node.
The fault-tolerant grammar tree can be traversed based on a preset mapping relation between the input position and the fault-tolerant grammar tree, and the smallest grammar tree node containing the current input position is searched to be used as the corresponding current node. In addition, the associated node information of the current node can be information such as brother nodes, father nodes and child nodes, the current input position can be effectively positioned to the statement position of the current compiling block through the associated node information, the possibility of variable assignment input of a developer can be judged at the current input position through referencing the statement position, and whether the completion of assignment symbols of variables is provided is further selected.
In one embodiment, fig. 2 is a flowchart of a method for determining a sentence position of a current input position according to an embodiment of the present application, and as shown in fig. 2, a specific process for determining a sentence position of a current input position includes the following steps:
in step S1041, if the current node does not have a leading sibling node, the current input position is determined to be located at the statement position of the current compiled block based on the type of the parent node of the current node.
Wherein sibling nodes may be different branches belonging to the same hierarchy in the fault tolerant syntax tree, e.g. statements in a code block may be sibling nodes etc. If the current node does not have a leading sibling, then the syntax element corresponding to the current node is an isolated structure, e.g., a separate expression, a separate statement, etc. By combining the types of the father nodes, the statement position of the current input position corresponding to the current node can be determined.
Optionally, fig. 3 is a flowchart of a method for determining whether a current input position is located at a period end position according to an embodiment of the present application, and as shown in fig. 3, a specific process for determining whether the current input position is located at the period end position includes the following steps:
step S10411, determining that the current input position is located at the sentence head position of the current compiling block if the parent node of the current node does not belong to the first key type.
Step S10412, determining that the current input position is located at the non-period position of the current compiled block if the parent node of the current node belongs to the first key type.
The first key type may include "if", "case", "while", "for", "{" and "(" for which the parent node does not belong to the first key type, the current input position may be determined to be located at a sentence head position of the current compiled block, and for which the parent node belongs to the first key type, a scene in which the current input position does not satisfy the requirement of variable assignment may be determined to be located at a non-sentence head position of the current compiled block.
In step S1042, if the current node has a leading sibling node, determining that the current input position is located at the statement position of the current compiled block based on the type of the parent node of the current node and the number and type of the leading sibling nodes.
If the current node has a leading brother node, the type of the father node, the number and the type of the leading brother node are integrated to judge the statement position of the current input position.
In one embodiment, fig. 4 is a flowchart of another method for determining a sentence position of a current input position according to an embodiment of the present application, where a current node has a leading sibling node, and as shown in fig. 4, a specific process for determining a sentence position of a current input position includes the following steps:
step S10421, determining that the current input position is located at the sentence position of the current compiled block based on the type of the parent node of the current node and the number and type of the leading sibling nodes.
In step S10422, if the leading sibling node is provided with a child node, the child node at the end position is taken as the target sibling node.
In step S10423, in the case that the target sibling node belongs to the third key type, it is determined that the current input position is located at the position of the sentential head of the current compiled block.
In step S10424, in case that the target sibling node does not belong to the third key type, it is determined that the current input position is located at a non-period position of the current compiled block.
Wherein the third critical type may include "; "else", "do", "the", "action", "case", "configuration", "for", "function", "function_block", "if", "program", "repeat", "resource", "struct", "transmission", "type", "unit", "var", "while". Therefore, the statement position of the current input position in the current compiling block can be effectively determined by combining the child node type of the front brother node.
Optionally, fig. 5 is a flowchart of another method for determining whether the current input position is at the position of the sentence head according to the embodiment of the present application, which needs to comprehensively consider the type of the parent node of the current node and the number and types of the leading sibling nodes, and as shown in fig. 5, a specific process for determining whether the current input position is at the position of the sentence head includes the following steps:
step S104211, if the parent node of the current node belongs to the second key type, determining that the current input position is located at the sentence position of the current compiling block based on the number of leading sibling nodes and the symbol type.
Step S104212, if the parent node of the current node does not belong to the second key type, determining that the current input position is located at the non-period position of the current compiled block.
The second key type may include PROGRAM, FUNCTION or function_block type, the PROGRAM type may represent an entry point of the entire PROGRAM or a body of the PROGRAM, and the FUNCTION type and the function_block type may represent FUNCTIONs or methods in a programming language, among others. For the second key type, it may be determined that the current input position is located at a non-period position of the current compiling block, and for the second key type, it is necessary to further determine that the current input position is located at a sentence position of the current compiling block by combining the number of leading sibling nodes and the symbol type.
In one embodiment, fig. 6 is a flowchart of another method for determining a statement position of a current input position according to an embodiment of the present application, and as shown in fig. 6, a specific process for determining that the current input position is located at a statement position of a current compiled block includes the following steps:
in step S1042111, if the number of the leading sibling nodes is less than the first threshold, it is determined that the current input position is located at the period position of the current compiled block.
In step S1042112, if the number of the leading sibling nodes is greater than or equal to the first threshold, and a first preset symbol exists in the leading sibling nodes, it is determined that the current input position is located at the period position of the current compiled block.
The setting of the first threshold may be determined based on the complexity of the current code data, taking the first threshold as 2 as an example, where the number of leading sibling nodes is 1, then it may be determined that the current input position is located at the position of the sentential head of the current compiled block, the number of leading sibling nodes is greater than or equal to 2, and a symbol ":", then it may be determined that the current input position is located at the position of the sentential head of the current compiled block. Therefore, whether the current input position is at the position of the sentence head can be effectively judged according to the brother node information.
Step S105, under the condition that the current input position meets the set period head position condition, adding an assignment symbol to the recommended completion variable in the completion recommendation list to obtain a target completion variable.
The period position condition may be used to determine whether the current input position is located at the period of the coding block, and under the condition that the current input position is located at the period, a developer may need to perform variable assignment, so that an assignment symbol ": =" may be added to the recommended completion variable, thereby obtaining the target completion variable.
And step S106, displaying the target completion variable corresponding to the current input position.
The display mode of the target completion variable can be a drop-down list or a pop-up window, and a user can quickly complete code writing by selecting the required target completion variable. When the user completes the selection of the target completion variable, the editor may insert the option into the code to complete the code completion.
The current code data of the code editing interface is obtained; analyzing the current code data and generating a fault-tolerant grammar tree; acquiring a complement recommendation list corresponding to the current input content according to the fault-tolerant grammar tree and the current input position; determining a current node corresponding to the current input position in the fault-tolerant grammar tree, and determining that the current input position is positioned at the statement position of the current compiling block according to the associated node information of the current node; under the condition that the current input position meets the set sentence head position condition, adding an assignment symbol to the recommended completion variable in the completion recommendation list to obtain a target completion variable; and displaying the target completion variable corresponding to the current input position. The method and the device have the advantages that the fault-tolerant grammar tree generated by analyzing the current code data is realized, the code compiling position of the current input position is effectively determined, whether the current input position is positioned at the sentence head of the compiling block is accurately judged by combining the associated node information of the current input position mapped to the fault-tolerant grammar tree, so that the completion of the assignment symbol of the recommended variable is reasonably carried out, the manual input of the assignment symbol by a developer is not required, and the coding efficiency is improved.
Fig. 7 is a block diagram of a code complement device according to an embodiment of the present application, where the device is configured to execute the code complement method provided in the foregoing embodiment, and has functional modules and beneficial effects corresponding to the execution method. As shown in fig. 7, the code complement apparatus specifically includes:
an acquisition unit 101 configured to acquire current code data of a code editing interface;
a syntax tree generating unit 102 configured to parse the current code data and generate a fault-tolerant syntax tree;
a recommendation list obtaining unit 103 configured to obtain a complement recommendation list corresponding to the current input content according to the fault-tolerant syntax tree and the current input position;
an input position determining unit 104 configured to determine a current node corresponding to the current input position in the fault-tolerant syntax tree, and determine, according to the associated node information of the current node, that the current input position is located at a sentence position of the current compiling block;
an assigned symbol completion unit 105 configured to add an assigned symbol to a recommended completion variable in the completion recommendation list to obtain a target completion variable when the current input position satisfies a set period position condition;
the variable display unit 106 is configured to display the target completion variable corresponding to the current input position.
According to the method, the fault-tolerant grammar tree generated by analyzing the current code data is realized, the code compiling position where the current input position is located is effectively determined, whether the current input position is located at the sentence head of the compiling block is accurately judged by combining the associated node information of the current input position mapped to the fault-tolerant grammar tree, so that the completion of the assignment symbol of the recommended variable is reasonably carried out, a developer is not required to manually input the assignment symbol, and the coding efficiency is improved.
In one possible embodiment, the complement recommendation list includes a function name and a code variable, and the code complement apparatus further includes:
and the variable removing unit is configured to remove the function name and the structural body variable in the code variable through traversing the complement recommendation list to obtain a new complement recommendation list, wherein the new complement recommendation list comprises the recommended complement variable.
In one possible embodiment, the input position determining unit 104 includes:
the first position determining module is configured to determine that the current input position is positioned at the statement position of the current compiling block based on the type of the father node of the current node under the condition that the current node does not have the front brother node;
and the second position determining module is configured to determine that the current input position is positioned at the statement position of the current compiling block based on the type of the father node of the current node and the number and the type of the front brother nodes when the front brother nodes exist in the current node.
In one possible embodiment, the first location determining module is specifically configured to:
if the father node of the current node does not belong to the first key type, determining that the current input position is positioned at the sentence head position of the current compiling block;
and if the father node of the current node belongs to the first key type, determining that the current input position is positioned at the non-sentence head position of the current compiling block.
In one possible embodiment, the second location determining module is specifically configured to:
if the father node of the current node belongs to the second key type, determining that the current input position is positioned at the statement position of the current compiling block based on the number of the preposed brother nodes and the symbol type;
if the father node of the current node does not belong to the second key type, determining that the current input position is positioned at the non-period position of the current compiling block.
In one possible embodiment, the second location determining module is specifically configured to:
if the number of the front brother nodes is smaller than a first threshold value, determining that the current input position is positioned at the sentence head position of the current compiling block;
if the number of the leading brother nodes is greater than or equal to a first threshold value, and a first preset symbol exists in the leading brother nodes, determining that the current input position is positioned at the sentence head position of the current compiling block.
In a possible embodiment, the second position determining module is specifically configured to
If the front brother node is provided with the child node, the child node at the tail position is taken as the target brother node;
under the condition that the target brother node belongs to the third key type, determining that the current input position is positioned at the sentence head position of the current compiling block;
and under the condition that the target brother node does not belong to the third key type, determining that the current input position is positioned at the non-sentence head position of the current compiling block.
Fig. 8 is a schematic structural diagram of a code complement device according to an embodiment of the present application, and as shown in fig. 8, the device includes a processor 201, a memory 202, an input device 203, and an output device 204; the number of processors 201 in the device may be one or more, one processor 201 being taken as an example in fig. 8; the processor 201, memory 202, input devices 203, and output devices 204 in the apparatus may be connected by a bus or other means, for example in fig. 8. The memory 202 is a computer-readable storage medium, and may be configured to store a software program, a computer-executable program, and modules, such as program instructions/modules corresponding to the code complement method in the embodiments of the present application. The processor 201 executes various functional applications of the device and data processing by running software programs, instructions and modules stored in the memory 202, i.e., implements the code complement method described above. The input device 203 may be configured to receive input numeric or character information and to generate key signal inputs related to user settings and function control of the apparatus. The output device 204 may include a display device such as a display screen.
The code complement device provided by the above embodiment can be used for executing the code complement method provided by any embodiment, and has corresponding functions and beneficial effects.
The present application also provides a non-volatile storage medium containing computer-executable instructions that, when executed by a computer processor, are configured to perform a code complement method as described in the above embodiments, wherein the code complement method comprises: acquiring current code data of a code editing interface; analyzing the current code data and generating a fault-tolerant grammar tree; acquiring a complement recommendation list corresponding to the current input content according to the fault-tolerant grammar tree and the current input position; determining a current node corresponding to the current input position in the fault-tolerant grammar tree, and determining that the current input position is positioned at the statement position of the current compiling block according to the associated node information of the current node; under the condition that the current input position meets the set sentence head position condition, adding an assignment symbol to the recommended completion variable in the completion recommendation list to obtain a target completion variable; and displaying the target completion variable corresponding to the current input position.
Storage media-any of various types of memory devices or storage devices. The term "storage medium" is intended to include: mounting media such as CD-ROM, floppy disk or tape devices; computer system memory or random access memory such as DRAM, DDR RAM, SRAM, EDO RAM, lanbas (Rambus) RAM, etc.; nonvolatile memory such as flash memory, magnetic media, and optical storage; registers or other similar types of memory elements, etc. The storage medium may also include other types of memory or combinations thereof. In addition, the storage medium may be located in a first computer system in which the program is executed, or may be located in a second, different computer system connected to the first computer system through a network such as the internet. The second computer system may provide program instructions to the first computer for execution. The term "storage medium" may include two or more storage media residing in different locations (e.g., in different computer systems connected by a network). The storage medium may store program instructions (e.g., embodied as a computer program) executable by one or more processors.
Of course, the storage medium containing the computer executable instructions provided in the embodiments of the present application is not limited to the code complement method described above, and may also perform the related operations in the code complement method provided in any embodiment of the present application.
It should be noted that, in the embodiment of the code complement system, each unit and module included are only divided according to the functional logic, but not limited to the above division, so long as the corresponding functions can be implemented; in addition, the specific names of the functional units are also only for convenience of distinguishing from each other, and are not configured to limit the protection scope of the embodiments of the present application.
It should be noted that, the numbers of the steps in the solution are only used to describe the overall design framework of the solution, and do not represent the necessary sequence relationship between the steps. On the basis that the whole implementation process accords with the whole design framework of the scheme, the method belongs to the protection scope of the scheme, and the literal sequence during description is not an exclusive limit on the specific implementation process of the scheme. It will be appreciated by those skilled in the art that embodiments of the present application may be provided as a method, system, or computer program product. In one typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory. The memory may include volatile memory in a computer-readable medium, random Access Memory (RAM) and/or nonvolatile memory, etc., such as Read Only Memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.
It should also be noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article or apparatus that comprises an element.
Note that the above is only a preferred embodiment of the present invention and the technical principle applied. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, while the invention has been described in connection with the above embodiments, the invention is not limited to the embodiments, but may be embodied in many other equivalent forms without departing from the spirit or scope of the invention, which is set forth in the following claims.

Claims (10)

1. A code complement method, comprising:
acquiring current code data of a code editing interface;
analyzing the current code data and generating a fault-tolerant grammar tree;
acquiring a complement recommendation list corresponding to the current input content according to the fault-tolerant grammar tree and the current input position;
determining a current node corresponding to the current input position in the fault-tolerant grammar tree, and determining the statement position of the current input position in the current compiling block according to the associated node information of the current node;
under the condition that the current input position meets the set sentence head position condition, adding an assignment symbol to the recommended completion variable in the completion recommendation list to obtain a target completion variable;
and displaying the target completion variable corresponding to the current input position.
2. The code complement method of claim 1 wherein the complement recommendation list comprises function names and code variables;
after the obtaining of the complement recommendation list corresponding to the current input content, the method further comprises:
and removing the function name and the structural body variable in the code variable by traversing the complement recommendation list to obtain a new complement recommendation list, wherein the new complement recommendation list comprises a recommendation complement variable.
3. The code completion method according to claim 1, wherein determining that the current input position is located at a statement position of a current compiled block according to the associated node information of the current node comprises:
determining that the current input position is positioned at the statement position of the current compiling block based on the type of the father node of the current node under the condition that the current node does not have a front brother node;
and determining that the current input position is positioned at the statement position of the current compiling block based on the type of the father node of the current node and the number and the type of the front brother nodes under the condition that the front brother nodes exist in the current node.
4. A code completion method according to claim 3, wherein said determining that said current input position is located at a statement position of a current compiled block based on a type of a parent node of said current node comprises:
if the father node of the current node does not belong to the first key type, determining that the current input position is positioned at the sentence head position of the current compiling block;
and if the father node of the current node belongs to the first key type, determining that the current input position is positioned at the non-period position of the current compiling block.
5. A code completion method according to claim 3, wherein said determining that said current input location is at a statement location of a current compiled block based on a type of a parent node of said current node and a number and type of said leading sibling nodes comprises:
if the father node of the current node belongs to the second key type, determining that the current input position is positioned at the statement position of the current compiling block based on the number of the leading brother nodes and the symbol type;
and if the father node of the current node does not belong to the second key type, determining that the current input position is positioned at the non-period position of the current compiling block.
6. The code completion method of claim 5, wherein said determining that the current input location is at a statement location of a current compiled block based on the number of leading sibling nodes and a symbol type comprises:
if the number of the front brother nodes is smaller than a first threshold value, determining that the current input position is located at the sentence head position of the current compiling block;
and if the number of the leading brother nodes is greater than or equal to a first threshold value and a first preset symbol exists in the leading brother nodes, determining that the current input position is positioned at the sentence head position of the current compiling block.
7. A code completion method according to claim 3, wherein in the event that said current node has a leading sibling, further comprising:
if the front brother node is provided with the child node, the child node at the tail position is taken as a target brother node;
determining that the current input position is positioned at the sentence head position of the current compiling block under the condition that the target brother node belongs to a third key type;
and under the condition that the target brother node does not belong to the third key type, determining that the current input position is positioned at the non-period position of the current compiling block.
8. Code complement apparatus, characterized by comprising:
an acquisition unit configured to acquire current code data of a code editing interface;
the grammar tree generating unit is configured to analyze the current code data and generate a fault-tolerant grammar tree;
the recommendation list acquisition unit is configured to acquire a complement recommendation list corresponding to the current input content according to the fault-tolerant grammar tree and the current input position;
an input position determining unit, configured to determine a current node corresponding to the current input position in the fault-tolerant syntax tree, and determine, according to associated node information of the current node, that the current input position is located at a sentence position of a current compiling block;
the assignment symbol completion unit is configured to add assignment symbols to recommended completion variables in the completion recommendation list to obtain target completion variables under the condition that the current input position meets the set sentence head position condition;
and the variable display unit is configured to display the target complement variable corresponding to the current input position.
9. A code complement apparatus, the apparatus comprising: one or more processors; a storage device configured to store one or more programs that, when executed by the one or more processors, cause the one or more processors to implement the code complement method of any one of claims 1-7.
10. A non-transitory storage medium storing computer-executable instructions which, when executed by a computer processor, are configured to perform the code complement method of any one of claims 1-7.
CN202311561704.1A 2023-11-21 2023-11-21 Code complement method, device, equipment and storage medium Pending CN117632106A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311561704.1A CN117632106A (en) 2023-11-21 2023-11-21 Code complement method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311561704.1A CN117632106A (en) 2023-11-21 2023-11-21 Code complement method, device, equipment and storage medium

Publications (1)

Publication Number Publication Date
CN117632106A true CN117632106A (en) 2024-03-01

Family

ID=90020929

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311561704.1A Pending CN117632106A (en) 2023-11-21 2023-11-21 Code complement method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN117632106A (en)

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109144286A (en) * 2017-06-27 2019-01-04 北京搜狗科技发展有限公司 A kind of input method and device
CN109683907A (en) * 2018-12-29 2019-04-26 深圳乐信软件技术有限公司 Code completion method, apparatus, equipment and storage medium
CN110502227A (en) * 2019-08-28 2019-11-26 网易(杭州)网络有限公司 The method and device of code completion, storage medium, electronic equipment
CN112230781A (en) * 2019-07-15 2021-01-15 腾讯科技(深圳)有限公司 Character recommendation method and device and storage medium
CN114647408A (en) * 2022-04-02 2022-06-21 北京白海科技有限公司 Method and device for complementing codes, electronic equipment and storage medium
CN114676155A (en) * 2022-03-28 2022-06-28 阿里云计算有限公司 Code prompt information determining method, data set determining method and electronic equipment
CN114675816A (en) * 2022-03-14 2022-06-28 麒麟软件有限公司 Code completion ordering method and system based on user behaviors
CN115438070A (en) * 2022-09-26 2022-12-06 支付宝(杭州)信息技术有限公司 Method and device for automatically completing query sentence aiming at graph database

Patent Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109144286A (en) * 2017-06-27 2019-01-04 北京搜狗科技发展有限公司 A kind of input method and device
CN109683907A (en) * 2018-12-29 2019-04-26 深圳乐信软件技术有限公司 Code completion method, apparatus, equipment and storage medium
CN112230781A (en) * 2019-07-15 2021-01-15 腾讯科技(深圳)有限公司 Character recommendation method and device and storage medium
US20210294432A1 (en) * 2019-07-15 2021-09-23 Tencent Technology (Shenzhen) Company Limited Character recommending method and apparatus, and computer device and storage medium
CN110502227A (en) * 2019-08-28 2019-11-26 网易(杭州)网络有限公司 The method and device of code completion, storage medium, electronic equipment
CN114675816A (en) * 2022-03-14 2022-06-28 麒麟软件有限公司 Code completion ordering method and system based on user behaviors
CN114676155A (en) * 2022-03-28 2022-06-28 阿里云计算有限公司 Code prompt information determining method, data set determining method and electronic equipment
CN114647408A (en) * 2022-04-02 2022-06-21 北京白海科技有限公司 Method and device for complementing codes, electronic equipment and storage medium
CN115438070A (en) * 2022-09-26 2022-12-06 支付宝(杭州)信息技术有限公司 Method and device for automatically completing query sentence aiming at graph database

Similar Documents

Publication Publication Date Title
CN106919434B (en) Code generation method and device
US7509632B2 (en) Method and apparatus for analyzing call history data derived from execution of a computer program
US9208057B2 (en) Efficient model checking technique for finding software defects
JP4148527B2 (en) Functional test script generator
CN110502227B (en) Code complement method and device, storage medium and electronic equipment
US11386154B2 (en) Method for generating a graph model for monitoring machinery health
US8458681B1 (en) Method and system for optimizing the object code of a program
US11675575B2 (en) Checking source code validity at time of code update
WO2016196701A1 (en) Natural language engine for coding and debugging
US11579856B2 (en) Multi-chip compatible compiling method and device
US20090328002A1 (en) Analysis and Detection of Responsiveness Bugs
US20150026666A1 (en) Analysis system, analysis method, and computer program product
US20110271250A1 (en) Software Development Tool
US8364696B2 (en) Efficient incremental parsing of context sensitive programming languages
US9311077B2 (en) Identification of code changes using language syntax and changeset data
US8898649B2 (en) Application program analysis method, analysis system and recording medium for identifying a contributing factor for an invalid operation of an application program
CN114003269A (en) Component processing method and device, electronic equipment and storage medium
CN107038117B (en) Web automatic testing method based on definition-reference between event processing functions
CN111460137B (en) Method, equipment and medium for identifying micro-service focus based on topic model
CN110286912B (en) Code detection method and device and electronic equipment
CN117632106A (en) Code complement method, device, equipment and storage medium
CN115705250A (en) Monitoring stack usage to optimize programs
CN114691197A (en) Code analysis method and device, electronic equipment and storage medium
Tukaram Design and development of software tool for code clone search, detection, and analysis
US8769517B2 (en) Generating a common symbol table for symbols of independent applications

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination