Code processing method and device and storage medium
By using a syntax analyzer to parse JSP code and a tag rule mapping library to automatically convert it into Vue project files, the problem of low migration efficiency is solved, and efficient and accurate code migration is achieved.
Patent Information
- Application Number
- CN202511035560.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-25
- Publication Date
- 2025-11-11
AI Technical Summary
Current technologies for migrating JSP code to Vue projects are inefficient, error-prone, lack engineering support, and rely on manual secondary development.
The code file is parsed by a syntax analyzer to extract tag information, style information, and program logic information, generating the target project file. The target project file is then automatically converted using a syntax tree and tag rule mapping library.
It enables efficient code migration without manual intervention, improves migration efficiency, ensures the accuracy and integrity of target project files, and reduces manual verification work.
Smart Images

Figure CN120929086A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of artificial intelligence, and more specifically, to a code processing method, apparatus, and storage medium. Background Technology
[0002] With the continuous evolution of web technologies, the separation of front-end development frameworks and back-end services has become a significant trend in modern web applications. Vue.js (a progressive framework for building user interfaces), as a lightweight and high-performance front-end framework, has gained popularity among developers due to its concise API (Application Programming Interface), reactive data binding, and component-based development approach. Meanwhile, JSP (JavaServer Pages, a dynamic web page technology standard), once a mainstream server-side dynamic web page technology, is still widely used in legacy systems, but its mixed-language development approach and relatively low performance are no longer sufficient to meet the demands of modern web applications. Therefore, migrating JSP code to Vue projects (progressive frameworks for building user interfaces) has become a crucial transformation challenge for many enterprises.
[0003] Currently, methods for migrating JSP code to a Vue project primarily rely on manual refactoring and regular expression tools. Manual refactoring involves developers parsing the JSP file line by line, separating HTML (Hypertext Markup Language), CSS (Cascading Style Sheets), and Java (an object-oriented programming language) logic, and then reimplementing it using Vue's syntax and architecture. This method is not only time-consuming and labor-intensive but also prone to human error, especially when dealing with complex nested logic and EL expressions (a technique used to dynamically generate content in JSP pages). While regular expression replacement tools can accelerate the conversion process to some extent, they can only handle simple tag replacements and cannot handle nested logic, EL expressions, or backend code mapping. Therefore, existing methods are not only error-prone but also lack engineering support for JSP code processing, still relying on manual secondary development to migrate JSP code to a Vue project.
[0004] There is currently no effective solution to the problem of low efficiency in migrating JSP code to Vue projects in related technologies. Summary of the Invention
[0005] The main purpose of this application is to provide a code processing method, apparatus and storage medium to solve the problem of low efficiency in migrating JSP code to Vue projects in related technologies.
[0006] To achieve the above objectives, according to one aspect of this application, a code processing method is provided. The method includes: receiving a code file to be processed; parsing the code file using a syntax analyzer to extract tag information, style information, and program logic information from the code file; and generating a target project file corresponding to the code file based on the tag information, style information, and program logic information.
[0007] Furthermore, the code file is parsed using a parser to extract its tag information, style information, and program logic information. This includes: defining the syntax rules of the code file in the parser, and parsing the code file according to the defined syntax rules to obtain a first data stream and a second data stream; generating a syntax tree corresponding to the code file based on the first data stream and the second data stream; and determining the tag information, style information, and program logic information corresponding to the code file based on the second data stream and the syntax tree.
[0008] Furthermore, determining the tag information, style information, and program logic information corresponding to the code file based on the second data stream and the syntax tree includes: determining the tag information and style information based on the syntax tree; extracting variables, expressions, and logic scripts from the second data stream, and tracing the variables in the syntax tree to determine the scope mapping table of the variables; and determining the program logic information based on the scope mapping table, expressions, and logic scripts.
[0009] Furthermore, based on the tag information, style information, and program logic information, generating the target project file corresponding to the code file includes: generating the target code file corresponding to the code file based on the tag information, style information, and program logic information; extracting the global state data corresponding to the code file based on the tag information, style information, and program logic information; and generating the target project file based on the global state data and the target code file.
[0010] Furthermore, generating the target code file corresponding to the code file based on the tag information, style information, and program logic information includes: reading the tag rule mapping library and converting the tag information and style information into first target code based on the tag rule mapping library; converting the program logic information into second target code and determining the target request information based on the program logic information; and determining the target code file based on the first target code, the second target code, and the target request information.
[0011] Furthermore, based on tag information, style information, and program logic information, the global state data corresponding to the code file is extracted, including: determining single-file components based on tag information, style information, and program logic information; extracting session data and path data from the code file, and generating configuration data for the code file based on a preset template; and determining global state data based on single-file components, session data, path data, and configuration data.
[0012] Furthermore, based on global state data and target code files, the generation of target project files includes: generating a state management file corresponding to the target code file based on session data; generating a global routing file corresponding to the target code file based on path data; and generating target project files based on single-file components, state management files, global routing files, configuration data, and target code files.
[0013] To achieve the above objectives, according to another aspect of this application, a code processing apparatus is provided. The apparatus includes: a receiving unit for receiving a code file to be processed; a parsing unit for parsing the code file using a syntax analyzer to extract tag information, style information, and program logic information from the code file; and a generating unit for generating a target project file corresponding to the code file based on the tag information, style information, and program logic information.
[0014] Furthermore, the parsing unit includes: a first parsing module, used to define the syntax rules of the code file in the parser, and parse the code file according to the parser that defines the syntax rules to obtain a first data stream and a second data stream; a second parsing module, used to generate a syntax tree corresponding to the code file based on the first data stream and the second data stream; and a third parsing module, used to determine the tag information, style information and program logic information corresponding to the code file based on the second data stream and the syntax tree.
[0015] Furthermore, the third parsing module includes: a static information determination submodule, used to determine tag information and style information based on the syntax tree; a variable tracing submodule, used to extract variables, expressions, and logic scripts from the second data stream, and to determine the scope mapping table of variables based on the variables in the syntax tree; and a dynamic information determination submodule, used to determine program logic information based on the scope mapping table, expressions, and logic scripts.
[0016] Furthermore, the generation unit includes: a code generation module, used to generate the target code file corresponding to the code file based on tag information, style information and program logic information; a global state module, used to extract the global state data corresponding to the code file based on tag information, style information and program logic information; and a project generation module, used to generate the target project file based on the global state data and the target code file.
[0017] Furthermore, the code generation module includes: a first conversion submodule, used to read the tag rule mapping library and convert tag information and style information into first target code according to the tag rule mapping library; a second conversion submodule, used to convert program logic information into second target code and determine target request information according to the program logic information; and a code synthesis submodule, used to determine the target code file according to the first target code, the second target code and the target request information.
[0018] Furthermore, the global state module includes: a first extraction submodule, used to determine single-file components based on tag information, style information, and program logic information; a second extraction submodule, used to extract session data and path data from code files and generate configuration data for code files based on preset templates; and a state determination submodule, used to determine global state data based on single-file components, session data, path data, and configuration data.
[0019] Furthermore, the project generation module includes: a first generation submodule, used to generate a state management file corresponding to the target code file based on session data; a second generation submodule, used to generate a global routing file corresponding to the target code file based on path data; and a third generation submodule, used to generate a target project file based on single-file components, state management files, global routing files, configuration data, and target code files.
[0020] According to another aspect of this application, a computer-readable storage medium is provided, which includes a stored program, wherein, when the program is executed, it controls the device on which the computer-readable storage medium is located to execute any code processing method.
[0021] According to another aspect of this application, an electronic device is provided, comprising: one or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, and the one or more programs include methods for performing any kind of code processing.
[0022] According to another aspect of this application, a computer program product is provided, including computer instructions, which, when executed by a processor, implement the steps of the code processing method described above.
[0023] In this embodiment, the method involves receiving a code file to be processed; parsing the code file using a syntax analyzer to extract tag information, style information, and program logic information; and generating a target project file corresponding to the code file based on the tag information, style information, and program logic information. This solves the technical problem of low efficiency in migrating JSP code to a Vue project in the prior art.
[0024] This application achieves accurate extraction of complex nested information in code files through a parser, thereby obtaining accurate tag information, style information, and program logic information, laying the data foundation for the generation of the target project file. Furthermore, the target project file is generated based on the tag information, style information, and program logic information. Therefore, the code processing method of this application can be directly industrialized without secondary development by developers, improving the efficiency of migrating the code file to be processed to the target project file. Attached Figure Description
[0025] The accompanying drawings, which form part of this application, are used to provide a further understanding of this application. The illustrative embodiments and descriptions of this application are used to explain this application and do not constitute an undue limitation of this application. In the drawings:
[0026] Figure 1 A hardware structure block diagram of a computer terminal for implementing a code processing method is shown.
[0027] Figure 2 This is a flowchart of the code processing method provided according to the embodiments of this application;
[0028] Figure 3 This is a schematic diagram of a code processing apparatus provided according to an embodiment of this application;
[0029] Figure 4 This is a structural block diagram of an electronic device according to an embodiment of this application. Detailed Implementation
[0030] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of the present application.
[0031] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0032] First, some nouns or terms that appear in the description of the embodiments of this application shall be interpreted as follows:
[0033] It should be noted that the information collected in this application (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for display, data used for analysis, etc.) are information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, storage, use, processing, transmission, provision, disclosure, and application of this data all comply with relevant laws, regulations, and standards, necessary confidentiality measures have been taken, and they do not violate public order and good morals. Corresponding access points are provided for users to choose to authorize or refuse. For example, interfaces are set up between this system and relevant users or organizations, providing users with corresponding access points to choose to agree to or refuse automated decision-making results; if the user chooses to refuse, the process proceeds to the expert decision-making stage.
[0034] Example 1
[0035] According to an embodiment of this application, a method embodiment for code processing is also provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.
[0036] The method embodiment provided in Embodiment 1 of this application can be executed on a mobile terminal, computer terminal, or similar computing device. Figure 1 A hardware structure block diagram of a computer terminal (or mobile device) for implementing a code processing method is shown. Figure 1As shown, the computer terminal 10 (or mobile device) may include one or more processors 102 (shown as 102a, 102b, ..., 102n in the figure) 102 (processor 102 may include, but is not limited to, a microprocessor MCU or a programmable logic device FPGA, etc.), a memory 104 for storing data, and a transmission device 106 for communication functions. In addition, it may also include: a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of a BUS bus), a network interface, a power supply, and / or a camera. Those skilled in the art will understand that... Figure 1 The structure shown is for illustrative purposes only and does not limit the structure of the aforementioned electronic device. For example, computer terminal 10 may also include... Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown.
[0037] It should be noted that the aforementioned one or more processors 102 and / or other data processing circuits are generally referred to herein as "data processing circuits". These data processing circuits may be embodied, in whole or in part, in software, hardware, firmware, or any other combination thereof. Furthermore, the data processing circuits may be a single, independent processing module, or may be integrated, in whole or in part, into any other element within the computer terminal 10 (or mobile device). As involved in the embodiments of this application, the data processing circuits serve as a processor control mechanism (e.g., selection of a variable resistor termination path connected to an interface).
[0038] The memory 104 can be used to store software programs and modules of application software, such as the program instructions / data storage device corresponding to the code processing method in this embodiment. The processor 102 executes various functional applications and data processing by running the software programs and modules stored in the memory 104, thereby implementing the above-mentioned code processing method. The memory 104 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include memory remotely located relative to the processor 102, and these remote memories can be connected to the computer terminal 10 via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0039] The transmission device 106 is used to receive or send data via a network. Specific examples of the network described above may include a wireless network provided by the communication provider of the computer terminal 10. In one example, the transmission device 106 includes a Network Interface Controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, the transmission device 106 may be a Radio Frequency (RF) module, used for wireless communication with the Internet.
[0040] The display can be, for example, a touchscreen liquid crystal display (LCD) that allows the user to interact with the user interface of the computer terminal 10 (or mobile device).
[0041] Under the aforementioned operating environment, this application provides the following: Figure 2 The code processing method shown. Figure 2 This is a flowchart of the code processing method according to Embodiment 1 of this application.
[0042] Step S201: Receive the code file to be processed.
[0043] Optionally, the code file to be processed can be a JSP (Java Server Pages) code file, which generates an HTML page by embedding Java code. There are several ways to receive the code file, such as reading all the source code files of the JSP project directly from the local file system, downloading the code file to be processed from a remote server, or receiving the code file through a dedicated interface call.
[0044] Step S202: Use a syntax analyzer to parse the code file to extract the tag information, style information and program logic information of the code file.
[0045] Optionally, the parser used in this application embodiment can be an open-source parsing tool that generates and visualizes a syntax tree based on the input. It can compile the code file according to user-defined lexical rules for recognizing character streams and syntax analysis rules for interpreting data streams, converting it into an abstract syntax tree. The parser can be used to parse and identify various elements in the code file, constructing a syntax tree based on the parsing results to clearly mark the logical relationships in the code file. The syntax tree can then be traversed to extract tag information, style information, and program logic information. Tag information can be HTML tags or JSTL (JSP standard tag library) tags in the code file; style information can be CSS styles in the code file (e.g., embedded CSS and externally linked CSS files); and program logic information can be Java code or EL expressions in the code file.
[0046] Step S203: Based on the tag information, style information, and program logic information, generate the target project file corresponding to the code file.
[0047] Optionally, the target project file can be a Vue (i.e., Vue.js, an open-source progressive front-end framework) project file. It can generate corresponding Vue syntax based on tag information such as HTML and JSTL tags, and convert style information such as embedded CSS and externally linked CSS files into style settings for Vue components. It can also generate style scope properties for Vue components based on style information to ensure style isolation between components. It can encapsulate single-file Vue components based on tag information, style information, and program logic information, convert state information in the code file into Vue component state management integration, analyze the directory structure of the code file to generate Vue routing configurations, and thus obtain the target project file.
[0048] In summary, the parser accurately extracts complex nested information from code files. Furthermore, by acquiring tag information, style information, and program logic information, it lays the data foundation for generating the target project file. The target project file can be directly run industrially without secondary development by developers, thus improving the efficiency of migrating code files to be processed to the target project file.
[0049] To improve the accuracy of the target project file, optionally, a parser is used to parse the code file to extract the tag information, style information, and program logic information of the code file. This includes: defining the syntax rules of the code file in the parser, and parsing the code file according to the parser that defines the syntax rules to obtain a first data stream and a second data stream; generating a syntax tree corresponding to the code file based on the first data stream and the second data stream; and determining the tag information, style information, and program logic information corresponding to the code file based on the second data stream and the syntax tree.
[0050] Optionally, defining the syntax rules for the code file can involve storing these rules in a preset file format to describe the syntactic structure of the code file. For example, the preset file format could be a file with the ".g4" extension. A parser based on the defined syntax rules parses the code file to obtain a token stream. This token stream can be categorized into a first data stream and a second data stream. The first data stream can be static data (e.g., HTML nodes) within the token stream, while the second data stream can be dynamic data (e.g., loop logic and conditional logic). A syntax tree is constructed based on the first and second data streams. Node types can be labeled in the syntax tree; these can be static HTML nodes, dynamic logic nodes (e.g., loop logic and conditional logic), or Java code. By traversing the syntax tree, nodes corresponding to the first data stream are identified and extracted to obtain tag and style information. The syntax tree is then traversed based on the second data stream to identify and extract embedded code scripts, EL expressions (i.e., expression language), and other program data as program logic information. This program logic information can be reconstructed into reactive data bindings, computed attributes, and computation methods for the target project file.
[0051] For example, syntax rules may include rules for extracting JSP directives (<%@page%>, <%!%> declarations), rules for extracting JSP scripts (<%%>), rules for extracting EL expressions (${user.name}), and rules for extracting JSTL tags (...). <c:foreach>These grammar rules allow the extraction of a token stream, from which the first and second data streams are determined. A syntax tree for the code file is constructed based on the syntax parser, and node types are annotated in the syntax book; this could involve adding JSTL tags. <c:foreach>"This is parsed into a LoopStatement node in the syntax tree, containing the items and var attributes. Tag information can be extracted by traversing the syntax tree to identify and extract all HTML tags, JSP directives, and JSTL tags, and collecting relevant attribute information (e.g.,..." <c:foreach>The `var` and `items` properties facilitate the application of subsequent conversion rules. Style information can be extracted by traversing the syntax tree to identify and extract elements related to CSS styles.
[0052] In summary, by defining grammar rules and utilizing a parser and syntax tree, the tag information, style information, and program logic information corresponding to the code file were accurately extracted, providing accurate information for subsequent code conversion and thus improving the accuracy of the target project file.
[0053] To improve the accuracy of the target project file, optionally, determining the tag information, style information, and program logic information corresponding to the code file based on the second data stream and the syntax tree includes: determining the tag information and style information based on the syntax tree; extracting variables, expressions, and logic scripts from the second data stream, and tracing the variables in the syntax tree to determine the scope mapping table of the variables; and determining the program logic information based on the scope mapping table, expressions, and logic scripts.
[0054] Optionally, the syntax tree provides a clear structure to represent the syntax and logic hierarchy of a code file. By traversing the syntax tree, all HTML tags, JSTL tags, etc., can be identified, and their attributes, nesting structures, and position information can be recorded to determine tag information. The syntax tree also marks inline styles and external style references; style information can be determined by traversing the syntax tree. The second data stream contains all EL expressions and JSP scripts. By identifying and parsing these expressions and scripts, the page's expressions and logic scripts (e.g., loops, conditional statements, data binding logic, and backend API calls) can be determined. The second data stream and the syntax tree together provide a comprehensive view of variable definitions and references. For each variable in the second data stream, the variable's definition location, scope type, and all reference locations can be recorded during syntax tree traversal to generate a scope mapping table. The scope mapping table, expressions, and logic scripts can be used as program logic information.
[0055] For example, one can use inline styles from a grammar book (e.g., <div style="color:red;">) and references to external CSS (e.g., <link rel="stylesheet"href="styles.css"> This serves as style information. It identifies variables in the second data stream, uses a syntax tree to track the lifecycle of variables in JSP scripts and EL expressions, and generates a scope mapping table.
[0056] In summary, by tracing the syntax tree, the accuracy of retrieving nested tags from tag information is improved, enabling accurate extraction of complex expressions and thus enhancing the accuracy of the target project file.
[0057] To improve the efficiency of migrating JSP code to a Vue project, optionally, generating a target project file corresponding to the code file based on tag information, style information, and program logic information includes: generating a target code file corresponding to the code file based on tag information, style information, and program logic information; extracting global state data corresponding to the code file based on tag information, style information, and program logic information; and generating a target project file based on the global state data and the target code file.
[0058] Optionally, a preset rule engine can be used to convert tag information into Vue syntax, style information into style definitions in Vue components, and program logic information into Vue computed properties or methods to generate target code files. Global state data can be componentized outputs, API call templates, and project configuration files corresponding to the target project file. Extracting global state data can involve extracting session-scoped and request-scoped state data from the code file, reorganizing the extracted state data according to the management mode of the target project file, and storing the reorganized state data in the state management library of the target project file as global state data. Thus, the global state data and the target code file are used as the target project file.
[0059] In summary, by generating the target project file and global state data, the target project file was obtained, enabling the migration of code files to be processed to a target project file that can be run as a project. This effectively reduces secondary development by developers and improves the efficiency of migrating JSP code to a Vue project.
[0060] To improve the accuracy of the target code file, optionally, generating a target code file corresponding to the code file based on tag information, style information, and program logic information includes: reading a tag rule mapping library and converting tag information and style information into first target code based on the tag rule mapping library; converting program logic information into second target code and determining target request information based on the program logic information; and determining the target code file based on the first target code, the second target code, and the target request information.
[0061] Optionally, the tag rule mapping library can be a predefined set of transformation rules for migrating JSP tags to Vue syntax. The tag rule mapping library can have an extension interface to allow users to customize tag transformation rules within the library. Converting tag information and style information into the first target code based on the tag rule mapping library can involve using rules from the library to convert HTML and JSTL tags in JSP into corresponding instructions in the target project file, and to convert inline styles and external CSS files in JSP into style instructions for Vue components. Alternatively, a pre-defined logic converter can be used to convert JavaScript and EL expressions in the program logic information into Vue's second target code, and the JSP form submission path in the program logic information can be detected to generate corresponding target request information. The first target code (i.e., the converted HTML and CSS), the second target code (i.e., the refactored logic code), and the target request information are combined to form the target code file under the Vue framework.
[0062] For example, a tag rule mapping library can include the following rule: to assign the JSP tag's " <c:foreach>"Converted to the v-for directive of Vue syntax, it will convert the JSP tag's..." <fmt:formatdate>"Filters are used to convert code to Vue syntax. Preset logic converters can define a first logic and a second logic. The first logic uses a preset rule engine to match simple logic, such as converting the program logic "for(User u:userList)" to "userList.forEach(u=>{...})" in the Vue framework. The second logic marks code segments that cannot be automatically converted by the first logic with comments to prompt developers to manually migrate them. If the code file contains a JSP form submission path "action=saveUser.jsp", the preset rule engine generates a request template corresponding to that form submission path. Simultaneously, it detects each API call data in the program logic information (e.g., POST requests, URL (Uniform Resource Locator) paths, and required parameters) and generates a complete request configuration based on the API call data. The request template and request configuration are used as target request information, and an API documentation skeleton in Swagger (a real-time dynamic API documentation generation tool) format is automatically generated for backend developers to reference when implementing the interface."
[0063] In summary, by obtaining the first code through the tag rule mapping library and the second target code and target request information based on the program logic information, the limitations of manual conversion in existing technologies are overcome, human intervention is significantly reduced, efficient and accurate code migration is achieved, and the accuracy of the target code file is improved.
[0064] To improve the accuracy of the target project files, optionally, based on tag information, style information, and program logic information, the global state data corresponding to the code file is extracted, including: determining single-file components based on tag information, style information, and program logic information; extracting session data and path data from the code file, and generating configuration data for the code file based on a preset template; and determining global state data based on single-file components, session data, path data, and configuration data.
[0065] Optionally, different templates, styles, and script logic in the page can be extracted using tag information, style information, and program logic information. These templates, styles, and script logic can then be merged by functional area of the page to obtain single-file components corresponding to those functional areas. In the code file to be processed, session data is typically stored and accessed through session control data. By searching the code file, session control data stored within the session scope can be obtained as session data. Path data containing dynamic parameters can be obtained by parsing the directory hierarchy in the code file or parsing parameter calls and form submission actions in JSP. This path data can be either the storage path for calling already stored data or the URL path for accessing other pages.
[0066] In summary, by extracting the single-file components, session data, path data, and configuration data corresponding to the code files, the accurate calling of global state data by the target project files can be ensured at the entire project level. This can significantly reduce potential errors during code migration and improve the accuracy of the target project files.
[0067] To improve the efficiency of migrating JSP code to a Vue project, optionally, the target project file can be generated based on global state data and target code files, including: generating a state management file corresponding to the target code file based on session data; generating a global route file corresponding to the target code file based on path data; and generating a target project file based on single-file components, state management files, global route files, configuration data, and target code files.
[0068] For example, you can design a Vuex store (a state container containing core concepts) structure in a Vue project based on the extracted session data. Define a state field to store session data, and use mutations and actions functions to control the access to session data. Convert the Vuex store design into an actual code file, name the code file store.js, and place it in a folder named store in the root directory of the target project. Ensure that these code files contain all state fields, mutations functions, and actions functions to support data access and state management of the target code file. This will convert the session data of the code file into the state management file of the target code file (i.e., the Vuex module of Vue). The global route file includes all routes defined in the target code file, as well as advanced features such as route guards and dynamic loading, to meet the navigation needs of the target project file. Nested route configurations can be created within the global route file based on the directory hierarchy of the code file (e.g., generating the " / user" route based on the path data " / webpage / user.jsp"). Alternatively, the global route file can be generated through parameter mapping. For example, for the path data "user.jsp?id=1", the dynamic parameter id in the path data can be detected, a route configuration can be defined in the target project, and the dynamic parameter in the path data can be replaced with a preset string in the route configuration to obtain the parameter mapping result " / user / :id+this.$route.params.id". By integrating single-file components, state management files, global route files, and target code files, and generating Vue framework rule configuration files (e.g., ESLint rules), proxy configuration files, and global configuration files (e.g., continuous integration / continuous deployment configuration files) based on the configuration data, the target project file is obtained.
[0069] Alternatively, the target browser version corresponding to the target project file can be obtained by detecting the user agent string. Based on the target browser version, the corresponding front-end standard library can be selected, and the front-end standard library can be added to the target project file using a plugin to ensure that the generated target project file can run correctly in the browser and avoid script execution errors caused by compatibility issues.
[0070] In summary, by using the above methods, we can not only ensure that the migration of the code files to be processed to the target project files is syntactically correct, but also ensure the functionality and overall architectural integrity of the target project files. This avoids performance bottlenecks, state management chaos, or routing navigation problems caused by improper conversion, reduces manual verification after conversion, and improves the efficiency of migrating JSP code to Vue projects.
[0071] It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases the steps shown or described may be executed in a different order than that shown here.
[0072] Example 2
[0073] This application also provides a code processing apparatus. It should be noted that the code processing apparatus of this application can be used to execute the code processing method provided in this application. The code processing apparatus provided in this application will be described below.
[0074] According to embodiments of this application, an apparatus for implementing the above-described code processing method is also provided, such as... Figure 3 As shown, the device includes:
[0075] The receiving unit 301 is used to receive the code file to be processed.
[0076] Parsing unit 302 is used to parse code files using a syntax analyzer to extract tag information, style information and program logic information from the code files.
[0077] The generation unit 303 is used to generate a target project file corresponding to the code file based on the tag information, style information and program logic information.
[0078] The code processing apparatus provided in this application embodiment receives a code file to be processed through a receiving unit 301, parses the code file using a syntax analyzer through a parsing unit 302 to extract tag information, style information, and program logic information from the code file, and generates a target project file corresponding to the code file through a generation unit 303 based on the tag information, style information, and program logic information. This solves the problem of low efficiency in migrating JSP code to Vue projects in related technologies, thereby improving the efficiency of migrating JSP code to Vue projects.
[0079] Optionally, in the code processing apparatus provided in this application embodiment, the parsing unit 302 includes: a first parsing module, used to define the syntax rules of the code file in the syntax analyzer, and parse the code file according to the syntax analyzer that defines the syntax rules to obtain a first data stream and a second data stream; a second parsing module, used to generate a syntax tree corresponding to the code file according to the first data stream and the second data stream; and a third parsing module, used to determine the tag information, style information and program logic information corresponding to the code file according to the second data stream and the syntax tree.
[0080] Optionally, in the code processing apparatus provided in this application embodiment, the third parsing module includes: a static information determination submodule, used to determine tag information and style information based on the syntax tree; a variable tracing submodule, used to extract variables, expressions, and logic scripts from the second data stream, and to determine the scope mapping table of variables based on the variables tracing in the syntax tree; and a dynamic information determination submodule, used to determine program logic information based on the scope mapping table, expressions, and logic scripts.
[0081] Optionally, in the code processing apparatus provided in this application embodiment, the generation unit 303 includes: a code generation module, used to generate a target code file corresponding to the code file based on tag information, style information and program logic information; a global state module, used to extract global state data corresponding to the code file based on tag information, style information and program logic information; and a project generation module, used to generate a target project file based on the global state data and the target code file.
[0082] Optionally, in the code processing apparatus provided in this application embodiment, the code generation module includes: a first conversion submodule, used to read a tag rule mapping library and convert tag information and style information into first target code according to the tag rule mapping library; a second conversion submodule, used to convert program logic information into second target code and determine target request information according to the program logic information; and a code synthesis submodule, used to determine a target code file according to the first target code, the second target code and the target request information.
[0083] Optionally, in the code processing apparatus provided in this application embodiment, the global state module includes: a first extraction submodule, used to determine single-file components based on tag information, style information and program logic information; a second extraction submodule, used to extract session data and path data from the code file and generate configuration data of the code file based on a preset template; and a state determination submodule, used to determine global state data based on single-file components, session data, path data and configuration data.
[0084] Optionally, in the code processing apparatus provided in this application embodiment, the project generation module includes: a first generation submodule, used to generate a state management file corresponding to the target code file based on session data; a second generation submodule, used to generate a global routing file corresponding to the target code file based on path data; and a third generation submodule, used to generate a target project file based on a single-file component, a state management file, a global routing file, configuration data, and the target code file.
[0085] It should be noted that the receiving unit 301, parsing unit 302, and generating unit 303 mentioned above correspond to steps S201 to S203 in Embodiment 1. Each unit and the corresponding step implement the same instance and application scenario, but are not limited to the content disclosed in Embodiment 1. It should be noted that the above modules or units can be hardware or software components stored in memory (e.g., memory 104) and processed by one or more processors (e.g., processors 102a, 102b, ..., 102n). The above modules can also be part of a device and run in the computer terminal 10 provided in Embodiment 1.
[0086] Example 3
[0087] Embodiments of this application may provide an electronic device. Figure 4 This is a structural block diagram of an electronic device according to an embodiment of this application. Figure 4 As shown, the electronic device may include: one or more ( Figure 4 (Only one is shown) processor 1002, memory 1004, memory controller, and peripheral interface, wherein the peripheral interface is connected to the radio frequency module, audio module and display.
[0088] The memory can be used to store software programs and modules, such as the program instructions / modules corresponding to the methods and apparatus in the embodiments of this application. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory, thereby implementing the above-described methods. The memory may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory may further include memory remotely located relative to the processor, and these remote memories can be connected to the terminal via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0089] The processor can access information and applications stored in memory via a transmission device to perform the following steps: receiving a code file to be processed; parsing the code file using a syntax analyzer to extract tag information, style information, and program logic information from the code file; and generating a target project file corresponding to the code file based on the tag information, style information, and program logic information.
[0090] The processor can also call the information and application stored in the memory through the transmission device to perform the following steps: define the syntax rules of the code file in the parser, and parse the code file according to the parser that defines the syntax rules to obtain a first data stream and a second data stream; generate a syntax tree corresponding to the code file according to the first data stream and the second data stream; and determine the tag information, style information and program logic information corresponding to the code file according to the second data stream and the syntax tree.
[0091] The processor can also invoke information and applications stored in memory via a transmission device to perform the following steps: determine tag information and style information based on the syntax tree; extract variables, expressions, and logic scripts from the second data stream, and trace back the variables in the syntax tree to determine the scope mapping table of the variables; determine program logic information based on the scope mapping table, expressions, and logic scripts.
[0092] The processor can also access information and applications stored in the memory via a transmission device to perform the following steps: generating a target code file corresponding to the code file based on tag information, style information, and program logic information; extracting global state data corresponding to the code file based on tag information, style information, and program logic information; and generating a target project file based on the global state data and the target code file.
[0093] The processor can also call the information and application stored in the memory through the transmission device to perform the following steps: read the tag rule mapping library, and convert the tag information and style information into first target code according to the tag rule mapping library; convert the program logic information into second target code, and determine the target request information according to the program logic information; determine the target code file according to the first target code, the second target code and the target request information.
[0094] The processor can also call the information and application stored in the memory through the transmission device to perform the following steps: determine the single-file component based on the tag information, style information and program logic information; extract the session data and path data in the code file and generate the configuration data of the code file according to the preset template; determine the global state data based on the single-file component, session data, path data and configuration data.
[0095] The processor can also invoke information and applications stored in the memory via the transmission device to perform the following steps: generating a state management file corresponding to the target code file based on session data; generating a global routing file corresponding to the target code file based on path data; and generating a target project file based on single-file components, the state management file, the global routing file, configuration data, and the target code file.
[0096] This application provides a code processing solution. It receives a code file to be processed; uses a syntax analyzer to parse the code file to extract tag information, style information, and program logic information; and generates a target project file corresponding to the code file based on the tag information, style information, and program logic information. This solves the technical problem of low efficiency in migrating JSP code to a Vue project in the prior art.
[0097] Those skilled in the art will understand that Figure 4 The structure shown is for illustrative purposes only. Electronic devices can also be smartphones, tablets, handheld computers, mobile internet devices (MIDs), PADs, and other terminal devices. Figure 4 This does not limit the structure of the aforementioned electronic device. For example, electronic devices may also include components that are more... Figure 4 The more or fewer components shown (such as network interfaces, display devices, etc.), or having the same Figure 4 The different configurations shown.
[0098] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be implemented by a program instructing the hardware related to the terminal device. The program can be stored in a computer-readable storage medium, which may include: flash drive, read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.
[0099] Example 4
[0100] Embodiments of this application also provide a storage medium. Optionally, in this embodiment, the storage medium can be used to store the program code executed by the code processing method provided in Embodiment 1.
[0101] Optionally, in this embodiment, the storage medium may be located in any computer terminal in a group of computer terminals in a computer network, or in any mobile terminal in a group of mobile terminals.
[0102] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: receiving a code file to be processed; parsing the code file using a syntax analyzer to extract tag information, style information, and program logic information from the code file; and generating a target project file corresponding to the code file based on the tag information, style information, and program logic information.
[0103] Optionally, in this embodiment, the computer-readable storage medium is further configured to store program code for performing the following steps: defining syntax rules for the code file in a syntax analyzer, and parsing the code file according to the syntax analyzer that defines the syntax rules to obtain a first data stream and a second data stream; generating a syntax tree corresponding to the code file based on the first data stream and the second data stream; and determining tag information, style information, and program logic information corresponding to the code file based on the second data stream and the syntax tree.
[0104] Optionally, in this embodiment, the computer-readable storage medium is further configured to store program code for performing the following steps: determining tag information and style information based on the syntax tree; extracting variables, expressions, and logic scripts from the second data stream, and tracing back the variables in the syntax tree to determine the scope mapping table of the variables; and determining program logic information based on the scope mapping table, expressions, and logic scripts.
[0105] Optionally, in this embodiment, the computer-readable storage medium is further configured to store program code for performing the following steps: generating a target code file corresponding to the code file based on tag information, style information, and program logic information; extracting global state data corresponding to the code file based on tag information, style information, and program logic information; and generating a target project file based on the global state data and the target code file.
[0106] Optionally, in this embodiment, the computer-readable storage medium is further configured to store program code for performing the following steps: reading a tag rule mapping library and converting tag information and style information into first target code according to the tag rule mapping library; converting program logic information into second target code and determining target request information according to the program logic information; and determining a target code file according to the first target code, the second target code, and the target request information.
[0107] Optionally, in this embodiment, the computer-readable storage medium is further configured to store program code for performing the following steps: determining a single-file component based on tag information, style information, and program logic information; extracting session data and path data from the code file, and generating configuration data for the code file based on a preset template; and determining global state data based on the single-file component, session data, path data, and configuration data.
[0108] Optionally, in this embodiment, the computer-readable storage medium is further configured to store program code for performing the following steps: generating a state management file corresponding to the target code file based on session data; generating a global routing file corresponding to the target code file based on path data; and generating a target project file based on the single-file component, the state management file, the global routing file, the configuration data, and the target code file.
[0109] This application also provides a computer program product that, when executed on a data processing device, is adapted to perform code processing method steps.
[0110] The sequence numbers of the embodiments in this application are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0111] In the above embodiments of this application, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0112] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. The device embodiments described above are merely illustrative; for example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the displayed or discussed mutual coupling, direct coupling, or communication connection may be through some interfaces; the indirect coupling or communication connection between units or modules may be electrical or other forms.
[0113] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0114] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0115] If the integrated unit is implemented as 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 this application, in essence, 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. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard drive, magnetic disk, or optical disk.
[0116] The above description is only a preferred embodiment of this application. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of this application, and these improvements and modifications should also be considered within the scope of protection of this application.< / fmt:formatdate> < / c:foreach> < / c:foreach> < / c:foreach> < / c:foreach>
Claims
1. A code processing method, characterized in that, include: Receive the code file to be processed; The code file is parsed using a syntax analyzer to extract its tag information, style information, and program logic information. Based on the tag information, the style information, and the program logic information, a target project file corresponding to the code file is generated.
2. The method according to claim 1, characterized in that, The code file is parsed using a syntax analyzer to extract its tag information, style information, and program logic information, including: The syntax rules of the code file are defined in the parser, and the code file is parsed according to the syntax rules to obtain a first data stream and a second data stream. Based on the first data stream and the second data stream, generate the syntax tree corresponding to the code file; The tag information, style information, and program logic information corresponding to the code file are determined based on the second data stream and the syntax tree.
3. The method according to claim 2, characterized in that, Determining the tag information, style information, and program logic information corresponding to the code file based on the second data stream and the syntax tree includes: Based on the syntax tree, the tag information and the style information are determined; Extract the variables, expressions, and logic scripts from the second data stream, and trace the variables in the syntax tree to determine the scope mapping table of the variables; The program logic information is determined based on the scope mapping table, the expression, and the logic script.
4. The method according to claim 1, characterized in that, Based on the tag information, the style information, and the program logic information, generating the target project file corresponding to the code file includes: Based on the tag information, the style information, and the program logic information, generate the target code file corresponding to the code file; Based on the tag information, the style information, and the program logic information, extract the global state data corresponding to the code file; Based on the global state data and the target code file, the target project file is generated.
5. The method according to claim 4, characterized in that, Based on the tag information, the style information, and the program logic information, generating the target code file corresponding to the code file includes: Read the tag rule mapping library, and convert the tag information and style information into first target code according to the tag rule mapping library; The program logic information is converted into second target code, and the target request information is determined based on the program logic information; The target code file is determined based on the first target code, the second target code, and the target request information.
6. The method according to claim 4, characterized in that, Based on the tag information, the style information, and the program logic information, the global state data corresponding to the code file is extracted, including: Based on the tag information, the style information, and the program logic information, determine the single-file component; Extract session data and path data from the code file, and generate configuration data for the code file based on a preset template; Global state data is determined based on the single-file component, the session data, the path data, and the configuration data.
7. The method according to claim 6, characterized in that, Based on the global state data and the target code file, generating the target project file includes: Generate a state management file corresponding to the target code file based on the session data; Generate a global route file corresponding to the target code file based on the path data; The target project file is generated based on the single-file component, the state management file, the global routing file, the configuration data, and the target code file.
8. A code processing device, characterized in that, include: The receiving unit is used to receive code files to be processed. The parsing unit is used to parse the code file using a syntax analyzer to extract the tag information, style information and program logic information of the code file; The generation unit is used to generate a target project file corresponding to the code file based on the tag information, the style information, and the program logic information.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a stored executable program, wherein, when the executable program is executed, it controls the device on which the computer-readable storage medium is located to perform the code processing method according to any one of claims 1 to 7.
10. An electronic device, characterized in that, include: Memory, which stores executable programs; A processor for running the program, wherein the program, when running, executes the code processing method according to any one of claims 1 to 7.
11. A computer program product comprising computer instructions, characterized in that, When the computer instructions are executed by the processor, they implement the steps of the code processing method according to any one of claims 1 to 7.
Citation Information
Cited By
JSP and Vue-based front-end integration system and method
CN121349457A