CN-122018943-A - SPEL-based user-defined identifier dynamic identification and completion method and system
Abstract
The invention discloses a SPEL language-based user-defined identifier dynamic identification and code automatic completion method and system. The method includes the steps of monitoring editing operation of a user on SPEL codes in real time, obtaining and comparing code fragments before and after editing when a cursor leaves a current line, analyzing the changed codes based on a preset SPEL grammar regular expression to identify newly added user-defined identifiers and dynamically adding the newly added user-defined identifiers into a completion library, analyzing the codes before the change to identify the modified or deleted identifiers and removing invalid items from the completion library, and finally providing dynamic and context-related automatic completion prompts based on the updated completion library when the user inputs later. The system comprises a code change monitoring module (1), a difference comparison module (2), a grammar analysis module (3), a code complement library updating module (4) and a code complement prompting module (5). The invention relates to the technical field of industrial robot programming.
Inventors
- Feng Yangguang
- CHEN XIHONG
- HUANG XUEYONG
Assignees
- 珠海市海峰机器人系统有限公司
Dates
- Publication Date
- 20260512
- Application Date
- 20260403
Claims (10)
- 1. A SPEL-based user-defined identifier dynamic identification and completion method is characterized by comprising the following steps: s1, monitoring input or modification operation of a user on SPEL language codes in an integrated development environment in real time; S2, when a user finishes editing a current code line and leaves a cursor from the line, acquiring code fragments before and after the code line is edited, defining the code fragment before the editing as a first code fragment, and defining the code fragment after the editing as a second code fragment; s3, comparing the first code segment with the second code segment to determine changed code content; S4, judging and analyzing the grammar type of the second code segment according to a preset SPEL language grammar regular expression, and identifying a user-defined identifier statement contained in the grammar type; s5, when the user-defined identifier statement is identified, extracting a corresponding identifier name from the second code segment and dynamically adding the identifier name to a code complement candidate library; S6, when the fact that the user-defined identifier statement is modified or deleted is identified, removing the corresponding failure identifier name from the code complement candidate library; S7, the content in the code complement candidate library is called in real time when the user subsequently inputs the SPEL language code, so that the dynamic and contextually-related automatic complement prompt of the user-defined identifier is realized.
- 2. The method of claim 1, further comprising the step of, in step S1: S11, pre-caching the current code content of a certain line of codes as the first code fragment before a user starts editing the code of the line; and S12, when the user leaves the text cursor from the current editing line, caching the final code content of the line as the second code segment.
- 3. The method according to claim 1, wherein step S3 is specifically: S31, comparing the first code segment with the second code segment character by character, judging whether the first code segment and the second code segment have differences, and triggering the step S4 when the differences exist.
- 4. The method according to claim 1, wherein step S4 is specifically: S41, matching the second code segment by using a SPEL user-defined variable declaration grammar regular expression and a SPEL user-defined function declaration grammar regular expression; S42, judging that the SPEL user self-defined variable declaration grammar regular expression is a variable declaration when the matching is successful; S43, judging that the SPEL user self-defined function statement grammar regular expression is a function statement when the matching of the SPEL user self-defined function statement grammar regular expression is successful.
- 5. The method of claim 4, wherein when a variable declaration is determined, extracting a corresponding identifier name from the second code segment and dynamically adding to a code complement candidate library, specifically: S421, a SPEL user-defined variable declaration grammar regular expression matching iterator is used for obtaining the matched identifiers one by one; s422, judging whether the first matching item of the iterator belongs to a preset SPEL language data type keyword set; s423, when the data type keyword set belongs to, the legal identifiers which are matched with the iterator subsequently are sequentially added to the code complement candidate library as user-defined variable names.
- 6. The method according to claim 4, wherein when it is determined that a function is declared, extracting the corresponding identifier name from the second code segment and dynamically adding to a code complement candidate library, in particular: S431, extracting function names through SPEL user-defined function statement grammar regular expressions, and adding the function names to a code complement candidate library; S432, obtaining the contents of a shape parameter list through a SPEL user-defined function statement grammar regular expression; s433, the content of the shape parameter list is split one by utilizing an independent shape parameter matching regular expression, the identifier name of each shape parameter is extracted in sequence, and the shape parameter names are added to the code complement candidate library.
- 7. The method according to claim 1, wherein step S6 is specifically: S61, matching the first code segment by using a SPEL user-defined variable declaration grammar regular expression aiming at the modified or deleted variable declaration line, extracting an original variable name, and removing the corresponding variable name from a code complement candidate library; S62, matching the first code segment by using a SPEL user-defined function statement grammar regular expression aiming at the modified or deleted function statement line, extracting original function names and all shape parameter names, and removing the corresponding function names and all related shape parameter names from a code complement candidate library.
- 8. The method of claim 1, wherein the code complement candidate library comprises at least three mutually independent subsets of a set of user-defined variables, a set of user-defined functions, and a set of user-defined function-shape parameters.
- 9. The method according to claim 1, wherein step S7 is specifically: S71, searching all user-defined variable names, function names and valid shape parameter names in the current function scope, which are matched with the current input prefix, from a code complement candidate library when the input characters reach a preset threshold value or a complement shortcut key is triggered in the process of inputting codes by a user; S72, sorting the search results according to a preset priority rule and then presenting the search results to a user.
- 10. A system for implementing the method of any one of claims 1-9, the system comprising: The code change monitoring module (1) is used for monitoring the input or modification operation of a user on a SPEL language code in an integrated development environment in real time, and acquiring a first code segment before the code line is edited and a second code segment after the code line is edited when the user finishes the current code line editing and a cursor leaves the line; A difference comparison module (2) for comparing the first code segment with the second code segment to determine whether there is a code content difference; The grammar analysis module (3) is used for respectively judging and analyzing grammar types of the first code segment and the second code segment according to a preset SPEL language grammar regular expression when the difference exists; The code complement library updating module (4) is used for executing the following operations according to the analysis result of the grammar analysis module: When the second code segment is identified as containing a user-defined identifier declaration, extracting a corresponding identifier name from the second code segment and dynamically adding the identifier name to a code complement candidate library; removing the corresponding invalid identifier name from the code complement candidate library when the first code segment is identified as containing a user-defined identifier declaration that has been modified or deleted; And the code complement prompting module (5) is used for calling the contents in the code complement candidate library in real time when the user subsequently inputs the SPEL language code so as to provide the user with a dynamic and context-dependent automatic complement prompt for the user-defined identifier.
Description
SPEL-based user-defined identifier dynamic identification and completion method and system Technical Field The invention relates to an industrial robot programming technology and an internet information service technology, in particular to a method and a system for dynamically identifying and complementing user-defined identifiers based on SPEL (Structured Process Expression Language ). The invention is suitable for Cloud computing-based integrated development environment (Cloud IDE) and Internet code search service, and aims to improve the programming efficiency of a robot engineer through networked and intelligent data processing. Background In industrial robot application development, programming is the core bridge connecting engineers' intentions to machine actions. The industrial robot programming schemes in the current market mainly comprise two major categories, one category adopts mature general programming languages, such as Lua languages adopted by Taida robots and popular robots, and the other category adopts special programming languages independently developed by robot manufacturers, such as SPEL+ languages of the Epson robots, unnamed self-research languages of the sea-health robots and RAPID languages of the ABB robots. The adoption of the universal programming language has the advantages that advanced Integrated Development Environments (IDEs) in the industry such as Visual Studio Code, intelliJ IDEA and the like can be seamlessly connected, powerful intelligent perception (INTELLISENSE) functions are built in the IDEs, accurate automatic code complementation can be provided for user-defined variables, functions and shape parameters of the functions, and development efficiency and code quality are greatly improved. However, for vendors using self-developed proprietary languages, their intelligent capabilities with their mating IDEs tend to be quite weak due to the lack of sophisticated Language Server Protocol (LSP) support and the large community of developers. According to incomplete market research, in mainstream industrial robot products circulated in the market, only tandem robots realize a relatively perfect user-defined identifier complement function in self-research language IDE. The official IDE of the epson robot, which is a main user of the SPEL+ language, can only complement the function names customized by users, and can not provide any prompt for the user-defined variable names which are more basic and have extremely high use frequency and the shape parameter names in the functions. The situation is more severe for the sea robot and ABB robot, and its IDE cannot even complement the user-defined function name. This lack of technology presents a significant hurdle to first-line engineers. In developing large, complex automation projects, engineers need to memorize a large number of self or team member defined variable names, function names, and shape parameter names. Once forgotten, the search must be repeated across multiple code files, which not only severely slows development progress, but also compromises code readability and maintainability. Therefore, a technical solution capable of deeply understanding spel+ language grammar and dynamically identifying and managing user-defined identifiers in real time is needed to fill the gap in the market. Disclosure of Invention The invention aims to overcome the defects in the prior art and provide a SPEL-based user-defined identifier dynamic identification and complementation method and system. The method has the core targets that in the robot IDE, the comprehensive, accurate and real-time code automatic complement function of three key identifiers of a user-defined variable, a user-defined function and a function shape parameter in the SPEL+ programming language environment is realized, so that the technical effects of improving the development efficiency of a robot engineer and enhancing the interactive experience of the SPEL+ language are achieved. The technical scheme adopted by the invention is that the method for dynamically identifying the user-defined identifier and automatically complementing the code based on the SPEL language comprises the following steps: s1, monitoring input or modification operation of a user on SPEL language codes in an integrated development environment in real time; S2, when a user finishes editing a current code line and leaves a cursor from the line, acquiring code fragments before and after the code line is edited, defining the code fragment before the editing as a first code fragment, and defining the code fragment after the editing as a second code fragment; s3, comparing the first code segment with the second code segment to determine changed code content; S4, judging and analyzing the grammar type of the second code segment according to a preset SPEL language grammar regular expression, and identifying a user-defined identifier statement contained in the grammar type; s5, when the user-defined