CN113971028A - Data processing method, device, equipment, storage medium and computer program product - Google Patents

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

Info

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

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • G06F8/427Parsing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/76Adapting program code to run in a different environment; Porting

Landscapes

  • Engineering & Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Machine Translation (AREA)

Abstract

The application discloses a data processing method, related embodiments of which relate to the technical field of computers and can be applied to scenes such as cloud technology, artificial intelligence, intelligent traffic, driving assistance and the like. The method comprises the following steps: determining a target character string with a language type of a first language type from the codes to be detected based on semantic analysis of the codes to be detected to obtain an abstract syntax tree corresponding to the codes to be detected; adding a target function call to a target character string in a code to be detected to generate a target code; and 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 where the target code runs. The method and the device can analyze and modify the code to be detected, so that when the modified target code runs, the target character string can be displayed according to the language type of the language environment in which the target code runs, effective interaction with a user in the language environment can be realized, and user experience is improved.

Description

Data processing method, device, equipment, storage medium and computer program product
Technical Field
The present application relates to the field of computer technologies, and in particular, to a data processing method, apparatus, device, storage medium, and computer program product.
Background
When software, a webpage, an applet or the like is developed, internationalization processing is generally required to be performed on code, so that the code can be matched with a language environment where the code runs, namely, when the code runs, a character string used for interacting with a user in the code can be displayed in a language type of the language environment where the code runs, and effective interaction with the user in the language environment is realized. For example, if the language type of the language environment in which the code runs is chinese, it is required that a character string in the code for interacting with a user can be displayed in chinese; and if the language type of the language environment in which the code runs is English, the character string used for interacting with the user in the code is required to be displayed in English. However, when a developer writes code in an Integrated Development Environment (IDE), international processing on the code is sometimes ignored, which results in code defects, so that the code cannot be matched with a language Environment in which the code runs, that is, when the code runs, a character string in the code for interacting with a user cannot be displayed in a language type of the language Environment in which the code runs, and effective interaction with the user in the language Environment cannot be realized, so that user experience is reduced.
Disclosure of Invention
The embodiment of the application provides a data processing method, a data processing device, a data processing apparatus, a data processing storage medium and a computer program product, which can analyze and modify a code to be detected, so that when a target code obtained after modification runs, a target character string can be displayed according to a language type of a language environment in which the target code runs, effective interaction with a user in the language environment can be realized, and 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;
performing 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 the 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 a target function call to the target character string in the code to be detected to generate a 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 where 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 a 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 the 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 configured to add a target function call to the target character string in the code to be detected to generate a 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 where the target code runs.
In one aspect, an embodiment of the present application provides a data processing device, where the data processing device includes an input interface and an output interface, and further includes:
a processor adapted to implement one or more instructions; and the number of the first and second groups,
a computer storage medium having stored thereon one or more instructions adapted to be loaded by the processor and to execute the above-described data processing method.
In one aspect, an embodiment of the present application provides a computer storage medium, where computer program instructions are stored in the computer storage medium, and when the computer program instructions are executed by a processor, the computer storage medium is configured to execute the data processing method.
In one aspect, embodiments of the present application provide a computer program product or a computer program, where the computer program product includes a computer program, and the computer program is 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 data processing method described above.
In the embodiment of the application, after the data processing device obtains the code to be detected, semantic analysis can be performed on the code to be detected to obtain an abstract syntax tree corresponding to the code to be detected, a target character string with a language type being 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 is further added to the target character string in the code to be detected to call to generate a target code; 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 where the target code runs. Internationalized processing of the code to be detected can be realized based on semantic analysis of the code to be detected, that is, a target character string with a language type of a first language type is determined from the code to be detected based on the 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 where the target code runs, namely when the target code runs, the target character string can be displayed according to the language type of the language environment where the target code runs, effective interaction with a user in the language environment can be achieved, and 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 needed to be used in the description of the embodiments or the prior art will be briefly introduced below, it is obvious that the drawings in the following description are only some embodiments of the present application, and for a developer in the field, other drawings can be obtained according to the drawings without creative efforts.
Fig. 1 is a schematic flowchart of a data processing method provided in 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 schematic flow chart diagram of another data processing method provided in the embodiments of the present application;
FIG. 4a is a schematic diagram of determining a target character string according to an embodiment of the present application;
FIG. 4b is a schematic diagram of another specific target character string provided in the embodiment of the present application;
FIG. 5 is a diagram illustrating a target sub-tree according to an embodiment of the present disclosure;
FIG. 6a is a diagram of a modified abstract syntax tree according to an embodiment of the present application;
FIG. 6b is a diagram of another modified abstract syntax tree provided by an embodiment of the present application;
FIG. 7 is a schematic flowchart of generating object code according to an embodiment of the present application;
FIG. 8 is a schematic flow chart of another method for generating object code according to an embodiment of the present application;
fig. 9a is a schematic diagram illustrating that a code detection tool eslin prompts a target character string according to an embodiment of the present application;
FIG. 9b is a schematic diagram of another code detection tool ESLint prompting a target character string according to the embodiment of the present application;
fig. 10 is a schematic structural 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 technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
In order to achieve effective interaction between a code and a user in any language environment when the code runs in any language environment and improve user experience, a data processing scheme is provided in an embodiment of the present application, and a target character string with a language type of a 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 is further added to the target character string in the code to be detected to call and generate a target code, where the target function is used to display 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 a target character string is written, the target character string is a character string which is used for interacting 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 the character string determined from an annotation part of the code to be detected, the main body part of the code to be detected is an operable part of the code to be detected, the annotation part of the code to be detected is annotation content used for explaining the code to be detected, and the annotation 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 operates is english, the target character string is displayed in english when the target code operates in the language environment.
In a specific implementation, the data processing scheme may be executed by a data processing device, and the data processing device may be a terminal device or a server; terminal devices herein may include, but are not limited to: computers, smart phones, tablet computers, notebook computers, intelligent voice interaction devices, intelligent household 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 basic cloud computing services such as a cloud service, a cloud database, cloud computing, a cloud function, cloud storage, a web service, cloud communication, a middleware service, a domain name service, a security service, a Content Delivery Network (CDN), a big data and artificial intelligence platform, and the like.
Based on the data processing scheme, the embodiment of the application provides a data processing method. Referring to fig. 1, a schematic 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:
and 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 can be written in programming languages such as C language, JavaScript, Python and the like; the code to be detected comprises an operable main body part; 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, which may facilitate understanding of the code to be detected by a developer.
S102, performing 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 for describing the code syntax logic of the code to be detected, namely a structure for describing the code syntax logic of the main part of the code to be detected. An Abstract Syntax Tree (AST), or simply Syntax Tree (Syntax Tree), is an Abstract representation of the Syntax structure of the source code, and represents the Syntax structure of the programming language in the form of a Tree, where each node on the Tree represents a Syntax structure in the source code, and the Abstract Syntax Tree has the relevant features of the Tree. The abstract syntax tree corresponding to the code to be detected 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. For example, if the main part of the code to be detected is var desc written in JavaScript ═ hello, "and the comment part 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 be as shown in fig. 2a, including 3 nodes, where, in the 3 nodes, node 1 represents a variable declaration, node 2 represents a variable name desc, 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 part of the code to be detected is var desc written in JavaScript ═ selected "+ num +" person, "num is a predefined string variable, and the comment part of the code to be detected is" declare a variable named desc, indicating that several persons have been selected ", the abstract syntax tree corresponding to the code to be detected may be as shown in fig. 2b, and include 7 nodes, where, of the 7 nodes, node 1 represents the variable declaration, node 2 represents the variable name desc, node 3 and node 4 all represent string concatenations, specifically, a concatenation character" + ", node 5 represents a string" person, "node 6 represents the string" selected, "node 7 represents the string variable num, and string concatenation +, string" selected, "string variable num, and string" person "constitute the initial value of the variable desc.
In one embodiment, the performing, by the data processing device, semantic analysis on the code to be detected to obtain an abstract syntax tree corresponding to the code to be detected 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 the main portion of the code to be detected, and obtain the abstract syntax tree corresponding to the code to be detected according to the code syntax logic of the main portion of the code to be detected. Optionally, for the code to be detected written in different programming languages, the adopted code detection tools may be different, for example, if the code to be detected is written in JavaScript, the code detection tool eslin may be adopted 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 strings used for interacting with the user in the code to be detected refer to: when the code to be detected runs, the character string which needs to be displayed in the running result page of the code to be detected and can be directly interacted with a user is required; the character strings used for interacting with the user in the codes to be detected are written in the main body part of the codes to be detected, so that the target character strings determined from the codes to be detected are the character strings determined from the main body part of the codes to be detected and are not the character strings determined from the annotation part of the codes 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 part of the code to be detected, it can also be known that the target character string determined from the code to be detected is a character string determined from the main 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 explanation, the embodiments of the present application are described below with the codes to be detected without including the comment portion. For example, if the code to be detected is a code corresponding to a product detail page of the product a, if the name of the product a is "product a", the category of the product a is "food", the specification of the product a is "300 g", and the selling price of the product a is "35 yuan", which need to be displayed in the product detail page of the product a, so that the user can know specific parameters of the product a, in this case, the character string for interacting with the user in the code to be detected may include "product a", "food", "300 g", and "35 yuan".
Further, the data processing device determines a target character string from the code to be detected based on the abstract syntax tree corresponding to the code to be detected as follows: and in the character strings used for interacting with the user in the code to be detected, the character strings called by the target function are not added. 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, 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 can be used. Optionally, the target function may be developed by a developer, or may be some commonly used functions that can display a character string added with a target function call in the code in a language type of a language environment in which the code runs, for example, a weLANG function. The language environment in which 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 in which 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 in which the code runs; for example, if the code runs 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 operates in the code operating device a is chinese, and the language type of the language environment in which the code operates in the code operating device B is english.
For example, if the character strings used for interacting with the user in the code to be detected include "commodity a", "food", "300 g", and "35 yuan", where the character strings "commodity a", "food" are not added with the target function call, the target character strings are "commodity a" and "food"; 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 character string determined is hello if the target function call is not added to the character string; for another example, if the code to be detected is var desc ═ selected "+ num +" person ", where num is a predefined string variable, the string used for interacting with the user in the code to be detected is" selected "+ num +" person ", and the string is not added with the target function call, then the determined target string is" selected "+ num +" person ".
And S104, adding a target function call to the target character string in the code to be detected to generate a target code.
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 where the target code runs. In the character strings used for interacting with the user in the code to be detected, the target character string which is not added with the target function call is added with the target function call, and the target character string can be displayed according to the language type of the language environment where the target code is operated through the operation of the target function.
In the embodiment of the application, after the data processing device obtains the code to be detected, semantic analysis can be performed on the code to be detected to obtain an abstract syntax tree corresponding to the code to be detected, a target character string with a language type being 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 is further added to the target character string in the code to be detected to call to generate a target code; 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 where the target code runs. Internationalized processing of the code to be detected can be realized based on semantic analysis of the code to be detected, that is, a target character string with a language type of a first language type is determined from the code to be detected based on the 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 where the target code runs, namely when the target code runs, the target character string can be displayed according to the language type of the language environment where the target code runs, effective interaction with a user in the language environment can be achieved, and user experience is improved.
Based on the above method embodiments, the present application provides another data processing method. Referring to fig. 3, a schematic flow chart of another data processing method provided in the 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, acquiring the code to be detected.
S302, performing 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 of the nodes represents a syntax structure of the code to be detected. Step S301 is the same as step S201, and step S302 is the same as step S201, which are not repeated herein.
And S303, taking any node which is not traversed in the abstract syntax tree as a currently traversed target node.
S304, if the target node represents a first character string with the language type being the first language type, determining whether the target node is added with a 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 steps S303 to S305, as shown in fig. 4a, for a schematic diagram of determining a target character string provided in the embodiment of the present application, the data processing device uses any node in the abstract syntax tree that is not traversed as a currently traversed target node; if the target node does not represent the first character string with the language type being the first language type, 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 (namely determining whether the abstract syntax tree is traversed or not, and if the abstract syntax tree is not traversed, repeatedly executing a relevant process of taking any node which is not traversed in the abstract syntax tree as the currently traversed target node); if the target node represents a first character string with the language type being the first language type, determining whether the target node is added with a target function call; if the target node is added with the target function call, the target node is used as a traversed node, and the target node is determined again under the condition that the abstract syntax tree is not traversed; and if the target node does not add the target function call, determining a target character string based on the first character string.
In an embodiment, when the data processing device traverses the abstract syntax tree, traversal manners such as forward traversal, middle traversal, or backward traversal may be adopted, and the data processing device performs forward traversal on the abstract syntax tree in the following description of the embodiment of the present application.
In one embodiment, the first character string is a syntactic structure represented by the target node, and the target node does not represent the first character string with the language type of the first language type means that: the target node does not represent the character string or the target node represents the 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 the language type being a first language type, and the method comprises the following steps: the target node represents a character string, and the language type of the first character string represented by the target node is the first language type. The data processing device 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 is added with the target function call; and if the parent node of the target node does not represent the function call, or the parent node of the target node represents the function call but the sibling node of the target node does not represent the target function, determining that the target function call is not added to the target node.
In a specific implementation, as shown in fig. 4b, which is another schematic diagram for determining a target character string provided in the embodiment of the present application, the data processing device uses any node in the abstract syntax tree that is not traversed 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 a traversed node, and the target node is determined again under the condition that the abstract syntax tree is not traversed; if the target node represents the character string, taking the character string represented by the target node as a first character string, and determining whether the language type of the first character string is a first language type; if the language type of the first character string is not the first language type, the target node is used as a traversed node, the target node is determined again under the condition that the abstract syntax tree is not traversed, and if the language type of the first character string is the first language type, whether a father node of the target node represents function call is determined; if the father node of the target node does not represent the function call, determining that the target node is not added with 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 adds the target function call; if the target node is added with the target function call, the target node is used as a traversed node, and the target node is determined again under the condition that the abstract syntax tree is not traversed; and 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 device determines a target character string based on the first character string, which may include: 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 character string splicing, determining the first character string as a target character string; if the father node of the target node represents character string splicing, performing recursive operation for determining the target character string from the father node of the target node to obtain a target sub-tree from the abstract syntax tree based on the parent-child relationship among the nodes in the abstract syntax tree, wherein the root node of the target sub-tree represents character string splicing, and the leaf nodes of the target sub-tree comprise target nodes; and determining character strings in the codes to be detected, which are indicated by the target subtree, as target character strings.
In a specific implementation, the data processing device, starting from a parent node of the target node, performs a recursive operation of determining the target character string to obtain the target sub-tree from the abstract syntax tree based on parent-child relationships between nodes in the abstract syntax tree, and may include: taking a father node of the target node as an initial node when the recursive operation starts to be executed, and sequentially determining whether one or more ancestor nodes of the initial node represent character string splicing or not 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 recursive operation stops, wherein the target ancestor node does not represent character string splicing; and determining the target sub-tree comprising the target node from the abstract syntax tree by taking the ancestor node of the child node belonging to the termination node in one or more ancestor nodes of the initial node processed by the recursive operation as the root node of the target sub-tree. Wherein, the ancestor node of the initial node refers to: nodes on the branches passed from the root node of the abstract syntax tree to the initial node; the determined target ancestor node refers to: on a branch from the initial node to a root node of the abstract syntax tree, the first node does not represent an ancestor node for splicing the character strings; the determined root node of the target subtree refers to: the child nodes of the target ancestor node on the branch from the initial node to the root node of the abstract syntax tree, that is, the plurality of child nodes of the target ancestor node may exist in the abstract syntax tree, and the child node of the target ancestor node determined as the root node of the target subtree is the node on the branch from the initial node to the root node of the abstract syntax tree.
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, and if the first language type is set as chinese and the abstract syntax tree is subjected to front-end traversal, the first target node determined by the data processing device is node 1; if the node 1 does not represent the character string, taking the node 1 as a traversed node, and re-determining a second target node as a node 2; if the node 2 does not represent the character string, taking the node 2 as a traversed node, and re-determining a third target node as a node 3; if the node 3 represents the character string, taking the character string 'hello' represented by the node 3 as a first character string, and determining whether the language type of the first character string is Chinese; determining whether a father node of the node 3, namely the node 1 represents character string splicing or not because the language type of the first character string 'hello' is Chinese; since node 1 does not represent a string splice, the first string "hello" is determined to be the target string.
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, and if the first language type is set as chinese and the abstract syntax tree is subjected to front-end traversal, the first target node determined by the data processing device is node 1; if the node 1 does not represent the character string, taking the node 1 as a traversed node, and re-determining a second target node as a node 2; if the node 2 does not represent the character string, taking the node 2 as a traversed node, and re-determining a third target node as a node 3; if the node 3 does not represent the character string, taking the node 3 as a traversed node, and re-determining a fourth target node as a node 4; if the node 4 does not represent the character string, taking the node 4 as a traversed node, and re-determining a fifth target node as a node 6; if the node 6 represents the 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 string "selected" is Chinese, it is determined whether the parent node of node 6, i.e., node 4, represents string concatenation; because the node 4 represents character string splicing, the node 4 is used as an initial node when the recursive operation starts to be executed, whether one or more ancestor nodes (the node 3 and the node 1) of the node 4 represent character string splicing is sequentially determined until a target ancestor node is determined from the node 3 and the node 1 and is used as a node 1 which is used as a termination node when the recursive operation stops; taking one or more ancestor nodes (namely, the node 3 and the node 1) of the initial node processed by the recursive operation, and an ancestor node (node 3) of a child node belonging to the terminal node (node 1) as a root node of a target sub-tree, determining the target sub-tree comprising the target node from the abstract syntax tree, wherein the determined target sub-tree can be marked by 501 in fig. 5, and the target sub-tree comprises the node 3, the node 4, the node 5, the node 6 and the node 7. Further, the data processing equipment determines the character string in the code to be detected, which is indicated by the target subtree, as a target character string; namely, the character string 'selected' + num + 'person' in the code to be detected indicated by the target sub-tree is determined as the target character string.
In the 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 being the node 1, determines first ancestor node of the node 4, namely father node of the node 4, namely the node 3 represents character string splicing or not; because the node 3 represents the string concatenation, it is determined whether the second ancestor node of the node 4, i.e., the father node of the node 3, i.e., the node 1, represents the string concatenation; since node 1 does not represent a string splice, the target ancestor node is determined to be node 1.
And S306, adding a target function call to the target character string in the code to be detected to generate a target code.
In one embodiment, the data processing device adds a target function call to a target character string in the code to be detected to generate the target code, and may include: generating a target function call sub-tree 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 call sub-tree 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 call subtree to obtain a modified abstract syntax tree; and carrying out format conversion processing on the modified abstract syntax tree to obtain a target code. Further, when the target character string is obtained based on the target sub-tree and the target character string includes the character string variable, the data processing device generates a target function call sub-tree corresponding to the target character string based on the target character string and the target function call, which may include: splicing the leaf nodes of the target subtree to obtain a character string to be replaced corresponding to the target character string; replacing character string variables included in the character string to be replaced by the placeholders to obtain a target character string to be replaced; and generating a target function call sub-tree 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 splices the leaf nodes of the target sub-tree to obtain a character string to be replaced corresponding to the target character string, and the splicing process may include: and performing preorder traversal on the target subtree, sequentially determining leaf nodes of the target subtree, and splicing the sequentially determined leaf nodes of the target subtree to obtain a character string to be replaced corresponding to the target character string. Optionally, the leaf nodes of the target subtrees determined in sequence may be stored in a list, and the leaf nodes of the target subtrees stored in the list are spliced to obtain the character string to be replaced corresponding to the target character string.
For example, as shown in fig. 6a, a schematic diagram of a modified abstract syntax tree provided in the embodiment of the present application is shown; if the code to be detected is var desc ═ hello, the abstract syntax tree is marked as 601, if the first language type is set as Chinese, the target function is a weLANG function, and the abstract syntax tree is traversed in the front sequence; 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", that is, the target character string is the first character string, at this time, the data processing apparatus may use the target character string as a parameter of the target function, and generate a target function call sub-tree corresponding to the target character string based on the target character string and the target function call, where the obtained target function call sub-tree may be as indicated by a reference numeral 602 and includes 3 nodes, where the 3 nodes respectively represent a function call, a target function weLANG, and a target character string "hello", where the target character string "hello" is a parameter of the target function, at this time, the target node is replaced by the target function call sub-tree, and the obtained modified abstract syntax tree may be as indicated by a reference numeral 603. Further, the data processing device may perform format conversion processing on the modified abstract syntax tree, and obtain the target code var desc ═ weLANG ("hello").
For another example, as shown in fig. 6b, another schematic diagram of the modified abstract syntax tree provided in the embodiment of the present application is shown; 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 as Chinese, the target function is a weLANG function, and the abstract syntax tree is traversed in a front sequence; then, in this case, the determined target character string is "selected" + num + "person" based on the first character string ("selected") represented by the target node (node 6), and the determined target sub-tree is shown as 611 marker; the determined target character string comprises a character string variable num, namely the target character string is obtained based on the target subtree and comprises the character string variable; then, the data processing device may perform a forward traversal on the target sub-tree, sequentially determine leaf nodes of the target sub-tree, sequentially include the node 6, the node 7, and the node 5, and perform a splicing process on the sequentially determined leaf nodes of the target sub-tree to obtain a to-be-replaced character string "selected num persons" corresponding to the target character string; then replacing a character string variable num included in the character string 'selected num person' to be replaced by the placeholder% s to obtain a target character string 'selected% s person' to be replaced; further, the data processing device may use the target character string to be replaced and the character string variable as parameters of a target function, respectively, to generate a target function call sub-tree corresponding to the target character string based on the target character string to be replaced, the character string variable and the target function call, where the obtained target function call sub-tree may be as indicated by 612 notation, and includes 4 nodes, where the 4 nodes represent a function call, a target function weLANG, a target character string to be replaced, "selected% s person", and a character string variable num, respectively, where the target character string to be replaced "selected% s person" and the character string variable num are parameters of the target function, at this time, the target sub-tree is replaced with the target function call sub-tree, and the obtained modified abstract syntax tree may be as indicated by 613 notation. Further, the data processing device may perform format conversion processing on the modified abstract syntax tree, and obtain the target code var desc ═ weLANG ("co-selected% s person", num).
As shown in fig. 7, which is a schematic diagram of generating an object code provided in the embodiment of the present application, a data processing device may obtain a code to be detected; then, performing 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 a language type being a first language type from the codes to be detected based on the abstract syntax tree corresponding to the codes to be detected; generating a target function call sub-tree corresponding to the target character string based on the target character string and the target function call, and modifying the abstract syntax tree based on the target function call sub-tree to obtain a modified abstract syntax tree; and carrying out format conversion processing on the modified abstract syntax tree to obtain a target code.
In one embodiment, the data processing device adds a target function call to a target character string in the code to be detected to generate the target code, and may include: generating a target function calling code corresponding to the target character string based on the target character string and the target function calling; and replacing the target character string in the code to be detected with a target function calling code to obtain a target code. Further, if the target character string is obtained based on the target sub-tree, and the target character string includes a character string variable; the data processing device generates a target function call code corresponding to the target character string based on the target character string and the target function call, and may include: splicing the leaf nodes of the target subtree to obtain a character string to be replaced corresponding to the target character string; replacing character string variables included in the character string to be replaced by the placeholders to obtain a target character string to be replaced; and generating a target function calling code corresponding to the target character string based on the target character string to be replaced, the character string variable and the target function calling. In a specific implementation, the data processing device may first determine whether the target character string is obtained based on the target sub-tree, and if the target character string is obtained based on the target sub-tree, the data processing device may perform splicing processing on leaf nodes of the target sub-tree to obtain a to-be-replaced character string corresponding to the target character string; further, if the target character string includes a character string variable, replacing the character string variable included in the character string to be replaced with a placeholder to obtain the target character string to be replaced, and if the target character string does not include the character string variable, determining the character string to be replaced as the target character string to be replaced; and then generating a target function calling code corresponding to the target character string based on the target character string to be replaced, the character string variable and the target function calling.
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 as chinese, the target function is the weLANG function, and the abstract syntax tree is traversed in the front order; then, in this case, if the target character string is "hello" determined based on the first character string ("hello") represented by the target node (node 3), the data processing apparatus may generate a target function call code corresponding to the target character string as a parameter of the target function, based on the target character string and the target function call, as weLANG; further, the data processing device replaces the target character string "hello" in the code to be detected with the target function calling code, and the obtained target code var desc is weLANG.
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, and if the first language type is set to be chinese, the target function is the weLANG function, and the abstract syntax tree is traversed in the front order; then, in this case, if the target character string determined based on the first character string ("selected") represented by the target node (node 6) is "selected" + num + "man", the target character string is obtained based on the target sub-tree, and the target character string includes the character string variable num, the data processing device may perform a splicing process on leaf nodes of the target sub-tree to obtain a character string "selected num man" to be replaced corresponding to the target character string; then replacing a character string variable num included in the character string 'selected num person' to be replaced by the placeholder% s to obtain a target character string 'selected% s person' to be replaced; further, the data processing device may use the target character string to be replaced and the character string variable as parameters of the target function, respectively, to generate 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, and the obtained target function call code is weLANG ("co-select% s person", num); further, the data processing device replaces the target character string of the code to be detected, namely ' selected ' + num + ' person ', with the target function calling code, and the obtained target code var desc is weLANG (' co-selected% s person ', num ').
Further, as shown in fig. 8, for another schematic flow chart of generating a target code provided by the present application, the data processing device may obtain a code to be detected; then, performing 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 of the current traversal; if the target node does not represent the first character string with the language type being the first language type, the target node is used as a traversed node, and the target node is determined again under the condition that the abstract syntax tree is not traversed completely; if the target node represents a first character string with the language type being the first language type, determining whether the target node is added with a target function call; if the target node is added with the target function call, the target node is used as a traversed node, and the target node is determined again 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, then 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 completely; and then, based on the re-determined target node, re-determining the target character string, and adding a target function call to the re-determined target character string to repeatedly update the code to be detected until the abstract syntax tree is traversed completely. Further, when the data processing equipment adds a target function call to the re-determined target character string to repeatedly update the code to be detected, if the re-determined target character string is the same as a certain target character string determined historically, the re-determined target node is used as a traversed node, and the target node is re-determined under the condition that the abstract syntax tree is not traversed completely; and if the re-determined target character string is different from any one of the historically determined target character strings, adding a target function call to the re-determined target character string to repeatedly update the code to be detected.
In an embodiment, after the data processing device finishes updating the code to be detected, that is, after all the character strings of which the language type is the first language type and to which the target function call is not added in the code to be detected are added with the target function call, the finally obtained target code can be output. 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 character strings to which the target function call is added via the data processing apparatus may be prompted so that the developer can know which character strings are modified. Optionally, corresponding functions of the data processing method provided in the embodiment of the present application may be integrated into a code detection tool, for example, the code detection tool eslin 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 using the code detection tool eslin to obtain an abstract syntax tree corresponding to the code to be detected; determining a target character string with a language type being a first language type from the codes to be detected based on the abstract syntax tree corresponding to the codes to be detected; adding a target function call to a target character string in a code to be detected to generate a target code; and outputting the finally obtained object code, for example, outputting in an integrated development environment and displaying. Optionally, the string to which the target function call is added via the data processing device may be prompted to enable the developer to know which strings have been modified.
Optionally, part of functions of the data processing method provided in the embodiment of the present application may also be integrated into a code detection tool, for example, the data processing method may be integrated into an eslin for a code to be detected written in JavaScript, so that semantic analysis may be performed on the code to be detected by the eslin to obtain an abstract syntax tree corresponding to the code to be detected; and determining a target character string with the language type being the first language type from the codes to be detected based on the abstract syntax tree corresponding to the codes 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 the prompt of the obtained target character string can be given in a prompt message mode. For example, when a developer writes a code in an integrated development environment, the code detection tool eslin may be installed and configured with a check rule, so that the code detection tool eslin may obtain the code written by the developer in real time, use the code as a code to be detected, analyze the code written by the developer in real time, and prompt an 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 eslin provided in the embodiment of the present application is provided, where the prompt of the obtained target character string may be given in a prompt information manner, for example, please use a webang package for "detecting a chinese case". Optionally, the developer may also globally install a code detection tool eslin in the integrated development environment and configure a check rule, so that the code detection tool may obtain a code file to be checked, which is specified by the developer in a command line, and take a code in the code file as a code to be detected, so as to analyze a code in the code file, and prompt an obtained target character string in the integrated output environment; fig. 9b is a schematic diagram of another code detection tool eslin provided for the embodiment of the present application to prompt a target character string, where the prompt for the obtained target character string may be given by a prompt message, for example, the prompt may be "chinese language case is detected, and webang is used for wrapping".
In the embodiment of the application, after the data processing device obtains the code to be detected, semantic analysis can be performed 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 currently traversed target node, if the target node represents a first character string with a language type of a first language type, whether the target node adds a target function call or not 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 further the target function call is 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, and the second language type is the language type of the language environment where the target code runs. Determining a target character string which is not added with target function call and has a language type of a first language type from a code to be detected based on an abstract syntax tree, and further adding a target function call 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 where the target code runs, namely when the target code runs, the target character string can be displayed according to the language type of the language environment where the target code runs, effective interaction with a user in the language environment can be achieved, and user experience is improved.
Based on the above method embodiments, the present application provides a data processing apparatus. Referring to fig. 10, a schematic structural diagram of a data processing apparatus according to an embodiment of the present disclosure is shown, where the data processing apparatus 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 to obtain an abstract syntax tree corresponding to the code to be detected;
the processing unit 1002 is further configured to determine a target character string from the code to be detected based on the 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 1002 is further configured to add a target function call to a target character string in the code to be detected to generate a 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 where the target code runs.
In one embodiment, the abstract syntax tree includes a plurality of nodes, parent-child relationships exist among the nodes, and one of the nodes represents a syntax structure of the code to be detected;
when the processing unit 1002 determines a target character string from the code to be detected based on the abstract syntax tree corresponding to the code to be detected, the following operations are specifically performed:
taking any node which is not traversed in the abstract syntax tree as a target node of current traversal;
if the target node represents a first character string with a language type of a first language type, determining whether the target node is added with a target function call;
and if the target node is not added with a target function call, determining the target character string based on the first character string.
In an embodiment, when the processing unit 1002 determines whether the target node adds the target function call, the following operation is 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 is added with the target function call;
and if the parent node of the target node does not represent the function call, or the parent node of the target node represents the function call but the sibling node of the target node does not represent the target function, determining that the target node does not add the target function call.
In an embodiment, if the target node does not add a target function call, when determining the target character string based on the first character string, the processing unit 1002 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 character string splicing, determining the first character string as the target character string;
if the parent node of the target node represents character string splicing, performing a recursive operation for determining the target character string from the parent node of the target node, so as to obtain a target sub-tree from the abstract syntax tree based on a parent-child relationship between nodes in the abstract syntax tree, wherein a root node of the target sub-tree represents character string splicing, and leaf nodes of the target sub-tree 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 a recursive operation of determining the target character string starting from the parent node of the target node, so as to obtain the target sub-tree from the abstract syntax tree based on the parent-child relationship between the nodes in the abstract syntax tree, and specifically performs the following operations:
taking a father node of the target node as an initial node when the recursive operation starts to be executed, and sequentially determining whether one or more ancestor nodes of the initial node represent character string splicing or not until a 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 recursive operation stops, wherein the target ancestor node does not represent character string splicing;
and determining a target sub-tree comprising the target node from the abstract syntax tree by taking one or more ancestor nodes of the initial node processed by the recursive operation and an ancestor node of a child node belonging to the termination node as a root node of the target sub-tree.
In an embodiment, when the processing unit 1002 adds a target function call to the target character string in the code to be detected to generate a target code, the following operations are specifically performed:
generating a target function call sub-tree 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 call sub-tree 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 call 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 an embodiment, when the processing unit 1002 adds a target function call to the target character string in the code to be detected to generate a target code, the following operations are specifically performed:
generating a target function calling code corresponding to the target character string based on the target character string and the target function calling;
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 character string is obtained based on the target sub-tree, and the target character string includes a character string variable;
when the processing unit 1002 generates a target function call code corresponding to the target character string based on the target character string and the target function call, the following operations are specifically performed:
splicing the leaf nodes of the target subtree to obtain a character string to be replaced corresponding to the target character string;
replacing character string variables included in the character string to be replaced with placeholders to obtain a target character string to be replaced;
and generating a target function calling code corresponding to the target character string based on the target character string to be replaced, the character string variable and the target function calling.
According to an embodiment of the present application, the steps involved in the data processing methods shown in fig. 1 and 3 may be performed by units in the data processing apparatus shown in fig. 10. For example, step S101 shown in fig. 1 may be executed by the acquisition unit 1001 in the data processing apparatus shown in fig. 10; steps S102 to S104 shown in fig. 1 may be executed by the processing unit 1002 in the data processing apparatus shown in fig. 10. For another example, step S301 shown in fig. 3 may be executed by the acquisition unit 1001 in the data processing apparatus shown in fig. 10; steps S302 to S306 shown in fig. 3 can be executed by the processing unit 1002 in the data processing apparatus shown in fig. 10.
According to another embodiment of the present application, the units in the data processing apparatus shown in fig. 10 may be respectively or entirely combined into one or several other units to form one or several other units, or some unit(s) therein may be further split into multiple functionally smaller units to form one or several other units, which may achieve the same operation without affecting the achievement of the technical effect of the embodiment of the present application. The units are divided based on logic functions, and in practical application, the functions of one unit can be realized by a plurality of units, or the functions of a plurality of units can be realized by one unit. In other embodiments of the present application, the data processing apparatus based on logical function division may also include other units, and in practical applications, the functions may also be implemented by being assisted by other units, and may be implemented by cooperation of a plurality of units.
According to another embodiment of the present application, the data processing apparatus shown in fig. 10 may be constructed by running a computer program (including program codes) capable of executing the steps involved in the respective methods 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 a storage element, and implementing the data processing method of the embodiment of the present application. The computer program may be embodied on a computer-readable storage medium, for example, and loaded into and executed by the above-described computing apparatus via the computer-readable storage medium.
In this embodiment of the 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 of which the language type is the 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 a target code; 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 where the target code runs. Internationalized processing of the code to be detected can be realized based on semantic analysis of the code to be detected, that is, a target character string with a language type of a first language type is determined from the code to be detected based on the 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 where the target code runs, namely when the target code runs, the target character string can be displayed according to the language type of the language environment where the target code runs, effective interaction with a user in the language environment can be achieved, and user experience is improved.
Based on the method embodiment and the device embodiment, the application also provides a data processing device. Fig. 11 is a schematic structural diagram of a data processing apparatus according to an embodiment of the present application. The data processing device shown in fig. 11 may comprise at least a processor 1101, an input interface 1102, an output interface 1103, and a computer storage medium 1104. 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.
A computer storage medium 1104 may be stored in the memory of the data processing apparatus, the computer storage medium 1104 being for storing a computer program comprising program instructions, the processor 1101 being for executing the program instructions stored by the computer storage medium 1104. The processor 1101 (or CPU) is a computing core and a control core of the data Processing apparatus, and is adapted to implement one or more instructions, and in particular, is adapted to load and execute one or more instructions so as to implement the data Processing method flow or corresponding functions.
An embodiment of the present application further provides a computer storage medium (Memory), which is a Memory device in a data processing device and is used to store programs and data. It is understood that the computer storage medium herein may include a built-in storage medium in the terminal, and may also include 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), suitable for loading and execution by the processor 1101. The computer storage medium may be a Random Access Memory (RAM) memory, or a non-volatile memory (non-volatile memory), such as at least one disk memory; and optionally at least one computer storage medium located remotely from the processor.
In one embodiment, one or more instructions stored in the computer storage medium may be loaded and executed by the processor 1101 and the input interface 1102 to implement the corresponding steps of the method in the data processing method embodiment described above with reference to fig. 1 and fig. 3, and in particular, one or more instructions stored in the computer storage medium may be loaded and executed by the processor 1101 and the input interface 1102 to implement the following steps:
an input interface 1102 for acquiring 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 a target character string from the code to be detected based on the 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 a target function call to a target character string in the code to be detected to generate a 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 where the target code runs.
In one embodiment, the abstract syntax tree includes a plurality of nodes, parent-child relationships exist among the nodes, and one of the nodes represents a syntax structure of the code to be detected;
when the processor 1101 determines a target character string from the code to be detected based on the abstract syntax tree corresponding to the code to be detected, the following operations are specifically performed:
taking any node which is not traversed in the abstract syntax tree as a target node of current traversal;
if the target node represents a first character string with a language type of a first language type, determining whether the target node is added with a target function call;
and if the target node is not added with a target function call, determining the target character string based on the first character string.
In one embodiment, when the processor 1101 determines whether the target node adds the target function call, the following operation is 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 is added with the target function call;
and if the parent node of the target node does not represent the function call, or the parent node of the target node represents the function call but the sibling node of the target node does not represent the target function, determining that the target node does not add the target function call.
In an embodiment, if the target node does not add a target function call, when determining the target character string based on the first character string, the processor 1101 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 character string splicing, determining the first character string as the target character string;
if the parent node of the target node represents character string splicing, performing a recursive operation for determining the target character string from the parent node of the target node, so as to obtain a target sub-tree from the abstract syntax tree based on a parent-child relationship between nodes in the abstract syntax tree, wherein a root node of the target sub-tree represents character string splicing, and leaf nodes of the target sub-tree 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 the following operation when performing a recursive operation for determining the target character string starting from the parent node of the target node to obtain the target sub-tree from the abstract syntax tree based on the parent-child relationship between the nodes in the abstract syntax tree:
taking a father node of the target node as an initial node when the recursive operation starts to be executed, and sequentially determining whether one or more ancestor nodes of the initial node represent character string splicing or not until a 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 recursive operation stops, wherein the target ancestor node does not represent character string splicing;
and determining a target sub-tree comprising the target node from the abstract syntax tree by taking one or more ancestor nodes of the initial node processed by the recursive operation and an ancestor node of a child node belonging to the termination node as a root node of the target sub-tree.
In an embodiment, when the processor 1101 adds a target function call to the target character string in the code to be detected to generate a target code, the following operations are specifically performed:
generating a target function call sub-tree 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 call sub-tree 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 call 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 an embodiment, when the processor 1101 adds a target function call to the target character string in the code to be detected to generate a target code, the following operations are specifically performed:
generating a target function calling code corresponding to the target character string based on the target character string and the target function calling;
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 character string is obtained based on the target sub-tree, and the target character string includes a character string variable;
when the processor 1101 generates a target function call code corresponding to the target character string based on the target character string and the target function call, the following operations are specifically performed:
splicing the leaf nodes of the target subtree to obtain a character string to be replaced corresponding to the target character string;
replacing character string variables included in the character string to be replaced with placeholders to obtain a target character string to be replaced;
and generating a target function calling code corresponding to the target character string based on the target character string to be replaced, the character string variable and the target function calling.
Embodiments of the present application provide a computer program product or a computer program, the computer program product comprising a computer program, the computer program being stored in a computer storage medium; the processor of the data processing device reads the computer program from the computer storage medium, and the processor executes the computer program, so that the data processing device executes the method embodiments shown in fig. 1 and fig. 3. The computer-readable storage medium may be a magnetic disk, an optical disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), or the like.
The above description is only for the specific embodiments of the present application, but the scope of the present application is not limited thereto, and any person skilled in the art can easily conceive of the changes or substitutions within the technical scope of the present application, and shall be covered by the scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.

Claims (10)

1. A data processing method, comprising:
acquiring a code to be detected;
performing 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 the 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 a target function call to the target character string in the code to be detected to generate a 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 where the target code runs.
2. The method of claim 1, wherein the abstract syntax tree comprises a plurality of nodes, wherein parent-child relationships exist between the plurality of nodes, and one of the plurality of nodes represents a syntax structure of the code to be detected;
the determining a target character string from the code to be detected based on the abstract syntax tree corresponding to the code to be detected comprises the following steps:
taking any node which is not traversed in the abstract syntax tree as a target node of current traversal;
if the target node represents a first character string with a language type of a first language type, determining whether the target node is added with a target function call;
and if the target node is not added with a target function call, determining the target character string based on the first character string.
3. The method of claim 2, wherein said determining whether the target node adds a target function call comprises:
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 is added with the target function call;
and if the parent node of the target node does not represent the function call, or the parent node of the target node represents the function call but the sibling node of the target node does not represent the target function, determining that the target node does not add the target function call.
4. The method of claim 2, wherein 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 character string splicing, determining the first character string as the target character string;
if the parent node of the target node represents character string splicing, performing a recursive operation for determining the target character string from the parent node of the target node, so as to obtain a target sub-tree from the abstract syntax tree based on a parent-child relationship between nodes in the abstract syntax tree, wherein a root node of the target sub-tree represents character string splicing, and leaf nodes of the target sub-tree 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.
5. The method of claim 4, wherein said performing a recursive operation from a parent node of the target node to determine the target string to obtain a target sub-tree from the abstract syntax tree based on parent-child relationships between nodes in the abstract syntax tree comprises:
taking a father node of the target node as an initial node when the recursive operation starts to be executed, and sequentially determining whether one or more ancestor nodes of the initial node represent character string splicing or not until a 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 recursive operation stops, wherein the target ancestor node does not represent character string splicing;
and determining a target sub-tree comprising the target node from the abstract syntax tree by taking one or more ancestor nodes of the initial node processed by the recursive operation and an ancestor node of a child node belonging to the termination node as a root node of the target sub-tree.
6. The method of claim 4, wherein the adding a target function call to the target character string in the code to be detected to generate target code comprises:
generating a target function call sub-tree 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 call sub-tree 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 call 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.
7. The method of claim 4, wherein the adding a target function call to the target character string in the code to be detected to generate target code comprises:
generating a target function calling code corresponding to the target character string based on the target character string and the target function calling;
and replacing the target character string in the code to be detected with the target function calling code to obtain the target code.
8. The method of claim 7, wherein the target string is derived based on the target sub-tree and includes a string variable;
generating a target function call code corresponding to the target character string based on the target character string and the target function call, including:
splicing the leaf nodes of the target subtree to obtain a character string to be replaced corresponding to the target character string;
replacing character string variables included in the character string to be replaced with placeholders to obtain a target character string to be replaced;
and generating a target function calling code corresponding to the target character string based on the target character string to be replaced, the character string variable and the target function calling.
9. A data processing apparatus, comprising:
the acquisition unit is used for acquiring a 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 the 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 configured to add a target function call to the target character string in the code to be detected to generate a 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 where the target code runs.
10. A data processing apparatus, characterized in that the data processing apparatus comprises an input interface and an output interface, and further comprises:
a processor adapted to implement one or more instructions; and the number of the first and second groups,
a computer storage medium having stored thereon one or more instructions adapted to be loaded by the processor and to execute the above-described data processing method.
CN202111251532.9A 2021-10-26 2021-10-26 Data processing method, device, equipment, storage medium and computer program product Pending CN113971028A (en)

Priority Applications (1)

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

Applications Claiming Priority (1)

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

Publications (1)

Publication Number Publication Date
CN113971028A true CN113971028A (en) 2022-01-25

Family

ID=79588511

Family Applications (1)

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

Country Status (1)

Country Link
CN (1) CN113971028A (en)

Similar Documents

Publication Publication Date Title
US10824691B2 (en) Page rendering method, device, and data storage medium
WO2018082562A1 (en) Method and device for compiling page data and rendering page, and storage medium
US20120110444A1 (en) Help Document Animated Visualization
CN110727429B (en) Front-end page generation method, device and equipment
US20190065164A1 (en) Computer speed via metadata-based business rule interpreter
CN112506602B (en) Page generation method and device, electronic equipment and computer readable medium
CN110673837B (en) Code repairing method and device, electronic equipment and computer readable storage medium
WO2018222327A1 (en) Automated or machine-enhanced source code debugging
CN111176629A (en) Application development method and device
CN112905179A (en) Mobile terminal H5 page generation method and device, electronic equipment and storage medium
CN108920566B (en) Method, device and equipment for operating SQLite database
CN114077430A (en) Interface generation method and device, electronic equipment and storage medium
CN110362317B (en) Code conversion method, device and storage medium
CN111061466A (en) Automatic conversion method, system, terminal and medium of behavior control scripting language
CN114911541B (en) Processing method and device of configuration information, electronic equipment and storage medium
CN113971028A (en) Data processing method, device, equipment, storage medium and computer program product
CN114879965A (en) Data settlement method, device, equipment and storage medium
US11429358B2 (en) Representing asynchronous state machine in intermediate code
CN114816420A (en) Data processing method and device
CN110941429B (en) Method, device and equipment for processing business script of webpage
CN113448874A (en) Method and device for generating unit test script
CN117270838B (en) Method, device, equipment and medium for generating universal formula script
CN112241505A (en) Page updating method, page updating device, medium and electronic equipment
CN113741900B (en) Development method and device of front-end page application and related equipment
CN117170654A (en) Development method and device of graphical user interface application program and electronic equipment

Legal Events

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