CN113971028B - Data processing method, apparatus, device, storage medium and computer program product - Google Patents

Data processing method, apparatus, device, storage medium and computer program product Download PDF

Info

Publication number
CN113971028B
CN113971028B CN202111251532.9A CN202111251532A CN113971028B CN 113971028 B CN113971028 B CN 113971028B CN 202111251532 A CN202111251532 A CN 202111251532A CN 113971028 B CN113971028 B CN 113971028B
Authority
CN
China
Prior art keywords
target
node
code
character string
detected
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202111251532.9A
Other languages
Chinese (zh)
Other versions
CN113971028A (en
Inventor
彭振清
黄梓群
罗程
李斌
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tencent Technology Shenzhen Co Ltd
Original Assignee
Tencent Technology Shenzhen Co Ltd
Filing date
Publication date
Application filed by Tencent Technology Shenzhen Co Ltd filed Critical Tencent Technology Shenzhen Co Ltd
Priority to CN202111251532.9A priority Critical patent/CN113971028B/en
Publication of CN113971028A publication Critical patent/CN113971028A/en
Application granted granted Critical
Publication of CN113971028B publication Critical patent/CN113971028B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Abstract

The application discloses a data processing method, and related embodiments thereof relate to the technical field of computers, and can be applied to cloud technology, artificial intelligence, intelligent traffic, auxiliary driving and other scenes. The method comprises the following steps: based on semantic analysis of the code to be detected, an abstract syntax tree corresponding to the code to be detected is obtained, and a target character string with the language type being the first language type is determined from the code to be detected; adding an objective function call for an objective character string in the code to be detected to generate an objective code; the objective function is used for displaying the objective character string in a second language type when the objective code runs, wherein the second language type is the language type of the language environment in which the objective code runs. The method and the device can analyze and modify the code to be detected, so that the target character string obtained after modification can be displayed in the language type of the language environment in which the target code is located when in operation, effective interaction with a user in the language environment can be realized, and user experience is improved.

Description

Data processing method, apparatus, device, storage medium and computer program product
Technical Field
The present application relates to the field of computer technology, and in particular, to a data processing method, apparatus, device, storage medium, and computer program product.
Background
When developing software, web pages, applets or the like, internationalization processing is usually required to be performed on codes, so that the codes can be matched with the language environment in which the codes run, namely, character strings used for interaction with users in the codes can be displayed in the language type of the language environment in which the codes run, and effective interaction with users in the language environment is achieved. For example, if the language type of the language environment in which the code is running is chinese, it is required that the character string used for interaction with the user in the code can be displayed in chinese; if the language type of the language environment in which the code is located is English when the code is operated, the character string used for interacting with the user in the code is required to be displayed in English. However, when a developer writes a code in an integrated development environment (INTEGRATED DEVELOPMENT ENVIRONMENT, IDE), internationalization processing on the code is sometimes omitted, so that the code is defective, and thus cannot be matched with the language environment in which the code is running, that is, a character string used for interacting with a user in the code cannot be displayed in the language type of the language environment in which the code is running, and effective interaction with the user in the language environment cannot be achieved, so that user experience is reduced.
Disclosure of Invention
The embodiment of the application provides a data processing method, a device, equipment, a storage medium and a computer program product, which can analyze and modify a code to be detected, so that when the modified target code runs, a target character string can be displayed in the language type of the language environment in which the target code runs, the effective interaction with a user in the language environment can be realized, and the user experience is improved.
In one aspect, an embodiment of the present application provides a data processing method, including:
Acquiring a code to be detected;
Carrying out semantic analysis on the code to be detected to obtain an abstract syntax tree corresponding to the code to be detected;
Determining a target character string from the code to be detected based on an abstract syntax tree corresponding to the code to be detected, wherein the language type of the target character string is a first language type;
Adding an objective function call to an objective character string in the code to be detected to generate an objective code; and the objective function is used for displaying the target character string in a second language type when the target code runs, wherein the second language type is the language type of the language environment in which the target code runs.
In one aspect, an embodiment of the present application provides a data processing apparatus, including:
the acquisition unit is used for acquiring the code to be detected;
The processing unit is used for carrying out semantic analysis on the code to be detected to obtain an abstract syntax tree corresponding to the code to be detected;
the processing unit is further configured to determine a target character string from the code to be detected based on an abstract syntax tree corresponding to the code to be detected, where a language type of the target character string is a first language type;
The processing unit is further used for adding an objective function call to the objective character string in the code to be detected to generate an objective code; and the objective function is used for displaying the target character string in a second language type when the target code runs, wherein the second language type is the language type of the language environment in which the target code runs.
In one aspect, an embodiment of the present application provides a data processing apparatus, where the data processing apparatus includes an input interface and an output interface, and further includes:
A processor adapted to implement one or more instructions; and
A computer storage medium storing one or more instructions adapted to be loaded by the processor and to perform the data processing method described above.
In one aspect, an embodiment of the present application provides a computer storage medium, where computer program instructions are stored, where the computer program instructions are used to execute the above-mentioned data processing method when executed by a processor.
In one aspect, embodiments of the present application provide a computer program product or computer program, the computer program product comprising a computer program stored in a computer storage medium; the processor of the data processing apparatus reads the computer program from the computer storage medium and executes the computer program, so that the data processing apparatus executes the above-described data processing method.
In the embodiment of the application, after the data processing equipment acquires the code to be detected, semantic analysis can be carried out on the code to be detected to obtain an abstract syntax tree corresponding to the code to be detected, a target character string with the language type of a first language type is determined from the code to be detected based on the abstract syntax tree corresponding to the code to be detected, and a target function call is further added to the target character string in the code to be detected to generate the target code; the target function is used for displaying the target character string in a second language type when the target code runs, wherein the second language type is the language type of the language environment in which the target code runs. Internationalization processing of the code to be detected can be realized based on semantic analysis of the code to be detected, namely, a target character string with the language type of the first language type is determined from the code to be detected based on semantic analysis of the code to be detected, and a target function call is further added to the target character string in the code to be detected to generate a target code; the target code can be matched with the language environment in which the target code is operated, namely, when the target code is operated, the target character string can be displayed in the language type of the language environment in which the target code is operated, so that effective interaction with a user in the language environment can be realized, and the user experience is improved.
Drawings
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings that are required in the embodiments or the description of the prior art will be briefly described, and it is obvious that the drawings in the following description are only some embodiments of the present application, and other drawings may be obtained according to these drawings without inventive effort for a person of ordinary skill in the art.
FIG. 1 is a schematic flow chart of a data processing method according to an embodiment of the present application;
FIG. 2a is a schematic diagram of an abstract syntax tree corresponding to a code to be detected according to an embodiment of the present application;
FIG. 2b is a schematic diagram of an abstract syntax tree corresponding to another code to be detected according to an embodiment of the present application;
FIG. 3 is a flowchart of another data processing method according to an embodiment of the present application;
FIG. 4a is a schematic diagram of determining a target string according to an embodiment of the present application;
FIG. 4b is a schematic diagram of another embodiment of determining a target string;
FIG. 5 is a schematic diagram of a determining target subtree according to an embodiment of the present application;
FIG. 6a is a schematic diagram of a modified abstract syntax tree according to an embodiment of the present application;
FIG. 6b is a schematic diagram of another modified abstract syntax tree provided by an embodiment of the present application;
FIG. 7 is a flow chart of generating object code according to an embodiment of the present application;
FIG. 8 is a flow chart of another method for generating object code according to an embodiment of the present application;
FIG. 9a is a schematic diagram of a code detection tool ESLint prompting a target string according to an embodiment of the present application;
FIG. 9b is a schematic diagram illustrating a prompting of a target string by another code detection tool ESLint according to an embodiment of the present application;
FIG. 10 is a schematic diagram of a data processing apparatus according to an embodiment of the present application;
Fig. 11 is a schematic structural diagram of a data processing apparatus according to an embodiment of the present application.
Detailed Description
The following description of the embodiments of the present application will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present application, but not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the application without making any inventive effort, are intended to be within the scope of the application.
In order to achieve effective interaction between a code and a user in any language environment when the code runs in the any language environment so as to improve user experience, the embodiment of the application provides a data processing scheme, which can determine a target character string with a language type of a first language type from the code to be detected based on semantic analysis of the code to be detected, and further add a target function call to the target character string in the code to be detected to generate a target code, wherein the target function is used for displaying the target character string in a second language type when the target code runs, and the second language type is the language type of the language environment in which the target code runs. The first language type is a language type adopted when writing a target character string, the target character string is a character string used for interaction with a user in a code to be detected, the character string is determined from a main body part of the code to be detected and is not a character string determined from an annotating part of the code to be detected, the main body part of the code to be detected is an executable part of the code to be detected, the annotating part of the code to be detected is an annotating content used for explaining the code to be detected, and the annotating part of the code to be detected can facilitate understanding of developers on the code to be detected. For example, if the first language type is chinese and the language type of the language environment in which the target code is operated is english, the target character string is displayed in english when the target code is operated in the language environment.
In a specific implementation, the data processing scheme may be executed by a data processing device, where the data processing device may be a terminal device or a server; the terminal devices herein may include, but are not limited to: computers, smart phones, tablet computers, notebook computers, intelligent voice interaction equipment, intelligent home appliances, vehicle-mounted terminals and the like; the server may be an independent physical server, a server cluster or a distributed system formed by a plurality of physical servers, or a cloud server providing cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, a content distribution network (Content Delivery Network, CDN), basic cloud computing services such as big data and an artificial intelligent platform.
Based on the above data processing scheme, the embodiment of the application provides a data processing method. Referring to fig. 1, a flow chart of a data processing method according to an embodiment of the present application is shown. The data processing method shown in fig. 1 may be performed by a data processing apparatus. The data processing method shown in fig. 1 may include the steps of:
S101, acquiring a code to be detected.
The code to be detected is any source code written by a developer; the code to be detected can be written in any programming language, for example, the code to be detected can be written in programming languages such as C language, javaScript, python and the like; the code to be detected comprises an operable body portion; optionally, the code to be detected may further include an annotation part, where the annotation part of the code to be detected is annotation content for explaining the code to be detected, so that a developer can understand the code to be detected conveniently.
S102, carrying out semantic analysis on the code to be detected to obtain an abstract syntax tree corresponding to the code to be detected.
The abstract syntax tree corresponding to the code to be detected is a structure describing code syntax logic of the code to be detected, namely a structure describing code syntax logic of a main body part of the code to be detected. An abstract Syntax tree (Abstract Syntax Tree, AST), or simply Syntax tree (Syntax tree), is an abstract representation of the source code Syntax structure, the abstract Syntax tree representing the Syntax structure of the programming language in the form of a tree, each node on the tree representing a Syntax structure in the source code, the abstract Syntax tree having associated features of the tree. The abstract syntax tree corresponding to the code to be detected comprises a plurality of nodes, father-son relations exist among the nodes, and one node in the nodes represents a syntax structure of the code to be detected. For example, if the main body portion of the code to be detected is var desc= "hello" written in JavaScript, and the comment portion of the code to be detected is "declare a variable named desc and assign it as hello", the abstract syntax tree corresponding to the code to be detected may include 3 nodes, as shown in fig. 2a, where node 1 represents the variable declaration, node 2 represents the variable name desc, and node 3 represents a character string "hello", and the character string "hello" is an initial value of the variable desc. For another example, if the main body portion of the code to be detected is var desc= "selected" +num+ "person" written in JavaScript, where num is a string variable that is declared in advance, and the comment portion of the code to be detected is "declaring a variable named desc, indicating that several persons have been selected", then the abstract syntax tree corresponding to the code to be detected may include 7 nodes, where node 1 represents the variable declaration, node 2 represents the variable name desc, node 3 and node 4 each represent a string splice, specifically, a splice "+", node 5 represents a string "person", node 6 represents a string "selected", node 7 represents a string variable num, string splice+, string "selected string variable num, and string" person "constitute the initial value of the variable desc.
In one embodiment, the data processing device performs semantic analysis on the code to be detected to obtain an abstract syntax tree corresponding to the code to be detected, which may include: and calling a code detection tool to perform semantic analysis on the code to be detected to obtain an abstract syntax tree corresponding to the code to be detected. Specifically, the code detection tool may perform semantic analysis on a main body portion of the code to be detected, and obtain an abstract syntax tree corresponding to the code to be detected according to code syntax logic of the main body portion of the code to be detected. Alternatively, the code detection tool used may be different for the code to be detected written in different programming languages, for example, if the code to be detected is written in JavaScript, the code detection tool ESLint may be used to perform semantic analysis on the code to be detected.
S103, determining a target character string from the code to be detected based on the abstract syntax tree corresponding to the code to be detected.
The language type of the target character string is a first language type. The target character string is a character string used for interacting with a user in the code to be detected; the character string in the code to be detected for interaction with the user refers to: when the code to be detected runs, a character string which can be directly interacted with a user is required to be displayed in a running result page of the code to be detected; the character string used for interacting with the user in the code to be detected is written in the main body part of the code to be detected, so that the target character string determined from the code to be detected is the character string determined from the main body part of the code to be detected and is not the character string determined from the annotation part of the code to be detected; moreover, since the target character string is determined based on the abstract syntax tree corresponding to the code to be detected, and the abstract syntax tree corresponding to the code to be detected is a structure describing the code syntax logic of the main body part of the code to be detected, it can be known that the target character string determined from the code to be detected is a character string determined from the main body part of the code to be detected, and is not a character string determined from the comment part of the code to be detected; for convenience of subsequent description, the embodiments of the present application will be described with reference to the code to be detected that does not include the comment portion. For example, if the code to be detected is a code corresponding to the commodity detail page of the commodity a, if the name of the commodity a is "commodity a", the class of the commodity a is "food", the specification of the commodity a is "300 g" and the selling price of the commodity a is "35 yuan" need to be displayed in the commodity detail page of the commodity a, so that the user knows the specific parameters of the commodity a, in this case, the character string for interaction with the user in the code to be detected may include "commodity a", "food", "300 g" and "35 yuan".
Further, the data processing device determines, based on an abstract syntax tree corresponding to the code to be detected, that the target character string is: and the character string used for interacting with the user in the code to be detected is not added with the character string called by the target function. The target function is used for displaying the character string added with the target function call in the code in a second language type when the code runs, wherein the second language type is the language type of the language environment where the code runs, and the code can be any source code, for example, the code to be detected and the target code generated after the target function call is added to the target character string in the code to be detected. Alternatively, the objective function may be developed by a developer, or may be some commonly used functions capable of displaying a string added with an objective function call in a code in a language type of a language environment in which the code is running, for example, may be weLANG functions. The language environment where the code runs can be determined by the system language environment of the code running device running the code, the system language environment of the code running device running the code can be determined as the language environment where the code runs, and the language type of the system language environment of the code running device running the code is determined as the language type of the language environment where the code runs; for example, if the code is run in the code running device a and the code running device B, the language type of the system language environment of the code running device a is chinese, and the language type of the system language environment of the code running device B is english; the language type of the language environment in which the code is run in the code running device a is chinese and the language type of the language environment in which the code is run in the code running device B is english.
For example, if the character strings in the code to be detected for interaction with the user include "commodity a", "food", "300 g" and "35 yuan", wherein the character strings "commodity a", "food" are not added with the target function call, the target character strings are "commodity a" and "food"; for another example, if the code to be detected is var desc= "hello", the character string used for interacting with the user in the code to be detected is "hello", and the target function call is not added to the character string, and the determined target character string is "hello"; for another example, if the code to be detected is var desc= "selected" +num+ "person", where num is a pre-declared string variable, the string used for interaction with the user in the code to be detected is "selected" +num+ "person", and the string is not added with the target function call, and the determined target string is "selected" +num+ "person".
S104, adding an objective function call for an objective character string in the code to be detected to generate an objective code.
The target function is used for displaying the target character string in a second language type when the target code runs, wherein the second language type is the language type of the language environment in which the target code runs. And adding the target function call to the target character string which is not added with the target function call in the character string used for interacting with the user in the code to be detected, and displaying the target character string in the language type of the language environment in which the target code is positioned by the operation of the target function.
In the embodiment of the application, after the data processing equipment acquires the code to be detected, semantic analysis can be carried out on the code to be detected to obtain an abstract syntax tree corresponding to the code to be detected, a target character string with the language type of a first language type is determined from the code to be detected based on the abstract syntax tree corresponding to the code to be detected, and a target function call is further added to the target character string in the code to be detected to generate the target code; the target function is used for displaying the target character string in a second language type when the target code runs, wherein the second language type is the language type of the language environment in which the target code runs. Internationalization processing of the code to be detected can be realized based on semantic analysis of the code to be detected, namely, a target character string with the language type of the first language type is determined from the code to be detected based on semantic analysis of the code to be detected, and a target function call is further added to the target character string in the code to be detected to generate a target code; the target code can be matched with the language environment in which the target code is operated, namely, when the target code is operated, the target character string can be displayed in the language type of the language environment in which the target code is operated, so that effective interaction with a user in the language environment can be realized, and the user experience is improved.
Based on the above method embodiment, another data processing method is provided in the embodiment of the present application. Referring to fig. 3, a flow chart of another data processing method according to an embodiment of the present application is shown. The data processing method shown in fig. 3 may be performed by a data processing apparatus. The data processing method shown in fig. 3 may include the steps of:
S301, obtaining a code to be detected.
S302, carrying out semantic analysis on the code to be detected to obtain an abstract syntax tree corresponding to the code to be detected.
The abstract syntax tree comprises a plurality of nodes, parent-child relations exist among the nodes, and one node in the nodes represents a syntax structure of the code to be detected. The process of step S301 is the same as the process of step S201, and the process of step S302 is the same as the process of step S201, and will not be described again here.
S303, taking any node which is not traversed in the abstract syntax tree as a target node which is traversed currently.
S304, if the target node represents a first character string with the language type being the first language type, determining whether the target node adds the target function call.
S305, if the target node does not add the target function call, determining a target character string based on the first character string.
In step S303 to step S305, as shown in fig. 4a, which is a schematic diagram of determining a target character string according to an embodiment of the present application, the data processing device uses any node that is not traversed in the abstract syntax tree as a target node that is traversed currently; if the target node does not represent the first character string with the language type of the first language type, the target node is used as the traversed node, and the target node is redetermined under the condition that the abstract syntax tree is not traversed (namely, whether the abstract syntax tree is traversed is determined, if the abstract syntax tree is not traversed, the related process of using any node which is not traversed in the abstract syntax tree as the currently traversed target node is repeatedly executed; if the target node represents a first character string with the language type being the first language type, determining whether the target node adds the target function call; if the target node is added with the target function call, the target node is used as the traversed node, and the target node is redetermined under the condition that the abstract syntax tree is not traversed; if the target node does not add the target function call, determining a target character string based on the first character string.
In one embodiment, the data processing device traverses the abstract syntax tree in a preamble traversal manner, a middle-order traversal manner or a subsequent traversal manner, and the embodiment of the application subsequently uses the data processing device to describe the preamble traversal of the abstract syntax tree as an example.
In one embodiment, the first string is a grammar structure represented by a target node, and the target node does not represent the first string whose language type is the first language type, which means that: the target node does not represent a character string or the target node represents a character string, but the language type of the first character string represented by the target node is not the first language type; the target node represents a first character string with a language type of a first language type, and is: the target node represents a character string, and the language type of the first character string represented by the target node is a first language type. The data processing apparatus determining whether the target node adds the target function call may include: if the father node of the target node represents the function call and the brother node of the target node represents the target function, determining that the target node has added the target function call; if the father node of the target node does not represent the function call, or the father node of the target node represents the function call but the brothers node of the target node does not represent the target function, determining that the target node does not add the target function call.
In a specific implementation, as shown in fig. 4b, which is a schematic diagram of another determination target character string provided by an embodiment of the present application, the data processing device uses any node that is not traversed in the abstract syntax tree as a currently traversed target node; determining whether the target node represents a character string; if the target node does not represent the character string, the target node is used as the traversed node, and the target node is redetermined under the condition that the abstract syntax tree is not traversed; if the target node represents the character string, the character string represented by the target node is used as a first character string, and whether the language type of the first character string is the first language type is determined; if the language type of the first character string is not the first language type, taking the target node as the traversed node, and re-determining the target node under the condition that the abstract syntax tree is not traversed, if the language type of the first character string is the first language type, determining whether a father node of the target node represents function call; if the father node of the target node does not represent the function call, determining that the target node does not add the target function call, and if the father node of the target node represents the function call, determining whether the brother node of the target node represents the target function; if the brother node of the target node does not represent the target function, determining that the target node does not add the target function call, and if the brother node of the target node represents the target function, determining that the target node has added the target function call; if the target node is added with the target function call, the target node is used as the traversed node, and the target node is redetermined under the condition that the abstract syntax tree is not traversed; if the target node does not add the target function call, determining a target character string based on the first character string.
Further, if the target node does not add the target function call, the data processing apparatus determines the target string based on the first string, and may include: if the target node does not add the target function call, determining whether a father node of the target node represents character string splicing; if the father node of the target node does not represent the character string splicing, determining the first character string as the target character string; if the father node of the target node represents string splicing, performing recursion operation of determining the target string from the father node of the target node to obtain a target subtree from the abstract syntax tree based on father-son relations among all nodes in the abstract syntax tree, wherein the root node of the target subtree represents string splicing, and leaf nodes of the target subtree comprise the target node; and determining the character string in the code to be detected, which is indicated by the target subtree, as a target character string.
In a specific implementation, the data processing apparatus, starting from a parent node of the target node, performs a recursive operation of determining the target string to obtain the target subtree from the abstract syntax tree based on parent-child relationships between nodes in the abstract syntax tree, may include: sequentially determining whether one or more ancestor nodes of the initial node represent character string splicing or not by taking a father node of the target node as the initial node when the recursion operation starts to be executed until the target ancestor node is determined from the one or more ancestor nodes of the initial node and is taken as a termination node when the recursion operation stops, wherein the target ancestor node does not represent character string splicing; and determining a target subtree comprising the target node from the abstract syntax tree by taking the ancestor node belonging to the child node of the termination node as the root node of the target subtree in one or more ancestor nodes of the initial node processed through the recursion operation. Wherein, ancestor nodes of the initial node refer to: nodes on branches passed from a root node of the abstract syntax tree to the initial node; the determined target ancestor node refers to: the first one of the branches from the initial node to the root node of the abstract syntax tree does not represent an ancestor node of the string splice; the root node of the determined target subtree refers to: on the branch from the initial node to the root node of the abstract syntax tree, the child node of the target ancestor node, that is, there may be multiple child nodes of the target ancestor node in the abstract syntax tree, and the child node of the target ancestor node determined for being the root node of the target subtree is a node on the branch from the initial node to the root node of the abstract syntax tree among the multiple child nodes of the target ancestor node.
For example, if the code to be detected is var desc= "hello", the abstract syntax tree is the abstract syntax tree as shown in fig. 2a, and if the first language type is set to be chinese and the abstract syntax tree is traversed in a preamble, the first target node determined by the data processing apparatus is node 1; if the node 1 does not represent a character string, taking the node 1 as a traversed node, and redefining a second target node as a node 2; if the node 2 does not represent a character string, taking the node 2 as a traversed node, and redefining a third target node as the node 3; the node 3 represents a character string, the character string 'hello' represented by the node 3 is used as a first character string, and whether the language type of the first character string is Chinese is determined; because the language type of the first character string 'hello' is Chinese, determining whether the father node of the node 3, namely the node 1, represents character string splicing; since node 1 does not represent string concatenation, the first string "hello" is determined to be the target string.
For another example, if the code to be detected is var desc= "selected" +num+ "person", the abstract syntax tree is the abstract syntax tree as shown in fig. 2b, and if the first language type is set to be chinese, and the abstract syntax tree is traversed in a preamble, the first target node determined by the data processing device is node 1; if the node 1 does not represent a character string, taking the node 1 as a traversed node, and redefining a second target node as a node 2; if the node 2 does not represent a character string, taking the node 2 as a traversed node, and redefining a third target node as the node 3; if the node 3 does not represent a character string, taking the node 3 as a traversed node, and redefining a fourth target node as a node 4; if the node 4 does not represent a character string, taking the node 4 as a traversed node, and redefining a fifth target node as a node 6; the node 6 represents a character string, the character string represented by the node 6 is selected as a first character string, and whether the language type of the first character string is Chinese is determined; since the language type of the first character string "selected" is chinese, determining whether the parent node of the node 6, i.e., the node 4, represents a character string concatenation; since node 4 represents string concatenation, using node 4 as an initial node when the recursive operation starts to be executed, sequentially determining whether one or more ancestor nodes (node 3 and node 1) of node 4 represent string concatenation until a target ancestor node is determined from node 3 and node 1, and is node 1 as a termination node when the recursive operation stops; among one or more ancestor nodes of the initial node (i.e., node 3 and node 1) processed via the recursive operation, the ancestor node (node 3) of the child node belonging to the terminating node (node 1) is taken as the root node of the target subtree, and the target subtree including the target node is determined from the abstract syntax tree, and the determined target subtree may be indicated by the reference numeral 501 in fig. 5, where the target subtree includes node 3, node 4, node 5, node 6, and node 7. Further, the data processing device determines the character string in the code to be detected, which is indicated by the target subtree, as a target character string; that is, the character string "selected" +num+ "person" in the code to be detected, which is indicated by the target subtree, is determined as the target character string.
In a specific implementation, the data processing device sequentially determines whether one or more ancestor nodes (node 3 and node 1) of the node 4 represent character string splicing or not until a target ancestor node is determined from the node 3 and the node 1, and in the process of determining that the target ancestor node is the node 1, the first ancestor node of the node 4, namely a father node of the node 4, namely whether the node 3 represents character string splicing or not is determined; since node 3 represents string concatenation, determining whether the second ancestor node of node 4, the parent node of node 3, node 1, represents string concatenation; since node 1 does not represent a string splice, the target ancestor node is determined to be node 1.
S306, adding an objective function call to the objective character string in the code to be detected to generate an objective code.
In one embodiment, the data processing apparatus adds an object function call to an object string in the code to be detected to generate an object code, which may include: generating a target function call subtree corresponding to the target character string based on the target character string and the target function call; if the target character string is the first character string, replacing the target node with a target function calling subtree to obtain a modified abstract syntax tree; if the target character string is obtained based on the target subtree, replacing the target subtree with a target function calling subtree to obtain a modified abstract syntax tree; and carrying out format conversion processing on the modified abstract syntax tree to obtain an object code. Further, when the target string is obtained based on the target subtree and the target string includes a string variable, the data processing apparatus generates a target function call subtree corresponding to the target string based on the target string and the target function call, which may include: splicing the leaf nodes of the target subtrees to obtain character strings to be replaced, which correspond to the target character strings; replacing character string variables included in the character string to be replaced with the placeholder to obtain a target character string to be replaced; and generating a target function call subtree corresponding to the target character string based on the target character string to be replaced, the character string variable and the target function call. Further, the data processing device performs a splicing process on the leaf nodes of the target subtree to obtain a character string to be replaced corresponding to the target character string, which may include: and performing preamble traversal on the target subtree, sequentially determining leaf nodes of the target subtree, and performing splicing processing on the sequentially determined leaf nodes of the target subtree to obtain a character string to be replaced, which corresponds to the target character string. Optionally, the leaf nodes of the target subtrees which are determined in sequence can be stored in a list, and the leaf nodes of the target subtrees stored in the list are spliced to obtain the character strings to be replaced, which correspond to the target character strings.
For example, as shown in fig. 6a, a schematic diagram of a modified abstract syntax tree according to an embodiment of the present application is shown; if the code to be detected is var desc= "hello", the abstract syntax tree is shown as 601 mark, if the first language type is set as Chinese, the objective function is weLANG function, and the abstract syntax tree is traversed in advance; then, in this case, the target string determined based on the first string ("hello") represented by the target node (node 3) is "hello", that is, the target string is the first string, where the data processing apparatus may use the target string as a parameter of the target function, generate a target function call subtree corresponding to the target string based on the target string and the target function call, where the obtained target function call subtree may be shown as 602 mark, and include 3 nodes, where the 3 nodes represent the function call, the target function weLANG, and the target string "hello", respectively, where the target string "hello" is the parameter of the target function, and at this time, replace the target node with the target function call subtree, and the obtained modified abstract syntax tree may be shown as 603 mark. Further, the data processing device may perform format conversion processing on the modified abstract syntax tree, where the resulting target code is var desc= weLANG ("hello").
As another example, as shown in fig. 6b, another schematic diagram of a modified abstract syntax tree is provided according to an embodiment of the present application; if the code to be detected is var desc= "selected" +num+ "person", the abstract syntax tree is the abstract syntax tree shown in fig. 2b, if the first language type is set to be Chinese, the objective function is weLANG functions, and the abstract syntax tree is traversed in advance; then, in this case, the target string determined based on the first string ("selected") represented by the target node (node 6) is "selected" +num+ "person", and the determined target subtree is indicated by the 611 flag; because the determined target character string comprises a character string variable num, namely the target character string is obtained based on a target subtree, and the target character string comprises a character string variable; the data processing equipment can perform preamble traversal on the target subtree, sequentially determine leaf nodes of the target subtree, sequentially comprise a node 6, a node 7 and a node 5, and perform splicing processing on the sequentially determined leaf nodes of the target subtree to obtain a character string 'num person selected' corresponding to the target character string; then, replacing the character string variable num included in the character string to be replaced 'selected num person' with the placeholder%s, so as to obtain a target character string to be replaced 'selected%s person'; further, the data processing device may use the target to-be-replaced string and the string variable as parameters of the target function, respectively, to generate a target function call subtree corresponding to the target string based on the target to-be-replaced string, the string variable and the target function call, where the obtained target function call subtree may be shown as 612 mark, and includes 4 nodes, where the 4 nodes represent the function call, the target function weLANG, the target to-be-replaced string "selected% s person" and the string variable num, where the target to-be-replaced string "selected% s person" and the string variable num are respectively used as parameters of the target function, and at this time, the target subtree is replaced by the target function call subtree, and the obtained modified abstract syntax tree may be shown as 613 mark. Further, the data processing device may perform format conversion processing on the modified abstract syntax tree, where the resulting target code is var desc= weLANG ("co-select% s person", num).
Fig. 7 is a schematic diagram of generating an object code according to an embodiment of the present application, where a data processing device may obtain a code to be detected; then carrying out semantic analysis on the code to be detected to obtain an abstract syntax tree corresponding to the code to be detected; determining a target character string with the language type being the first language type from the code to be detected based on an abstract syntax tree corresponding to the code to be detected; generating an objective function call subtree corresponding to the objective character string based on the objective character string and the objective function call, and modifying the abstract syntax tree based on the objective function call subtree to obtain a modified abstract syntax tree; and carrying out format conversion processing on the modified abstract syntax tree to obtain an object code.
In one embodiment, the data processing apparatus adds an object function call to an object string in the code to be detected to generate an object code, which may include: generating a target function call code corresponding to the target character string based on the target character string and the target function call; and replacing the target character string in the code to be detected with the target function calling code to obtain the target code. Further, if the target character string is obtained based on the target subtree, the target character string comprises a character string variable; the data processing apparatus generates an object function call code corresponding to the object character string based on the object character string and the object function call, which may include: splicing the leaf nodes of the target subtrees to obtain character strings to be replaced, which correspond to the target character strings; replacing character string variables included in the character string to be replaced with the placeholder to obtain a target character string to be replaced; and generating an objective function call code corresponding to the objective character string based on the objective character string to be replaced, the character string variable and the objective function call. In a specific implementation, the data processing device may determine whether the target character string is obtained based on the target subtree, and if the target character string is obtained based on the target subtree, the data processing device may perform a splicing process on leaf nodes of the target subtree to obtain a character string to be replaced corresponding to the target character string; further, if the target character string comprises a character string variable, replacing the character string variable included in the character string to be replaced with the placeholder to obtain the target character string to be replaced, and if the target character string does not comprise the character string variable, determining the character string to be replaced as the target character string to be replaced; and generating a target function call code corresponding to the target character string based on the target character string to be replaced, the character string variable and the target function call.
For example, if the code to be detected is var desc= "hello", the abstract syntax tree is the abstract syntax tree shown in fig. 2a, if the first language type is set to be chinese, the objective function is weLANG functions, and the abstract syntax tree is traversed in advance; then, in this case, the target character string determined based on the first character string ("hello") represented by the target node (node 3) is "hello", and then the data processing apparatus may generate, with the target character string as a parameter of the target function, a target function call code corresponding to the target character string based on the target character string and the target function call, which is weLANG ("hello"); further, the data processing device replaces the target character string "hello" in the code to be detected with the target function call code, and the obtained target code var desc= weLANG ("hello").
For another example, if the code to be detected is var desc= "selected" +num+ "person", the abstract syntax tree is the abstract syntax tree as shown in fig. 2b, if the first language type is set to be chinese, the objective function is weLANG functions, and the abstract syntax tree is traversed in advance; then, in this case, the target string determined based on the first string ("selected") represented by the target node (node 6) is "selected" +num+ "person", the target string is obtained based on the target subtree, and the target string includes the string variable num, and the data processing apparatus may perform the concatenation processing on the leaf nodes of the target subtree to obtain the string to be replaced "selected num person" corresponding to the target string; then, replacing the character string variable num included in the character string to be replaced 'selected num person' with the placeholder%s, so as to obtain a target character string to be replaced 'selected%s person'; further, the data processing device may use the target string to be replaced and the string variable as parameters of the target function, respectively, so as to generate a target function call code corresponding to the target string based on the target string to be replaced, the string variable and the target function call, where the obtained target function call code is weLANG ("co-select% s person", num); further, the data processing device replaces the target string "selected" +num+ "person" in the code to be detected with the target function call code, and the resulting target code var desc= weLANG ("co-select% s person", num).
Further, as shown in fig. 8, another flow chart for generating an object code provided by the present application, the data processing device may obtain a code to be detected; then carrying out semantic analysis on the code to be detected to obtain an abstract syntax tree corresponding to the code to be detected; taking any node which is not traversed in the abstract syntax tree as a target node which is traversed currently; if the target node does not represent the first character string with the language type of the first language type, the target node is used as the traversed node, and the target node is redetermined under the condition that the abstract syntax tree is not traversed; if the target node represents a first character string with the language type being the first language type, determining whether the target node adds the target function call; if the target node is added with the target function call, the target node is used as the traversed node, and the target node is redetermined under the condition that the abstract syntax tree is not traversed; if the target node is not added with the target function call, determining a target character string based on the first character string, adding the target function call to the target character string to update the code to be detected, taking the target node as a traversed node, and re-determining the target node under the condition that the abstract syntax tree is not traversed; and then, the target character string can be redetermined based on the redetermined target node, and a target function call is added to the redetermined target character string to repeatedly update the code to be detected until the abstract syntax tree is traversed. Further, when the data processing device adds an objective function call for the newly determined objective character string to repeatedly update the code to be detected, if the newly determined objective character string is the same as a certain objective character string determined by the history, the newly determined objective node is used as a traversed node, and the objective node is newly determined under the condition that the abstract syntax tree is not traversed; if the re-determined target character string is different from any one of the target character strings determined by the history, adding an objective function call for the re-determined target character string to repeatedly update the code to be detected.
In one embodiment, after updating the code to be detected, the data processing device may output the finally obtained target code after adding the target function call to all the character strings which are not added with the target function call and have the language type of the first language type in the code to be detected. For example, the code to be detected can be output to an integrated development environment in which a developer writes the code to be detected; further, the strings to which the target function call was added via the data processing device may be prompted to enable a developer to know which strings were modified. Optionally, the corresponding function of the data processing method provided by the embodiment of the present application may be integrated into a code detection tool, for example, may be integrated into a code detection tool ESLint for a code to be detected written in JavaScript, so that semantic analysis may be performed on the code to be detected written in JavaScript by the code detection tool ESLint to obtain an abstract syntax tree corresponding to the code to be detected; determining a target character string with the language type being the first language type from the code to be detected based on an abstract syntax tree corresponding to the code to be detected; adding an objective function call for an objective character string in the code to be detected to generate an objective code; and outputs the resulting object code, for example, in an integrated development environment for display. Optionally, the string to which the target function call was added via the data processing device may be prompted to enable the developer to learn which strings were modified.
Optionally, part of the functions of the data processing method provided by the embodiment of the present application may be integrated into a code detection tool, for example, may be integrated into a code detection tool ESLint for a code to be detected written in JavaScript, so that the code to be detected may be subjected to semantic analysis by the code detection tool ESLint to obtain an abstract syntax tree corresponding to the code to be detected; and determining a target character string with the language type of the first language type from the code to be detected based on an abstract syntax tree corresponding to the code to be detected, and prompting the obtained target character string in an integrated output environment to prompt a developer to add a target function call to the target character string, wherein prompting of the obtained target character string can be given in a prompting information mode. For example, when a developer writes a code in an integrated development environment, a code detection tool ESLint may be installed and a check rule is configured, and then the code detection tool ESLint may obtain the code written by the developer in real time and use the code as a code to be detected, so as to analyze the code written by the developer in real time and prompt the obtained target character string in the integrated output environment, as shown in fig. 9a, a schematic diagram of prompting the target character string by the code detection tool ESLint provided by the embodiment of the present application is shown, where the prompting of the obtained target character string may be given in a prompting information manner, for example, "detect chinese document, please use weLANG package. Optionally, the developer may globally install the code detection tool ESLint in the integrated development environment and configure the inspection rule, so that the code detection tool may obtain a code file to be inspected specified by the developer in the command line, and take a code in the code file as the code to be detected, so as to analyze the code in the code file, and prompt the obtained target character string in the integrated output environment; as shown in fig. 9b, another schematic diagram of a code detection tool ESLint for prompting a target string according to an embodiment of the present application is provided, where the prompting of the obtained target string may be given in the form of prompting information, for example, "detect chinese document, package with weLANG".
In the embodiment of the application, after the data processing equipment acquires the code to be detected, semantic analysis can be carried out on the code to be detected to obtain an abstract syntax tree corresponding to the code to be detected, any node which is not traversed in the abstract syntax tree is used as a target node which is traversed currently, if the target node represents a first character string of a first language type, whether the target node adds a target function call is determined, if the target node does not add the target function call, the target character string is determined based on the first character string, and the target function call is further added to the target character string in the code to be detected to generate the target code; the target function is used for displaying the target character string in a second language type when the target code runs, wherein the second language type is the language type of the language environment in which the target code runs. The method comprises the steps that based on an abstract syntax tree, a target character string which is not added with target function call and has a language type of a first language type is determined from codes to be detected, and target function call is further added to the target character string in the codes to be detected to generate target codes; the target code can be matched with the language environment in which the target code is operated, namely, when the target code is operated, the target character string can be displayed in the language type of the language environment in which the target code is operated, so that effective interaction with a user in the language environment can be realized, and the user experience is improved.
Based on the method embodiment, the embodiment of the application provides a data processing device. Referring to fig. 10, a schematic structural diagram of a data processing apparatus according to an embodiment of the present application may include an obtaining unit 1001 and a processing unit 1002. The data processing apparatus shown in fig. 10 may operate as follows:
an acquiring unit 1001 configured to acquire a code to be detected;
The processing unit 1002 is configured to perform semantic analysis on the code to be detected, so as to obtain an abstract syntax tree corresponding to the code to be detected;
the processing unit 1002 is further configured to determine, based on an abstract syntax tree corresponding to the code to be detected, a target character string from the code to be detected, where a language type of the target character string is a first language type;
The processing unit 1002 is further configured to add an objective function call to an objective string in the code to be detected to generate an objective code; and the objective function is used for displaying the target character string in a second language type when the target code runs, wherein the second language type is the language type of the language environment in which the target code runs.
In one embodiment, the abstract syntax tree comprises a plurality of nodes, wherein father-son relations exist among the plurality of nodes, and one node in the plurality of nodes represents a syntax structure of the code to be detected;
the processing unit 1002 specifically performs the following operations when determining the target string from the code to be detected based on the abstract syntax tree corresponding to the code to be detected:
Taking any node which is not traversed in the abstract syntax tree as a target node which is traversed currently;
if the target node represents a first character string with the language type being the first language type, determining whether the target node adds a target function call;
and if the target node does not add the target function call, determining the target character string based on the first character string.
In one embodiment, when the processing unit 1002 determines whether the target node adds an objective function call, the following operations are specifically performed:
If the father node of the target node represents a function call and the brother node of the target node represents a target function, determining that the target node has added the target function call;
And if the father node of the target node does not represent the function call, or the father node of the target node represents the function call but the brother node of the target node does not represent the target function, determining that the target node does not add the target function call.
In one embodiment, if the target node does not add a target function call, the processing unit 1002 determines the target string based on the first string, specifically performs the following operations:
if the target node is not added with the target function call, determining whether a father node of the target node represents character string splicing;
If the father node of the target node does not represent string splicing, determining the first string as the target string;
If the father node of the target node represents string splicing, performing recursion operation of determining the target string from the father node of the target node to obtain a target subtree from the abstract syntax tree based on father-son relationships among all nodes in the abstract syntax tree, wherein the root node of the target subtree represents string splicing, and leaf nodes of the target subtree comprise the target node;
And determining the character string in the code to be detected, which is indicated by the target subtree, as the target character string.
In one embodiment, the processing unit 1002 performs, starting from a parent node of the target node, a recursive operation of determining the target string, so as to obtain the target subtree from the abstract syntax tree based on a parent-child relationship between the nodes in the abstract syntax tree, and specifically performs the following operations:
sequentially determining whether one or more ancestor nodes of the initial node represent character string splicing or not by taking a father node of the target node as the initial node when the recursive operation starts to be executed until the target ancestor node is determined from the one or more ancestor nodes of the initial node and is taken as the termination node when the recursive operation stops, wherein the target ancestor node does not represent character string splicing;
And determining a target subtree comprising the target node from the abstract syntax tree by taking the ancestor node of the child nodes belonging to the termination node in one or more ancestor nodes of the initial node processed by the recursion operation as a root node of the target subtree.
In one embodiment, when the processing unit 1002 adds an objective function call to the objective string in the code to be detected to generate an objective code, the following operations are specifically executed:
Generating a target function call subtree corresponding to the target character string based on the target character string and the target function call;
If the target character string is the first character string, replacing the target node with the target function calling subtree to obtain a modified abstract syntax tree;
if the target character string is obtained based on the target subtree, replacing the target subtree with the target function calling subtree to obtain a modified abstract syntax tree;
And carrying out format conversion processing on the modified abstract syntax tree to obtain the target code.
In one embodiment, when the processing unit 1002 adds an objective function call to the objective string in the code to be detected to generate an objective code, the following operations are specifically executed:
Generating a target function call code corresponding to the target character string based on the target character string and the target function call;
And replacing the target character string in the code to be detected with the target function calling code to obtain the target code.
In one embodiment, the target string is obtained based on the target subtree, and the target string includes a string variable therein;
when generating the target function call code corresponding to the target character string based on the target character string and the target function call, the processing unit 1002 specifically performs the following operations:
Splicing the leaf nodes of the target subtrees to obtain character strings to be replaced corresponding to the target character strings;
Replacing character string variables included in the character string to be replaced with the placeholder to obtain a target character string to be replaced;
and generating an objective function call code corresponding to the objective character string based on the objective character string to be replaced, the character string variable and the objective function call.
According to one embodiment of the present application, the steps involved in the data processing methods shown in fig. 1 and 3 may be performed by the units in the data processing apparatus shown in fig. 10. For example, step S101 shown in fig. 1 may be performed by the acquisition unit 1001 in the data processing apparatus shown in fig. 10; steps S102 to S104 shown in fig. 1 may be performed by the processing unit 1002 in the data processing apparatus shown in fig. 10. As another example, step S301 shown in fig. 3 may be performed by the acquisition unit 1001 in the data processing apparatus shown in fig. 10; steps S302 to S306 shown in fig. 3 may be performed by the processing unit 1002 in the data processing apparatus shown in fig. 10.
According to another embodiment of the present application, each unit in the data processing apparatus shown in fig. 10 may be separately or completely combined into one or several other units, or some unit(s) thereof may be further split into a plurality of units having smaller functions, which may achieve the same operation without affecting the implementation of the technical effects of the embodiments of the present application. The above units are divided based on logic functions, and in practical applications, the functions of one unit may be implemented by a plurality of units, or the functions of a plurality of units may be implemented by one unit. In other embodiments of the application, the data processing apparatus based on logical functional partitioning may also include other units, and in practical applications, these functions may also be implemented with the assistance of other units, and may be implemented by the cooperation of a plurality of units.
According to another embodiment of the present application, a data processing apparatus as shown in fig. 10 may be constructed by running a computer program (including program code) capable of executing the steps involved in the respective methods as shown in fig. 1 and 3 on a general-purpose computing device such as a computer including a processing element such as a Central Processing Unit (CPU), a random access storage medium (RAM), a read only storage medium (ROM), and the like, and a storage element, and implementing the data processing method of the embodiment of the present application. The computer program may be recorded on, for example, a computer readable storage medium, and loaded into and executed by the computing device described above.
In the embodiment of the present application, after the obtaining unit 1001 obtains the code to be detected, the processing unit 1002 may perform semantic analysis on the code to be detected to obtain an abstract syntax tree corresponding to the code to be detected, determine, based on the abstract syntax tree corresponding to the code to be detected, a target character string with a language type of a first language type from the code to be detected, and further add a target function call to the target character string in the code to be detected to generate the target code; the target function is used for displaying the target character string in a second language type when the target code runs, wherein the second language type is the language type of the language environment in which the target code runs. Internationalization processing of the code to be detected can be realized based on semantic analysis of the code to be detected, namely, a target character string with the language type of the first language type is determined from the code to be detected based on semantic analysis of the code to be detected, and a target function call is further added to the target character string in the code to be detected to generate a target code; the target code can be matched with the language environment in which the target code is operated, namely, when the target code is operated, the target character string can be displayed in the language type of the language environment in which the target code is operated, so that effective interaction with a user in the language environment can be realized, and the user experience is improved.
Based on the method embodiment and the device embodiment, the application also provides data processing equipment. Referring to fig. 11, a schematic structural diagram of a data processing apparatus according to an embodiment of the present application is provided. The data processing device shown in fig. 11 may include at least a processor 1101, an input interface 1102, an output interface 1103, and a computer storage medium 1104. Wherein the processor 1101, the input interface 1102, the output interface 1103, and the computer storage medium 1104 may be connected by a bus or other means.
The computer storage medium 1104 may be stored in a memory of a data processing apparatus, the computer storage medium 1104 being for storing a computer program comprising program instructions, and the processor 1101 being for executing the program instructions stored by the computer storage medium 1104. The processor 1101 (or CPU (Central Processing Unit, central processing unit)) is a computing core and a control core of the data processing apparatus, which are adapted to implement one or more instructions, in particular to load and execute one or more instructions to implement the data processing method flow or corresponding functions described above.
The embodiment of the application also provides a computer storage medium (Memory), which is a Memory device in the data processing device and is used for storing programs and data. It will be appreciated that the computer storage medium herein may include both a built-in storage medium in the terminal and an extended storage medium supported by the terminal. The computer storage medium provides a storage space that stores an operating system of the terminal. Also stored in this memory space are one or more instructions, which may be one or more computer programs (including program code), adapted to be loaded and executed by the processor 1101. It should be noted that, the computer storage medium herein may be a high-speed random access memory (random access memory, RAM) memory, or may be a non-volatile memory (non-volatile memory), such as at least one disk memory; optionally, at least one computer storage medium remote from the processor may be present.
In one embodiment, one or more instructions stored in a computer storage medium may be loaded and executed by the processor 1101 and the input interface 1102 to implement the corresponding steps of the methods described above in connection with the data processing method embodiments of fig. 1 and 3, and in a specific implementation, the one or more instructions in the computer storage medium are loaded and executed by the processor 1101 and the input interface 1102 as follows:
an input interface 1102, configured to obtain a code to be detected;
The processor 1101 is configured to perform semantic analysis on the code to be detected to obtain an abstract syntax tree corresponding to the code to be detected;
The processor 1101 is further configured to determine, from the code to be detected, a target character string based on an abstract syntax tree corresponding to the code to be detected, where a language type of the target character string is a first language type;
The processor 1101 is further configured to add an objective function call to an objective string in the code to be detected to generate an objective code; and the objective function is used for displaying the target character string in a second language type when the target code runs, wherein the second language type is the language type of the language environment in which the target code runs.
In one embodiment, the abstract syntax tree comprises a plurality of nodes, wherein father-son relations exist among the plurality of nodes, and one node in the plurality of nodes represents a syntax structure of the code to be detected;
the processor 1101 specifically performs the following operations when determining the target character string from the code to be detected based on the abstract syntax tree corresponding to the code to be detected:
Taking any node which is not traversed in the abstract syntax tree as a target node which is traversed currently;
if the target node represents a first character string with the language type being the first language type, determining whether the target node adds a target function call;
and if the target node does not add the target function call, determining the target character string based on the first character string.
In one embodiment, the processor 1101 determines whether the target node adds an objective function call by:
If the father node of the target node represents a function call and the brother node of the target node represents a target function, determining that the target node has added the target function call;
And if the father node of the target node does not represent the function call, or the father node of the target node represents the function call but the brother node of the target node does not represent the target function, determining that the target node does not add the target function call.
In one embodiment, if the target node does not add a target function call, the processor 1101 determines the target string based on the first string, specifically performs the following operations:
if the target node is not added with the target function call, determining whether a father node of the target node represents character string splicing;
If the father node of the target node does not represent string splicing, determining the first string as the target string;
If the father node of the target node represents string splicing, performing recursion operation of determining the target string from the father node of the target node to obtain a target subtree from the abstract syntax tree based on father-son relationships among all nodes in the abstract syntax tree, wherein the root node of the target subtree represents string splicing, and leaf nodes of the target subtree comprise the target node;
And determining the character string in the code to be detected, which is indicated by the target subtree, as the target character string.
In one embodiment, the processor 1101 performs, starting from a parent node of the target node, a recursive operation of determining the target string, so as to obtain the target subtree from the abstract syntax tree based on a parent-child relationship between nodes in the abstract syntax tree, and specifically performs the following operations:
sequentially determining whether one or more ancestor nodes of the initial node represent character string splicing or not by taking a father node of the target node as the initial node when the recursive operation starts to be executed until the target ancestor node is determined from the one or more ancestor nodes of the initial node and is taken as the termination node when the recursive operation stops, wherein the target ancestor node does not represent character string splicing;
And determining a target subtree comprising the target node from the abstract syntax tree by taking the ancestor node of the child nodes belonging to the termination node in one or more ancestor nodes of the initial node processed by the recursion operation as a root node of the target subtree.
In one embodiment, when the processor 1101 adds an objective function call to the objective string in the code to be detected to generate an objective code, the following operations are specifically performed:
Generating a target function call subtree corresponding to the target character string based on the target character string and the target function call;
If the target character string is the first character string, replacing the target node with the target function calling subtree to obtain a modified abstract syntax tree;
if the target character string is obtained based on the target subtree, replacing the target subtree with the target function calling subtree to obtain a modified abstract syntax tree;
And carrying out format conversion processing on the modified abstract syntax tree to obtain the target code.
In one embodiment, when the processor 1101 adds an objective function call to the objective string in the code to be detected to generate an objective code, the following operations are specifically performed:
Generating a target function call code corresponding to the target character string based on the target character string and the target function call;
And replacing the target character string in the code to be detected with the target function calling code to obtain the target code.
In one embodiment, the target string is obtained based on the target subtree, and the target string includes a string variable therein;
when the processor 1101 generates the target function call code corresponding to the target string based on the target string and the target function call, the following operations are specifically executed:
Splicing the leaf nodes of the target subtrees to obtain character strings to be replaced corresponding to the target character strings;
Replacing character string variables included in the character string to be replaced with the placeholder to obtain a target character string to be replaced;
and generating an objective function call code corresponding to the objective character string based on the objective character string to be replaced, the character string variable and the objective function call.
Embodiments of the present application provide a computer program product or computer program, the computer program product comprising a computer program stored in a computer storage medium; the processor of the data processing apparatus reads the computer program from the computer storage medium, and the processor executes the computer program, so that the data processing apparatus executes the above-described method embodiments as shown in fig. 1 and 3. The computer readable storage medium may be a magnetic disk, an optical disk, a Read-Only Memory (ROM), a random access Memory (Random Access Memory, RAM), or the like.
The foregoing is merely illustrative of the present application, and the present application is not limited thereto, and any person skilled in the art will readily recognize that variations or substitutions are within the scope of the present application. Therefore, the protection scope of the application is subject to the protection scope of the claims.

Claims (9)

1. A method of data processing, comprising:
Acquiring a code to be detected;
Carrying out semantic analysis on the code to be detected to obtain an abstract syntax tree corresponding to the code to be detected; the abstract syntax tree comprises a plurality of nodes, wherein father-son relations exist among the nodes, and one node in the nodes represents a syntax structure of the code to be detected;
Determining a target character string from the code to be detected based on an abstract syntax tree corresponding to the code to be detected, wherein the language type of the target character string is a first language type;
Adding an objective function call to an objective character string in the code to be detected to generate an objective code; the objective function is used for displaying the target character string in a second language type when the target code runs, wherein the second language type is the language type of the language environment in which the target code runs;
The determining, based on the abstract syntax tree corresponding to the code to be detected, a target character string from the code to be detected includes:
Taking any node which is not traversed in the abstract syntax tree as a target node which is traversed currently;
If the target node represents a first character string with the language type being the first language type, determining whether the target node adds a target function call; if the father node of the target node represents a function call and the brother node of the target node represents a target function, determining that the target node has added the target function call; if the father node of the target node does not represent the function call, or the father node of the target node represents the function call but the brother node of the target node does not represent the target function, determining that the target node does not add the target function call;
and if the target node does not add the target function call, determining the target character string based on the first character string.
2. The method of claim 1, wherein the determining the target string based on the first string if the target node does not add a target function call comprises:
if the target node is not added with the target function call, determining whether a father node of the target node represents character string splicing;
If the father node of the target node does not represent string splicing, determining the first string as the target string;
If the father node of the target node represents string splicing, performing recursion operation of determining the target string from the father node of the target node to obtain a target subtree from the abstract syntax tree based on father-son relationships among all nodes in the abstract syntax tree, wherein the root node of the target subtree represents string splicing, and leaf nodes of the target subtree comprise the target node;
And determining the character string in the code to be detected, which is indicated by the target subtree, as the target character string.
3. The method of claim 2, wherein performing a recursive operation of determining the target string from a parent node of the target node to obtain a target sub-tree from the abstract syntax tree based on parent-child relationships between nodes in the abstract syntax tree comprises:
sequentially determining whether one or more ancestor nodes of the initial node represent character string splicing or not by taking a father node of the target node as the initial node when the recursive operation starts to be executed until the target ancestor node is determined from the one or more ancestor nodes of the initial node and is taken as the termination node when the recursive operation stops, wherein the target ancestor node does not represent character string splicing;
And determining a target subtree comprising the target node from the abstract syntax tree by taking the ancestor node of the child nodes belonging to the termination node in one or more ancestor nodes of the initial node processed by the recursion operation as a root node of the target subtree.
4. The method of claim 2, wherein the generating object code by adding an object function call to the object string in the code to be detected comprises:
Generating a target function call subtree corresponding to the target character string based on the target character string and the target function call;
If the target character string is the first character string, replacing the target node with the target function calling subtree to obtain a modified abstract syntax tree;
If the target character string is obtained based on the target subtree, replacing the target subtree with the target function calling subtree to obtain a modified abstract syntax tree;
And carrying out format conversion processing on the modified abstract syntax tree to obtain the target code.
5. The method of claim 2, wherein the generating object code by adding an object function call to the object string in the code to be detected comprises:
Generating a target function call code corresponding to the target character string based on the target character string and the target function call;
And replacing the target character string in the code to be detected with the target function calling code to obtain the target code.
6. The method of claim 5, wherein the target string is derived based on the target subtree, and wherein the target string includes a string variable therein;
The generating the target function call code corresponding to the target character string based on the target character string and the target function call includes:
Splicing the leaf nodes of the target subtrees to obtain character strings to be replaced corresponding to the target character strings;
Replacing character string variables included in the character string to be replaced with the placeholder to obtain a target character string to be replaced;
and generating an objective function call code corresponding to the objective character string based on the objective character string to be replaced, the character string variable and the objective function call.
7. A data processing apparatus, comprising:
the acquisition unit is used for acquiring the code to be detected;
the processing unit is used for carrying out semantic analysis on the code to be detected to obtain an abstract syntax tree corresponding to the code to be detected; the abstract syntax tree comprises a plurality of nodes, wherein father-son relations exist among the nodes, and one node in the nodes represents a syntax structure of the code to be detected;
the processing unit is further configured to determine a target character string from the code to be detected based on an abstract syntax tree corresponding to the code to be detected, where a language type of the target character string is a first language type;
The processing unit is further used for adding an objective function call to the objective character string in the code to be detected to generate an objective code; the objective function is used for displaying the target character string in a second language type when the target code runs, wherein the second language type is the language type of the language environment in which the target code runs;
The processing unit is used for determining a target character string from the code to be detected based on an abstract syntax tree corresponding to the code to be detected, and specifically is used for taking any node which is not traversed in the abstract syntax tree as a target node which is traversed currently; if the target node represents a first character string with the language type being the first language type, determining whether the target node adds a target function call, wherein if the father node of the target node represents the function call and the brother node of the target node represents the target function, determining that the target node has added the target function call; if the father node of the target node does not represent the function call, or the father node of the target node represents the function call but the brother node of the target node does not represent the target function, determining that the target node does not add the target function call; and if the target node does not add the target function call, determining the target character string based on the first character string.
8. A data processing device, the data processing device comprising an input interface and an output interface, further comprising:
A processor adapted to implement one or more instructions; and
A computer storage medium storing one or more instructions adapted to be loaded by the processor and to perform the data processing method of any one of claims 1-6.
9. A computer program product comprising computer programs/instructions which, when executed by a processor, implement the steps of the data processing method according to any of claims 1-6.
CN202111251532.9A 2021-10-26 Data processing method, apparatus, device, storage medium and computer program product Active CN113971028B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111251532.9A CN113971028B (en) 2021-10-26 Data processing method, apparatus, device, storage medium and computer program product

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111251532.9A CN113971028B (en) 2021-10-26 Data processing method, apparatus, device, storage medium and computer program product

Publications (2)

Publication Number Publication Date
CN113971028A CN113971028A (en) 2022-01-25
CN113971028B true CN113971028B (en) 2024-07-09

Family

ID=

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111831384A (en) * 2020-07-20 2020-10-27 北京百度网讯科技有限公司 Language switching method and device, equipment and storage medium

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111831384A (en) * 2020-07-20 2020-10-27 北京百度网讯科技有限公司 Language switching method and device, equipment and storage medium

Similar Documents

Publication Publication Date Title
CN111708539B (en) Application program code conversion method and device, electronic equipment and storage medium
CN106919434B (en) Code generation method and device
WO2018082562A1 (en) Method and device for compiling page data and rendering page, and storage medium
CN110580147B (en) Application program development method and device
US10552534B2 (en) Contraction aware parsing system for domain-specific languages
US20130019224A1 (en) Systems and methods for verifying model equivalence
CN106796525B (en) On-demand loading dynamic script language codes are to reduce memory use
CN104407863A (en) Abstract control model programming device and method
CN110727429B (en) Front-end page generation method, device and equipment
CN108920566B (en) Method, device and equipment for operating SQLite database
CN114153459A (en) Interface document generation method and device
CN112506602A (en) Page generation method and device, electronic equipment and computer readable medium
CN111309332A (en) File content on-demand loading method and device, electronic equipment and storage medium
CN114217789A (en) Function component expansion method, device, equipment, storage medium and program product
Zhao et al. Pattern-based design evolution using graph transformation
CN113971028B (en) Data processing method, apparatus, device, storage medium and computer program product
CN111061466A (en) Automatic conversion method, system, terminal and medium of behavior control scripting language
CN116610558A (en) Code detection method, device, electronic equipment and computer readable storage medium
CN116257714A (en) Method, device, computer equipment and storage medium for generating cascading style sheet
CN111273913B (en) Method and device for outputting application program interface data represented by specifications
CN114449063A (en) Message processing method, device and equipment
CN110941429B (en) Method, device and equipment for processing business script of webpage
CN113971028A (en) Data processing method, device, equipment, storage medium and computer program product
CN113448852A (en) Test case obtaining method and device, electronic equipment and storage medium
CN112241505A (en) Page updating method, page updating device, medium and electronic equipment

Legal Events

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