Code prompting method and device, equipment and storage medium
By obtaining the change operations and data of code text, using the preset syntax tree and matching cache, matching operations are performed separately for the addition and deletion operations, solving the problem of inefficient matching when changing code text in the existing technology, and achieving more efficient code prompt matching.
Patent Information
- Application Number
- CN202411429442.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-14
- Publication Date
- 2025-02-28
- Estimated Expiration
- 2044-10-14
Smart Images

Figure CN119536704A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing technology, and in particular to a code prompt method, device, equipment and storage medium. Background Art
[0002] At present, in order to improve the editing efficiency in the code editing process, there is generally a design of performing syntax matching according to the input code text and displaying code prompts according to the syntax matching results. The current method generally compares the code text with the syntax tree and performs recursive traversal matching. However, when the code text contains operations of adding content and deleting content at the same time, the recursive traversal matching steps need to be repeated each time the code text changes. The matching efficiency is low, which can easily affect the user experience when editing the code. Summary of the invention
[0003] The present invention provides a code prompt method, device, equipment and storage medium to solve one or more technical problems existing in the prior art and at least provide a beneficial choice or create conditions.
[0004] The present invention provides a code prompting method, the code prompting method comprising: Acquire the code text, compare the code text before and after the preset period according to the preset period, and determine the change operation of the code text and the code change data; Obtaining a preset syntax tree of the language corresponding to the code text; When the change operation is to add the code text, the matching cache is updated according to the code change data and the preset syntax tree, and the code prompt information is determined; When the change operation is to delete the code text, determining the code prompt information according to the code change data, the preset syntax tree and the matching cache; Output the code prompt information.
[0005] Optionally, when the change operation is to add the code text, the step of updating the matching cache according to the code change data and the preset syntax tree, and determining the code prompt information includes: When the change operation is to add the code text, the matching start position is determined according to the blank characters in the code change data, and there are several character strings after the matching start position in the code change data; Based on the order of the character strings, searching the preset syntax tree for a number of target syntax nodes that match each of the character strings; Mounting the target syntax nodes to the matching cache in an order corresponding to the character strings; The code prompt information is formed by splicing the character data of the target syntax node mounted in the matching cache.
[0006] Optionally, the matching cache includes a plurality of cache nodes, each of the cache nodes corresponds to each character in the code change data, and the step of mounting the target syntax nodes to the matching cache in an order corresponding to the character strings includes: Mounting the starting point of the target syntax node to the cache node corresponding to the first character of the string; Mounting the end point of the target syntax node to the cache node corresponding to the last character of the string; A causal relationship is established between the target grammar nodes of adjacent character strings, and the causal relationship is mounted to the cache node of the first character of the latter character string in the adjacent character strings, wherein the causal relationship represents the order between the target grammar nodes.
[0007] Optionally, when the change operation is to delete the code text, the step of determining the code prompt information according to the code change data, the preset syntax tree and the matching cache further includes: When the change operation is to delete the code text, comparing the code change data with the matching cache to determine a target cache node of the deleted code text; Deleting the start point, the end point and / or the causal relationship mounted on the target cache node; Re-determining the matching target syntax node according to the code change data, and updating the matching cache; The code prompt information is formed by splicing the character data of the target syntax node mounted in the matching cache.
[0008] Optionally, after the step of mounting the target syntax nodes to the matching cache in the order corresponding to the character strings, the method further includes: Update the code change data according to the character data of the target syntax node mounted in the matching cache; The matched target syntax node is updated according to the updated code change data, and the matching cache is updated, and the step of updating the code change data according to the character data of the target syntax node mounted in the matching cache is returned to be executed until there is no change before and after the target syntax node is updated; The step of forming the code prompt information by splicing the character data of the target syntax node mounted in the matching cache is executed.
[0009] Optionally, the step of searching the preset syntax tree for a plurality of target syntax nodes matching each of the character strings comprises: When there is no target syntax node matching the character string, a syntax error prompt is output.
[0010] Optionally, the preset syntax tree is formed by multiple leaf grammars and multiple branch grammars, the leaf grammar includes the target syntax node, and the branch grammar includes a sequential grammar, a selective matching grammar, an optional matching grammar and / or an arbitrary matching grammar.
[0011] In addition, in order to achieve the above-mentioned purpose, the present application also proposes a code prompting device, which includes: An input module, the input module is used to obtain the code text, compare the code text before and after the preset period according to the preset period, and determine the change operation of the code text and the code change data; A syntax tree module, the syntax tree module is used to obtain a preset syntax tree of the language corresponding to the code text; A matcher module, the matcher module is used to: when the change operation is to add the code text, update the matching cache according to the code change data and the preset syntax tree, and determine the code prompt information; when the change operation is to delete the code text, determine the code prompt information according to the code change data, the preset syntax tree and the matching cache; A prompt output module, wherein the prompt output module is used to output the code prompt information.
[0012] In addition, in order to achieve the above-mentioned purpose, the present application also proposes a code prompting device, which includes: a memory, a processor, and a code prompting program stored in the memory and executable on the processor, wherein the code prompting program is configured to implement the steps of the code prompting method as described in any one of the above items.
[0013] In addition, in order to achieve the above-mentioned purpose, the present application also proposes a storage medium, on which a code prompt program is stored, and when the code prompt program is executed by a processor, the steps of the code prompt method as described in any one of the above items are implemented.
[0014] The present invention has at least the following beneficial effects: by acquiring code text, comparing the changes of the code text before and after the preset period according to the preset period, determining the change operation of the code text and the code change data, on the other hand, acquiring the preset syntax tree corresponding to the language of the code text, when the change operation is to add new code text, matching is performed from the preset syntax tree according to the code change data, updating the matching cache, and then determining the code prompt information, and when the change operation is to delete the code text, combining the matching cache updated when adding the new code text, matching is performed from the preset syntax tree according to the code change data, and then determining the code prompt information, and finally outputting the code prompt information. Compared with the need to perform a recursive traversal match every time the code text is updated, the present application performs different matching operations for the newly added code text and the deleted code text, and uses the matching cache to reduce the matching operations required when deleting the code text, thereby improving the matching efficiency of the code prompt and improving the user experience when editing the code. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] The accompanying drawings are used to provide a further understanding of the technical solution of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the technical solution of the present invention and do not constitute a limitation on the technical solution of the present invention.
[0016] Figure 1 This is a flow chart of the first embodiment of the code prompt method of the present invention; Figure 2 An example diagram of a syntax tree involved in the first embodiment of the code prompt method of the present invention; Figure 3 A matching schematic diagram of the first embodiment of the code prompt method of the present invention; Figure 4 Another matching schematic diagram of the first embodiment of the code prompt method of the present invention; Figure 5 This is a connection diagram involved in the operation of an embodiment of a code prompting device of the present invention; Figure 6 The figure is a schematic diagram of the device structure involved in the operation of an embodiment of a code prompt device of the present invention. DETAILED DESCRIPTION
[0017] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0018] It should be noted that, although the functional modules are divided in the system schematic diagram and the logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the system or the order in the flowchart. The terms "first", "second", etc. in the specification, claims and the above drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0019] The embodiment of the present invention provides a code prompt method. Figure 1 , a first embodiment of the code prompt method of the present application is proposed. In this embodiment, the code prompt method includes: Step S10, obtaining the code text, comparing the code text before and after the preset period according to the preset period, and determining the change operation of the code text and the code change data.
[0020] When the user edits the code, the code text edited by the user is obtained through the code input device. In this embodiment, the language of the code text is not limited. For example, it can be a robot language code of structured text syntax. The obtained code text is compared at intervals of a preset period to compare whether the code text changes before and after the preset period. The preset period can be set to 1 second or 3 seconds, etc. By comparing the code text, the change operation of the code text can be determined when the code text changes. The change operation includes adding code text or deleting code text. Then, the code text involved in the change is determined as code change data, and the code change data is stored in the text cache. Based on this, extracting the code change data in the text cache is equivalent to extracting the code content most recently edited by the user.
[0021] Step S20, obtaining a preset syntax tree of the language corresponding to the code text.
[0022] On the other hand, a preset syntax tree corresponding to the language of the code text is obtained. The syntax tree is used to represent the syntax structure of the programming language in a tree form. Each node on the tree represents a structure of the source code. The structure at the end of the syntax tree is a syntax node. By comparing the code text with the preset syntax tree, it is possible to analyze and determine whether the code text uses syntax that conforms to the language specification.
[0023] The preset syntax tree is configured in the environment in the form of a configuration file. After the language of the code text is determined, the preset syntax tree can be obtained by loading the configuration file. For different languages, corresponding preset syntax trees are configured respectively.
[0024] Step S31, when the change operation is to add new code text, the matching cache is updated according to the code change data and the preset syntax tree, and the code prompt information is determined.
[0025] Optionally, in addition to the above-mentioned text cache for storing code change data, the present embodiment also provides a matching cache for storing the matching results of the code change data and the preset syntax tree. Specifically, when the change operation is to add new code text, the syntax node that matches the code change data is found from the preset syntax tree, and it is associated with the matching cache to realize the storage of the matching results. The syntax node includes the character data corresponding to the node, such as the syntax node of "=". The code prompt information can be obtained by extracting the character data of the syntax node associated with the matching cache and performing splicing processing.
[0026] Step S32, when the change operation is to delete the code text, determine the code prompt information according to the code change data, the preset syntax tree and the matching cache.
[0027] Optionally, when the change operation is to delete code text, the matching cache that matched the deleted code text when it was input can be combined. Through this matching cache, the syntax node that matches the deleted code text can be directly determined, and then the specific deleted content can be determined based on the code change data. Based on this, the syntax node associated with the matching cache can be directly modified, and other adaptive modifications can be made based on the code change data and the preset syntax tree to achieve the update of the matching cache, thereby determining the code prompt information after deleting the code text, without having to match the syntax node from scratch again when deleting. From the user's perspective, it is equivalent to achieving the backtracking effect of code prompts when deleting code.
[0028] Step S40: output code prompt information.
[0029] Furthermore, the code prompt information is output in the user code editing interface to prompt the user of the code syntax. The output style and position of the code prompt information are not limited in this embodiment. For example, it can be displayed below the input cursor or in a new window.
[0030] The embodiments of the present invention have at least the following beneficial effects: by acquiring the code text, comparing the changes of the code text before and after the preset period according to the preset period, determining the change operation of the code text and the code change data, on the other hand, acquiring the preset syntax tree corresponding to the language of the code text, when the change operation is to add new code text, matching is performed from the preset syntax tree according to the code change data, updating the matching cache, and then determining the code prompt information, and when the change operation is to delete the code text, combining the matching cache updated when adding the new code text, matching is performed from the preset syntax tree according to the code change data, and then determining the code prompt information, and finally outputting the code prompt information. Compared with the need to perform a recursive traversal match every time the code text is updated, the present application performs different matching operations for the newly added code text and the deleted code text, and uses the matching cache to reduce the matching operations required when deleting the code text, thereby improving the matching efficiency of the code prompt and improving the user experience when editing the code.
[0031] Furthermore, in this embodiment, the preset syntax tree is formed by a plurality of leaf grammars and a plurality of branch grammars, and the branch grammars include sequential grammars, selective matching grammars, optional matching grammars and / or arbitrary matching grammars.
[0032] Specifically, refer to Figure 2 , Figure 2 This is an example diagram of a syntax tree. It should be noted that both the leaf syntax and the branch syntax in the syntax tree can be matched. The leaf syntax is equivalent to the syntax node in the above syntax tree. The leaf syntax is at the end of the syntax tree and is used to store the lexical structure. The lexical structure includes the character data of the above syntax node. The leaf syntax matches by comparing the lexical structure with the text. Figure 2 The grammar tree shown includes leaf grammar L1, leaf grammar L2, leaf grammar L3 and leaf grammar L4, and their lexical structures are indicated by dashed boxes respectively; the sequential grammar determines whether the sequential grammar matches by judging whether its child nodes can be successfully matched in sequence. Figure 2 The leaf grammar L1, leaf grammar L2 and selection matching grammar O1 are all child nodes of the sequential grammar S1, and their matching order is leaf grammar L1>leaf grammar L2>selection matching grammar O1; the selection matching grammar determines whether the selection matching grammar matches by judging whether there is a matching child node in its child node. Figure 2 The child nodes selected to match the grammar O1 include leaf grammars L3 and leaf grammars L4; the optional matching grammars ( Figure 2 (not shown) has only one child node, which may not match. In this case, the optional matching syntax is judged as a successful match, and the child node can also be matched. In this case, the matching result of the optional matching syntax follows the matching result of the child node; any matching syntax ( Figure 2(not shown) has only one child node, and the child node may not match. In this case, any matching syntax is judged as a successful match, and the child node can also be matched. If the child node matches successfully, any matching syntax matches successfully, and the child node can be matched again. If the child node matches unsuccessfully, any matching syntax matches unsuccessfully. In addition, in addition to the two states of successful match and failed match, the leaf syntax also has a matching state. When the lexical word and the text completely match, it is judged as a successful match. For example, if the lexical word is "VEL" and the text is also "VEL", and for the case where the lexical word is "number" and the text is "1", it is judged as a match. Only when the lexical word and the text do not match at all, it is judged as a failed match.
[0033] By constructing a preset syntax tree formed by multiple leaf syntaxes and multiple branch syntaxes, the preset syntax tree can include as many syntaxes as possible that may appear in the code text, thereby performing a more complete match, achieving a more comprehensive code prompt effect, and improving the user experience when editing code.
[0034] Furthermore, in this embodiment, when the change operation is to add a new code text, the step of updating the matching cache according to the code change data and the preset syntax tree and determining the code prompt information includes: When the change operation is to add a new code text, the matching start position is determined according to the blank characters in the code change data, and there are several character strings after the matching start position in the code change data.
[0035] Based on the order of the strings, a number of target syntax nodes matching each string are searched in the preset syntax tree.
[0036] Mount the target syntax nodes into the matching cache in the order of the corresponding strings.
[0037] The code prompt information is formed by splicing the character data of the target syntax node mounted in the matching cache.
[0038] Reference Figure 3 , Figure 3 This is a matching diagram when adding code text. For the sake of explanation, combined with Figure 2 The code change data is taken as "VEL=1" as an example.
[0039] It should be noted that for spaces in the code change data, they are first converted to blank characters before matching. The first character of the above "VEL=1" is a blank character. Figure 3SP is used to indicate a blank character. Using the blank character in the code change data as the starting position for matching can ensure that the match is still correct when the non-space content of the code text is deleted, and the blank characters in the non-starting position in the code change data are ignored. Taking "VEL=1" as an example, there are three character strings "VEL", "=" and "1" after the blank character. The character string in this embodiment includes at least one character. Based on the order of the character strings after the blank character, the target syntax nodes that match them are searched one by one in the preset syntax tree. The leaf syntax of the preset syntax tree includes the target syntax node. In addition, in the actual matching process, whether the character string formed by a combination of several characters matches the leaf syntax is still determined in the form of character-by-character judgment. There is no step of splitting the code change data into several character strings. The above "VEL=1" example is only for ease of explanation.
[0040] by Figure 2 Take the syntax tree as an example, first judge the child nodes of the sequential syntax S1, judge whether the leaf syntax L1 matches "VEL" successfully, judge whether the leaf syntax L2 matches "=" successfully, then judge and select the child nodes of the matching syntax O1, leaf syntax L3 and leaf syntax L4, leaf syntax L3 matches "1", judge leaf syntax L3 is in matching, leaf syntax L4 is in unsuccessful matching, for the target syntax node, only when it is judged to be a successful match or a matching leaf syntax is determined as the target syntax node, therefore, the target syntax node is determined to be leaf syntax L1, leaf syntax L2 and leaf syntax L3. Further, the target syntax nodes are mounted to the matching cache in the order of the corresponding strings, forming an association between the matching cache and the target syntax nodes, and when outputting the code prompt information, the associated target syntax node is determined by the matching cache, and the code prompt information is formed by splicing the character data of the target syntax node to output the code prompt information.
[0041] By comparing the string in the code change data with the syntax nodes in the preset syntax tree, the target syntax node is determined, the code prompt information is matched and determined, and the target syntax node is mounted by matching the cache. This is conducive to more quickly determining the target syntax node when further editing the code text, thereby further matching the syntax nodes, improving the matching efficiency of the code prompt, and improving the user experience when editing the code.
[0042] Further, in this embodiment, the matching cache includes a plurality of cache nodes, each cache node corresponds to each character in the code change data, and the step of mounting the target syntax node to the matching cache in the order of the corresponding character strings includes: Mount the start point of the target syntax node to the cache node corresponding to the first character of the string.
[0043] Mount the end point of the target syntax node to the cache node corresponding to the last character of the string.
[0044] A causal relationship is established between target grammar nodes of adjacent strings, and the causal relationship is mounted to a cache node of the first character of the latter string in the adjacent strings. The causal relationship represents the order between the target grammar nodes.
[0045] Specifically, refer to Figure 3 , corresponding to each character in the code change data, the matching cache has a corresponding cache node, including the blank character in the code change data. The start point and end point of the target syntax node are mounted to the cache node of the first character and the cache node of the last character of the corresponding string respectively. If the string has only one character, the start point and the end point are both mounted to the cache node of the character. The causal relationship represents the sequential relationship between different target syntax nodes. The causal relationship between two target syntax nodes corresponding to adjacent strings, mounted on the cache node of the first character of the latter string, indicates that the former target syntax node leads to the latter target syntax node, and there is a causal relationship between the two target syntax nodes. In addition to the start point, end point and causal relationship of the target syntax node being mounted to the cache node, the branch grammar also has a start point, end point and causal relationship. When the child node of the branch grammar begins to match, the start point of the branch grammar is mounted to the cache node of the first character of the string corresponding to the first matched child node, and the end point is mounted to the cache node of the last character in the string corresponding to the last matched child node. At the same time, causal relationships can be established not only between target syntax nodes (leaf grammars), but also between target syntax nodes and branch grammars, thereby including leaf grammars and branch grammars, and realizing the association of various structures of the syntax tree in the matching cache. In addition, for the first string after the blank character in the code change data, the start point related to the first string is mounted to the cache node corresponding to the blank character, rather than the cache node of the first character in the first string. In this way, when the non-space characters of the code text are deleted, the association between the syntax nodes can still be correctly traced back.
[0046] For example, Figure 2 and Figure 3 For example, for "VEL=1", there are cache nodes numbered from 0 to 5 corresponding to each character in it. Figure 3The matching process of the syntax tree is indicated by dotted arrows, the mounting status of each leaf syntax and branch syntax and the cache node is indicated by solid arrows, the node where the matching starts is indicated by a rounded rectangle, and the node where the matching ends is indicated by a circle. When matching starts, SP is used as the matching start position, and the starting points of the sequential grammar S1 and the leaf grammar L1 are mounted to the cache node 0. It is judged that the leaf grammar L1 matches the string "VEL", so the end point of the leaf grammar L1 is mounted to the cache node 3 of the last character "L" of "VEL", and then the leaf grammar L2 is judged to match the string "=", and the starting point and the end point of the leaf grammar L2 are both mounted to the cache node 4. At the same time, the causal relationship between the leaf grammar L2 and the leaf grammar L1 is established in the cache node 4. Further, the selection matching grammar O1 is judged, specifically, whether the leaf grammar L3 and the leaf grammar L4 match "1", and the starting points of the selection matching grammar O1, the leaf grammar L3 and the leaf grammar L4 are mounted to the cache node 5. At the same time, the causal relationship between the selection matching grammar O1 and the leaf grammar L2 is established in the cache node 5, and the leaf grammar L3 and "1" are judged to be matched, and the leaf grammar L4 and "1" are judged to fail to match, and the matching ends.
[0047] By matching each character with a cache node, determining the start point, end point and causal relationship related to the target syntax node and mounting them to a specific cache node, a precise correspondence between the code text and the syntax node is achieved, thereby achieving a more accurate code prompt matching effect, and facilitating faster determination of the relevant target syntax nodes and the relationship between the target syntax nodes when further editing the code text, thereby improving the matching efficiency of the code prompt and the user experience when editing the code.
[0048] Furthermore, in this embodiment, when the change operation is to delete the code text, the step of determining the code prompt information according to the code change data, the preset syntax tree and the matching cache further includes: When the change operation is to delete the code text, the code change data and the matching cache are compared to determine the target cache node of the deleted code text.
[0049] Deletes the start point, end point, and / or causality of a mount on the target cache node.
[0050] Re-determine the matching target syntax node based on the code change data and update the matching cache.
[0051] The code prompt information is formed by splicing the character data of the target syntax node mounted in the matching cache.
[0052] Reference Figure 4 , Figure 4 This is a matching diagram when deleting code text, taking the example of deleting the code text "VEL=1" to "VE" for explanation.
[0053] Specifically, by comparing the code change data and the matching cache, the cache node of the deleted code text and the cache node of the remaining code text are determined, wherein the cache node of the deleted code text is defined as the target cache node. Figure 4 For example, the target cache nodes include cache nodes 3, 4, and 5. Deleting the start point, end point, and / or causal relationship mounted on the target cache node is equivalent to canceling the association between the matching cache and the relevant target syntax node. When the step is actually executed, execution starts from the cache node at the end of the original string, which is equivalent to the reverse process when adding code text. If a causal relationship is mounted on the cache node, the target syntax node related to the previous cache node can be determined based on the causal relationship, thereby backtracking the matching of the target syntax node based on the causal relationship. Figure 4 Tracing back from cache node 5 to cache node 3, and because "VE" cannot completely match the leaf grammar L1, leaf grammar L1 is judged to be matching, cache node 3 cannot mount the end point of leaf grammar L1, the matching ends, and the re-determined target grammar node only includes leaf grammar L1.
[0054] It should be noted that the operation of deleting the code text does not necessarily start from the last character, it may also be to delete some characters from the middle position, for example, deleting "VEL=1" to "VE=1". In this case, the target cache node is still determined first, and the cache nodes corresponding to the changed characters are all determined as the target cache nodes. In this example, the characters from cache node 3 to cache node 5 also change, and the start point, end point and / or causal relationship mounted on the target cache node are also deleted.
[0055] Optionally, after deleting the start point, end point and / or causal relationship mounted on the target cache node, the target syntax node and the matching cache are re-determined and updated. For code text deleted starting from the end character of the string, the target syntax node and the matching cache are generally updated after deleting the start point, end point and / or causal relationship mounted on the target cache node. For code text deleted starting from the middle character of the string, it is necessary to start from the first cache node in the target cache node to execute the matching process as described above when adding new code text, and determine whether there are other updates to the target syntax node and the matching cache. For example, the user may correct the typo "VEEEL=1" to the correct "VEL=1", and finally splice the character data of the target syntax node mounted on the updated matching cache to form the code prompt information.
[0056] By utilizing the start point, end point and causal relationship of the syntax node mounted on the cache node, it is possible to backtrack the matching process of the target syntax node according to the mounted content when deleting the code text. Compared with the prior art, which requires a complete recursive traversal match before and after deletion, the matching operation is simplified, thereby improving the matching efficiency of the code prompt in scenarios where there are multiple input and deletion operations in the code text, and improving the user experience when editing the code.
[0057] It should be noted that for the leaf syntax judged to be matched, since the starting point of the leaf syntax has been mounted to the cache node, the leaf syntax also belongs to the target syntax node. When determining the code prompt information, its corresponding character data will also be used to splice to form the code prompt information. Based on this, the code prompt effect including the prediction function is realized. For example, when the input code text is "VE", the code prompt information outputs "VEL", etc.
[0058] Furthermore, in this embodiment, the step of searching for a plurality of target syntax nodes matching each character string in the preset syntax tree includes: When there is no target syntax node matching the string, a syntax error prompt is output.
[0059] It should be noted that the matching results between the leaf grammar and the string include successful matching, matching and failed matching. Only when it is judged as a matching failure, it is determined that the leaf grammar does not match the string. When there is no target grammar node that matches the string, that is, there is no leaf grammar that matches the string, it is judged as a syntax error and a syntax error prompt is output.
[0060] In other embodiments, the matching results of the branch grammar may also be monitored. When the branch grammar fails to match, it means that the structure of the currently input code text is different from that of the conventional grammar, and a grammar error prompt may also be output.
[0061] By outputting syntax error prompts, in addition to providing users with positive code prompts, it can also determine whether there are syntax errors in the code text currently edited by the user, so as to correct the syntax problems of the code text and improve the user experience when editing code.
[0062] Further, based on the above embodiment, a second embodiment of the code prompt method of the present application is proposed. Figure 5 In this embodiment, after the step of mounting the target syntax nodes to the matching cache in the order corresponding to the character strings, it also includes: The code change data is updated according to the character data of the target syntax node mounted in the matching cache.
[0063] The matching target syntax node is updated according to the updated code change data, and the matching cache is updated, and the step of updating the code change data according to the character data of the target syntax node mounted in the matching cache is returned to be executed until the target syntax node is unchanged before and after the update.
[0064] The step of forming the code prompt information by splicing the character data of the target syntax node mounted in the matching cache is executed.
[0065] For some grammars in the code, since their grammatical specifications are relatively fixed, their final text can be inferred based on a small number of characters. Based on this, for the target syntax nodes mounted in the matching cache, new code change data can be first spliced according to the character data of the target syntax nodes, and the updated code change data can be regarded as the newly added code text, and the matching process of the target syntax node when the new code text is added in the above embodiment is executed again, thereby updating the target syntax node and the matching cache, until the target syntax node is not updated or changed before and after the match, and the step of splicing the character data of the target syntax node to form code prompt information can be executed.
[0066] By updating the code change data according to the character data of the target syntax node, the matching process is re-executed using the updated code change data, and the output results are used as input for further prediction, providing a more complete code prompt effect and improving the user experience when editing code.
[0067] On the other hand, reference Figure 5 , Figure 5 This is a connection diagram of the code prompt device.
[0068] A code prompting device is provided, the code prompting device comprising: The input module is used to obtain the code text, compare the code text before and after the preset period according to the preset period, and determine the change operation of the code text and the code change data.
[0069] The syntax tree module is used to obtain the preset syntax tree of the language corresponding to the code text.
[0070] The matcher module is used to: when the change operation is to add new code text, update the matching cache according to the code change data and the preset syntax tree, and determine the code prompt information; when the change operation is to delete the code text, determine the code prompt information according to the code change data, the preset syntax tree and the matching cache.
[0071] Prompt output module, the prompt output module is used to output code prompt information.
[0072] Specifically, the input module is connected to the matcher module through the text cache. The input module is used to obtain the code text, compare the code text before and after the preset period according to the preset period, determine the change operation of the code text and the code change data, and store the code change data in the text cache. The syntax tree module is used to obtain the preset syntax tree of the language corresponding to the code text. The matcher module is also connected to the syntax tree module. The matcher module is used to obtain the preset syntax tree from the syntax tree module and the code change data from the text cache. Based on the change operation, the code prompt information is determined according to the code change data and the preset syntax tree, and the code prompt information is stored in the matching cache. The prompt output module is connected to the matcher module through the matching cache. The prompt output module is used to obtain the code prompt information from the matching cache and output it.
[0073] On the other hand, reference Figure 6 , Figure 6 It is a schematic diagram of the device structure of the code prompting device.
[0074] A code prompting device is provided, comprising: a processor and a memory, wherein the memory is used to store a computer-readable program. When the computer-readable program is executed by the processor, the processor implements the code prompting method as described in any one of the above technical solutions.
[0075] It will be appreciated by those skilled in the art that all or some of the steps and systems in the methods disclosed above may be implemented as software, firmware, hardware, and appropriate combinations thereof. Some or all physical components may be implemented as software executed by a processor, such as a central processing unit, a digital signal processor, or a microprocessor, or implemented as hardware, or implemented as an integrated circuit, such as an application-specific integrated circuit. Such software may be distributed on a computer-readable medium, which may include a computer storage medium (or non-transitory medium) and a communication medium (or temporary medium). As known to those skilled in the art, the term computer storage medium includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, program modules, or other data). Computer storage media include, but are not limited to, RAM, ROM, EEPROM, flash memory or other memory technology, CD-ROM, digital versatile disk (DVD) or other optical disk storage, magnetic cassettes, magnetic tapes, disk storage or other magnetic storage devices, or any other medium that can be used to store desired information and can be accessed by a computer. As is well known to those skilled in the art, communication media typically embodies computer readable instructions, data structures, program modules, or other data in a modulated data signal such as a carrier wave or other transport mechanism, and may include any information delivery media.
[0076] In addition, an embodiment of the present invention further provides a storage medium, on which a code prompt program is stored. When the code prompt program is executed by a processor, the relevant steps of any embodiment of the above code prompt method are implemented.
[0077] The terms "first", "second", "third", "fourth", etc. (if any) in the specification of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein, for example. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0078] It should be understood that in the present application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.
[0079] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0080] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0081] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0082] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art or all or part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, referred to as ROM), random access memory (Random Access Memory, referred to as RAM), disk or optical disk and other media that can store program codes.
[0083] Although the description of the present application has been quite detailed and specifically describes several embodiments, it is not intended to be limited to any of these details or embodiments or any particular embodiment, but should be regarded as providing a broad possible interpretation of these claims by reference to the attached claims, taking into account the prior art, so as to effectively cover the intended scope of the present application. In addition, the above description of the present application is based on the embodiments foreseeable by the inventor, and its purpose is to provide a useful description, and those non-substantial changes to the present application that have not yet been foreseen may still represent equivalent changes to the present application.
Claims
1. A code prompt method, characterized in that: The code prompt method comprises: Acquire the code text, compare the code text before and after the preset period according to the preset period, and determine the change operation of the code text and the code change data; Obtaining a preset syntax tree of the language corresponding to the code text; When the change operation is to add the code text, the matching cache is updated according to the code change data and the preset syntax tree, and the code prompt information is determined; When the change operation is to delete the code text, determining the code prompt information according to the code change data, the preset syntax tree and the matching cache; Output the code prompt information.
2. The code prompt method according to claim 1, characterized in that: When the change operation is to add the code text, the step of updating the matching cache according to the code change data and the preset syntax tree and determining the code prompt information includes: When the change operation is to add the code text, the matching start position is determined according to the blank characters in the code change data, and there are several character strings after the matching start position in the code change data; Based on the order of the character strings, searching the preset syntax tree for a number of target syntax nodes that match each of the character strings; Mounting the target syntax nodes to the matching cache in an order corresponding to the character strings; The code prompt information is formed by splicing the character data of the target syntax node mounted in the matching cache.
3. The code prompt method according to claim 2, characterized in that: The matching cache includes a plurality of cache nodes, each of which corresponds to each character in the code change data, and the step of mounting the target syntax nodes to the matching cache in the order corresponding to the character strings includes: Mounting the starting point of the target syntax node to the cache node corresponding to the first character of the string; Mounting the end point of the target syntax node to the cache node corresponding to the last character of the string; A causal relationship is established between the target grammar nodes of adjacent character strings, and the causal relationship is mounted to the cache node of the first character of the latter character string in the adjacent character strings, wherein the causal relationship represents the order between the target grammar nodes.
4. The code prompt method according to claim 3, characterized in that: When the change operation is to delete the code text, the step of determining the code prompt information according to the code change data, the preset syntax tree and the matching cache further includes: When the change operation is to delete the code text, comparing the code change data with the matching cache to determine a target cache node of the deleted code text; Deleting the start point, the end point and / or the causal relationship mounted on the target cache node; Re-determining the matching target syntax node according to the code change data, and updating the matching cache; The code prompt information is formed by splicing the character data of the target syntax node mounted in the matching cache.
5. The code prompt method according to claim 2, characterized in that: After the step of mounting the target syntax nodes to the matching cache in the order corresponding to the character strings, the method further includes: Update the code change data according to the character data of the target syntax node mounted in the matching cache; The matched target syntax node is updated according to the updated code change data, and the matching cache is updated, and the step of updating the code change data according to the character data of the target syntax node mounted in the matching cache is returned to be executed until there is no change before and after the target syntax node is updated; The step of forming the code prompt information by splicing the character data of the target syntax node mounted in the matching cache is executed.
6. The code prompt method according to claim 2, characterized in that: The step of searching the preset syntax tree for a plurality of target syntax nodes matching each of the character strings comprises: When there is no target syntax node matching the character string, a syntax error prompt is output.
7. The code prompt method according to any one of claims 2 to 6, characterized in that: The preset syntax tree is formed by multiple leaf grammars and multiple branch grammars, the leaf grammar includes the target syntax node, and the branch grammar includes a sequential grammar, a selective matching grammar, an optional matching grammar and / or an arbitrary matching grammar.
8. A code prompting device, characterized in that: The code prompting device comprises: An input module, the input module is used to obtain the code text, compare the code text before and after the preset period according to the preset period, and determine the change operation of the code text and the code change data; A syntax tree module, the syntax tree module is used to obtain a preset syntax tree of the language corresponding to the code text; A matcher module, the matcher module is used to: when the change operation is to add the code text, update the matching cache according to the code change data and the preset syntax tree, and determine the code prompt information; when the change operation is to delete the code text, determine the code prompt information according to the code change data, the preset syntax tree and the matching cache; A prompt output module, wherein the prompt output module is used to output the code prompt information.
9. A code prompting device, characterized in that: The code prompting device comprises: a memory, a processor, and a code prompting program stored in the memory and executable on the processor, wherein the code prompting program is configured to implement the steps of the code prompting method according to any one of claims 1 to 7.
10. A storage medium, characterized in that: The storage medium stores a code prompting program, and when the code prompting program is executed by the processor, the steps of the code prompting method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Complex data matching method and medium
CN111176656A
Association method of abstract syntax tree and source code coordinates, electronic equipment and medium
CN116954622A
Intelligent contract code completion method based on deep neural network and global cache
CN118092889A
SQL (Structured Query Language) code prompting method based on keyword backtracking and Token sorting
CN118113264A