CN113961192A - Code data processing method and device and electronic equipment - Google Patents

Code data processing method and device and electronic equipment Download PDF

Info

Publication number
CN113961192A
CN113961192A CN202111333092.1A CN202111333092A CN113961192A CN 113961192 A CN113961192 A CN 113961192A CN 202111333092 A CN202111333092 A CN 202111333092A CN 113961192 A CN113961192 A CN 113961192A
Authority
CN
China
Prior art keywords
character
target
function
identifier
placeholder
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
CN202111333092.1A
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.)
China Construction Bank Corp
Original Assignee
China Construction Bank Corp
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 China Construction Bank Corp filed Critical China Construction Bank Corp
Priority to CN202111333092.1A priority Critical patent/CN113961192A/en
Publication of CN113961192A publication Critical patent/CN113961192A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/38Creation or generation of source code for implementing user interfaces
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • 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/425Lexical analysis
    • 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/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/43Checking; Contextual analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/43Checking; Contextual analysis
    • G06F8/436Semantic checking

Landscapes

  • Engineering & Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Human Computer Interaction (AREA)
  • Computational Linguistics (AREA)
  • Document Processing Apparatus (AREA)

Abstract

The specification discloses a code data processing method, a device and electronic equipment, which relate to the technical field of automatic coding, wherein the method comprises the following steps: acquiring a target character to be changed in a target code segment and a substitute character for replacing the target character; acquiring a syntax tree of a target code segment; searching a target character from a text type node of a grammar tree; determining a target line of the searched character in the target code segment according to the syntax tree; and replacing the characters searched in the target line with placeholders, and establishing an association relation between the placeholders and the replaced characters so as to replace the placeholders with the replaced characters when the target code segment is compiled or executed. By the scheme, the problems of low replacement accuracy and low replacement efficiency in the conventional character replacement are solved, and the technical effect of effectively improving the character replacement accuracy and the character replacement efficiency is achieved.

Description

Code data processing method and device and electronic equipment
Technical Field
The present application relates to the field of automated coding technologies, and in particular, to a method and an apparatus for processing code data, and an electronic device.
Background
The information system is a man-machine integrated system composed of computer hardware, network and communication equipment, computer software, information resource, information user and regulation system and aimed at processing information flow. In short, an information system is a system that inputs data or information and generates information by processing. The task of the information system is to utilize modern computers and network communication technology to strengthen information management of enterprises, to establish correct data through investigation and understanding of resources owned by the enterprises, such as manpower, material resources, financial resources, equipment, technology and the like, to process, compile and make various information data to be provided for managers in time so as to make correct decisions.
In a modern information system, because multiple legal subjects need to be docked after the same system is applied and developed, and multiple subject versions need to be provided, the requirement of differential customization of the information system can appear. Most of the majority of the major improvement work for multiple legal people at present is focused on the front-end user interface.
There are two main methods for changing the front-end code.
Firstly, determining the keywords to be changed and the replaced words on the front-end display, and manually searching in batch and replacing the keywords with the replaced words. This approach is feasible in small-scale projects. However, there are significant drawbacks to large projects: it is difficult to maintain and error prone and requires a new operation each time multiple subject changes are involved.
And secondly, replacing keywords in the code file with placeholders according to a regular matching mode, recording a corresponding relation between the placeholders and the replaced replacing words in a configuration file of the code project, and calling the configuration file to modify the keywords through compiling or executing the code project.
There are currently many plug-ins or solutions in the front-end ecology based on the second solution, but this profile-based solution has the following problems:
1. the keywords are replaced by placeholders manually, errors are prone to occurring, and accuracy is low.
2. The keywords are replaced by the placeholders in a regular matching mode, so that certain limitation exists, many scenes needing to adjust matching rules appear due to personal coding habits and project management coding specifications, and particularly in scenes relating to Chinese file line change, regular matching is quite complicated to process, and manual adjustment is needed to enable the keywords to meet grammar specifications. But no matter how personal coding habits and how the code format is disordered, the code formatting function of the editor can always accurately organize the code according to the established rules. In short, the regular matching can only treat the code as a composition text, so that the problem of grammar specification cannot be solved, for example, the grammar specifications in the html template and the javascript are different, the regular replacement cannot identify the position of the document to be replaced and the context grammar environment thereof, after the regular matching replacement, manual intervention and adjustment are needed in many places to enable the document to be in accordance with the grammar specification, otherwise, the code is wrongly reported during running. Besides, it is easy to have a mismatch or missing match due to non-standardized format, and the operability is poor.
Disclosure of Invention
The embodiment of the application aims to provide a code data processing method and device and electronic equipment, so that accurate replacement is realized and replacement efficiency is improved.
In order to solve the above technical problem, a first aspect of the present specification provides a method for processing code data, including: acquiring a target character to be changed in a target code segment and a substitute character for replacing the target character; acquiring a syntax tree of the target code segment; searching the target character from a text type node of the grammar tree; determining a target line of the searched character in the target code segment according to the syntax tree; replacing the characters searched in the target line with placeholders, and establishing an association relation between the placeholders and the replaced characters so as to replace the placeholders with the replaced characters when the target code segment is compiled or executed.
In some embodiments, the placeholders include at least one of: an identifier, a function name of a preset function, and an attribute symbol for representing an attribute of the identifier.
In some embodiments, after determining a target line of the searched character in the target code segment according to the syntax tree, before replacing the searched character in the target line with a placeholder and establishing an association relationship between the placeholder and the replaced character, the method further includes: acquiring an identifier; a placeholder is generated from the identifier.
In some embodiments, generating placeholders from the identifiers comprises: determining whether the character found in the target line is located between a pair of html tags; determining an element for generating a placeholder according to a mustache syntax format under the condition that the character searched in the target line is positioned between the pair of html tags; the elements include: the attribute symbol, the function name of the preset function, the position relation between the attribute symbol and the identifier, and the position relation between the function name of the preset function and the identifier; a placeholder is generated from the identifier and the element.
In some embodiments, generating placeholders from the identifiers comprises: determining whether the character found in the target line is located between a pair of script tags; determining an element for generating a placeholder according to the JS grammar under the condition that the character searched in the target line is located between a pair of script tags; the elements include: presetting a function name of a function, and presetting a position relation between the function name of the function and an identifier; a placeholder is generated from the identifier and the element.
In some embodiments, the placeholder includes a function name of the custom function.
In some embodiments, replacing the character found in the target line with a placeholder, and establishing an association relationship between the placeholder and the replaced character includes: determining whether the character searched in the target line is the attribute of the html tag; under the condition that the character found in the target line is the attribute of the html tag, acquiring a function template, wherein the function template contains preset characters and is used for returning a substitute character corresponding to the preset characters; acquiring an identifier corresponding to the target character; replacing preset characters in the template of the custom function with the identifiers to obtain definition codes of the custom function, and writing the definition codes of the custom function into a code file associated with the target code segment; and replacing the characters searched in the target line with the calling codes of the custom function.
In some embodiments, determining a target line of the found character in the target code segment according to the syntax tree includes: determining the node position of the searched character in the grammar tree; determining a context node according to the node position; determining the context of the searched character in the target code segment according to the content of the context node; and determining a target line of the searched character in the target code segment according to the context of the searched character in the target code segment.
In some embodiments, the target code segment, when executed, replaces the placeholder with the replacement character, including: receiving a login request of a target user, wherein the login request carries identification information of the target user; obtaining an identification character associated with the target user according to the identification information matching; in response to the login request, executing the target code with an identification character associated with the target user as a replacement character.
A second aspect of the present specification is a code data processing apparatus, including: the first acquisition module is used for acquiring a target character to be changed in a target code segment and a substitute character for replacing the target character; the second acquisition module is used for acquiring the syntax tree of the target code segment; the searching module is used for searching the target character from the text type node of the grammar tree; the determining module is used for determining a target line of the searched character in the target code segment according to the syntax tree; and the replacing module is used for replacing the characters found in the target line with placeholders and establishing the association relationship between the placeholders and the replaced characters so as to replace the placeholders with the replaced characters when the target code segment is compiled or executed.
In some embodiments, the placeholders include at least one of: an identifier, a function name of a preset function, and an attribute symbol for representing an attribute of the identifier.
In some embodiments, the apparatus further comprises: a third obtaining module, configured to, after determining a target line of the searched character in the target code segment according to the syntax tree, replace the searched character in the target line with a placeholder, and obtain an identifier before establishing an association relationship between the placeholder and the replaced character; a generating module to generate a placeholder according to the identifier.
In some embodiments, the generating module comprises: the first determining submodule is used for determining whether the characters searched in the target line are positioned between a pair of html tags or not; a second determining submodule, configured to determine, according to a mustache syntax format, an element used for generating a placeholder when a character found in the target line is located between a pair of html tags; the elements include: the attribute symbol, the function name of the preset function, the position relation between the attribute symbol and the identifier, and the position relation between the function name of the preset function and the identifier; a first generation submodule to generate a placeholder based on the identifier and the element.
In some embodiments, the generating module comprises: a third determining submodule, configured to determine whether a character found in the target line is located between a pair of script tags; a fourth determining submodule, configured to determine, according to the JS syntax, an element used for generating a placeholder when the character found in the target line is located between the pair of script tags; the elements include: presetting a function name of a function, and presetting a position relation between the function name of the function and an identifier; a second generation submodule to generate a placeholder based on the identifier and the element.
In some embodiments, the placeholder includes a function name of the custom function.
In some embodiments, the replacement module comprises: a fifth determining submodule, configured to determine whether the character found in the target line is an attribute of an html tag; the first obtaining sub-module is used for obtaining a function template under the condition that the character found in the target line is the attribute of the html tag, wherein the function template contains preset characters and is used for returning a substitute character corresponding to the preset characters; the acquisition submodule is used for acquiring an identifier corresponding to the target character; the coding submodule is used for replacing preset characters in the template of the user-defined function by the identifier to obtain a definition code of the user-defined function, and writing the definition code of the user-defined function into a code file associated with the target code segment; and the replacing submodule is used for replacing the characters searched in the target line with the calling codes of the custom function.
In some embodiments, the determining module comprises: a sixth determining submodule, configured to determine a node position of the searched character in the syntax tree; a seventh determining submodule, configured to determine a context node according to the node position; an eighth determining submodule, configured to determine, according to the content of the context node, a context of the searched character in the target code segment; a ninth determining sub-module, configured to determine a target row of the searched character in the target code segment according to the context of the searched character in the target code segment.
In some embodiments, the apparatus further comprises: the system comprises a receiving module, a judging module and a sending module, wherein the receiving module is used for receiving a login request of a target user, and the login request carries identification information of the target user; the matching module is used for obtaining the identification characters associated with the target user according to the identification information; and the response module is used for responding to the login request, taking the identification character associated with the target user as a substitute character and executing the target code.
A third aspect of the present specification is an electronic apparatus comprising: a memory and a processor, the processor and the memory being communicatively coupled to each other, the memory having stored therein computer instructions, the processor implementing the steps of the method of the first aspect by executing the computer instructions.
A fourth aspect of the present description is a computer storage medium storing computer program instructions which, when executed, implement the steps of the method of the first aspect.
According to the code data processing method and device and the electronic device provided by the embodiment of the specification, after the target character to be changed and the substitute character for replacing the target character in the target code segment are obtained, the target character is searched from the text type node of the syntax tree of the target code segment, the target row of the searched character in the target code segment is determined according to the syntax tree, and the character in the target row is replaced by the placeholder. Through direct operation of nodes of the grammar tree, the target characters can be accurately identified, the grammar environment where the target characters are located is identified, the problem that code abnormality is caused due to replacement errors and omission is solved, and the accuracy and efficiency of searching and replacing can be effectively 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 described in the present application, and for those skilled in the art, other drawings can be obtained according to the drawings without creative efforts.
FIG. 1 illustrates a method flow diagram of an embodiment of a method of processing code data according to an embodiment of the invention;
FIG. 2 depicts a flow diagram of one embodiment of a method of generating placeholders from identifiers;
FIG. 3 depicts a flow diagram of another method embodiment of generating placeholders from identifiers;
FIG. 4 is a flow diagram illustrating one embodiment of a method for replacing characters found in a target line with placeholders and establishing associations between the placeholders and the replaced characters;
FIG. 5 depicts a method flow diagram of another embodiment of a method of processing code data according to an embodiment of the invention;
FIG. 6 is a block diagram of a code data processing apparatus according to an embodiment of the present specification;
fig. 7 is a schematic structural diagram of an electronic device according to an embodiment of the present disclosure.
Detailed Description
In order to make those skilled in the art better understand the technical solutions in the present application, 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 obtained by a person of ordinary skill in the art without any inventive work based on the embodiments in the present application shall fall within the scope of protection of the present application.
Aiming at the problems of large coding style difference, coexistence of multiple coding normal forms and parallel multiple frames existing when a large-scale code project is subjected to multi-legal subject transformation in the prior art, if the conventional regular matching mode is used for processing, many abnormal conditions can be caused, the problem of grammar specification can not be solved, further, after regular replacement, manual investigation and adjustment are needed, and the accuracy and the efficiency of replacement are low. In order to solve the problems of low replacement accuracy and low efficiency existing in the conventional multi-legal-person main body reconstruction, the embodiment provides a code data processing method, a grammar parsing result is used for quickly and accurately replacing a pattern in a project code into a bit occupying mark according to a specified rule, and the method has obvious advantages for the reconstruction of a large project.
The code data in this specification may be specific code in the code segment or may be data required when the code segment is executed.
The code segment and the target code segment in the specification can be continuous multiple lines of codes in one code file; or two or more non-adjacent code blocks in one code file, wherein one code block comprises continuous multiple lines of codes; there may also be multiple code blocks dispersed in different code files.
The code file containing the target code segment is organized in a code project, which refers to a code file set formed by organizing a plurality of code files together according to a certain rule through coding software (also called programming software and code development software, such as vscode, IntelliJ IDEA, sublitetext, PLSQL server). The coding software has a code editing window in which specific code statements in a code file can be written, modified, and viewed. The coding software can compile and link the code statements in each code file to form an executable file, and the executable file realizes the instruction operation expressed by the code statements in the code file when executing. The formed executable file is the software used by the user.
The types of the code files are various, and the code files can be written by adopting various coding rules to obtain code files with different suffixes. For example, a file with a suffix of ". java" is obtained by coding using java coding rules, a file with a suffix of ". js" is obtained by coding using javascript coding rules, and a file with a suffix of ". html" is obtained by coding using html coding rules. The code written for presentation at the front end is different for different encoding rules.
The "front end" in the present application refers to a portion that presents information to a user and provides a user operation interface. For example, when a web page is browsed through a browser, the content displayed on the web page is the content of the front-end presentation.
The implementation subject of the code data processing method provided by the present specification may be an electronic device with a logical computing function, for example, a computer client, a server, or a computer cluster formed by a plurality of servers.
The development process of the code project comprises the compiling of a source code and the testing of the source code and an executable file corresponding to the source code, and usually, a plurality of persons are required to cooperate together, so that code version control software is required to manage the source code compiled by each encoding person. The code version control software comprises server-side software and client-side software, and each encoding terminal (such as a computer) used by each encoding personnel or each testing terminal (such as a computer) used by each testing personnel runs one client-side software. The version control software may be, for example, Git, SVN, CVS.
After a coding person writes a source code of a certain module in a coding terminal, the source code of the module is submitted to a code version control server through client software, the server fuses the source codes coded by different coding persons to form a code file, and the code files are organized together according to a certain rule.
When a tester needs to test a source code, the code file is obtained from the code version control server through client software, and a software testing tool written by the tester is adopted for testing to obtain a testing result. When a coding worker needs to modify a source code, a client side obtains a needed code file from a code version control server, the code file is merged into a local code project of the client side, the source code is modified based on the merged code project, and the modified file is submitted to the code version control server after modification.
When the source code on the code version control server is written or modified relatively well, someone may compile, link, and package the source code stored in the code version control server to form an executable file, and deploy the executable file, that is, the software, to a server of a buyer of the software (for example, when a software system is written for a bank, the bank is the buyer of the software, and the unit for writing the source code is a provider). The software running process can realize the function expressed by the corresponding source code.
The code data processing method provided by the present specification may be applied to any one of the above-described encoding terminals, and may also be applied to an electronic device that runs the above-described code version control server.
Although the present specification provides method operational steps or apparatus configurations as illustrated in the following examples or figures, more or fewer operational steps or modular units may be included in the methods or apparatus based on conventional or non-inventive efforts. In the case of steps or structures which do not logically have the necessary cause and effect relationship, the execution sequence of the steps or the module structure of the apparatus is not limited to the execution sequence or the module structure described in the embodiments and shown in the drawings. When the described method or module structure is applied in an actual device or end product, the method or module structure according to the embodiments or shown in the drawings can be executed sequentially or executed in parallel (for example, in a parallel processor or multi-thread processing environment, or even in a distributed processing environment).
As shown in fig. 1, the processing method of code data includes the following steps.
S101: and acquiring a target character to be changed and a substitute character for replacing the target character in the target code segment.
The target character to be modified and the substitute character for replacing the target character may be stored in a configuration file in advance. Accordingly, step S101 may take the form of acquiring and reading a configuration file.
The configuration file may be determined according to customer requirements, for example, if the code item is originally used to implement a website of company a, and is modified to implement a website of company B, the target character to be modified in the code item includes "company a", and the corresponding substitute character may be "company B".
The "target character" and "alternative character" in this application may be numbers or letters, symbols such as $, and the like, or a string of characters formed by these symbols. The target character and the substitute character may be in a one-to-one correspondence.
S102: and acquiring a syntax tree of the target code segment.
In computer science, a syntax tree (english: syntax tree) or an Abstract Syntax Tree (AST) is a tree representation of an abstract syntax structure of source code, and is herein referred to specifically as source code of a programming language. It represents the syntactic structure of the programming language in the form of a tree, each node on the tree representing a structure in the source code. The syntax is said to be "abstract" in that the syntax does not represent every detail that appears in the true syntax.
The first feature of the abstract syntax tree is: and is not dependent on a particular grammar. The context is free of grammar, and the same syntax tree is required to be constructed during syntax analysis, so that a clear and unified interface can be provided for the rear end of the compiler. Even if the front end adopts different grammars, only the front end code needs to be changed without affecting the back end. I.e., reduced workload, and improved compiler maintainability.
The second feature of the abstract syntax tree is: independent of the details of the language. In each compiler, gcc may compile a variety of languages, such as C, C + +, java, ADA, Object C, FORTRAN, PASCAL, COBOL, and so forth. At the front end, gcc performs lexical, syntactic and semantic analysis on different languages, and generates an abstract syntax tree to form an intermediate code as an output for the back-end processing. To do this, it is necessary to construct the syntax tree independent of the language details. For example, in different languages, where statements like if-condition-then have different representation methods, the corresponding syntax trees may be the same.
Before step S102, the method may further include the steps of: a syntax tree of the target code segment is generated. In some embodiments, the syntax tree of the target code segment may also be generated and stored in advance. In some embodiments, the syntax tree may also be generated and transmitted to the execution subject of step S102 by other electronic devices.
Syntax trees can be generated using syntactic parsers, with corresponding syntactic parsers for essentially every language. The code formatting plug-in of the vscode is internally provided with a parser, for example, a prettier plug-in can be selected, and the built-in parser of the code formatting plug-in can be used for parsing vue front-end displayed code file or target code segment to generate a syntax tree.
S103: and searching the target character from the text type node of the grammar tree.
The node types of the syntax tree include a variety of types, for example: the js syntax tree node types may include nearly hundreds of types such as "Literal", "expressonstate", "Property", "directviereral", where "Literal" is a node of a text type.
S104: and determining a target line of the searched character in the target code segment according to the syntax tree.
The syntax tree reflects the syntax structure of the source code, and the target line of the node on the syntax tree in the target code segment can be known according to the syntax tree, and even more specific positions of the characters in the target line can be further found.
Specifically, the node position of the searched character in the syntax tree may be determined first, then a context node is determined according to the node position, then the context of the searched character in the target code segment is determined according to the content of the context node, and finally the target line of the searched character in the target code segment is determined according to the context of the searched character in the target code segment.
S105: and replacing the characters searched in the target line with placeholders, and establishing an association relation between the placeholders and the replaced characters so as to replace the placeholders with the replaced characters when the target code segment is compiled or executed.
The syntax involved may be different for different positions of the characters to be replaced in the target code segment, and therefore the rules for generating placeholders and the shape of the generated placeholders may be different.
In some embodiments, between steps S104 and S105, the following steps are further included: the identifier is obtained, and a placeholder is generated according to the identifier.
The identifier is an identification of the target character to be modified. The identifiers corresponding to the plurality of target characters may be sequentially numbered or randomly numbered.
In some embodiments, the identifier is predetermined. For example, in the configuration file in which the target character and the substitute character are in one-to-one correspondence, the target character and the substitute character also correspond to one identifier.
In some embodiments, the identifier is generated temporarily. For example, before the first identifier needs to be used, a first identifier identified as "XH 0001" is generated; before the second identifier needs to be used, a second identifier identified as "XH 0002" is generated, and so on for each identifier.
In some embodiments, the placeholders include at least one of: an identifier, a function name of a preset function, and an attribute symbol for representing an attribute of the identifier.
The preset function refers to a function defined in advance in a code file of a code item. The preset function is used to return the content corresponding to the form parameter. When the preset function is used, the calling code of the function can be directly written. The identifier can be used as a form parameter of the preset function, so that the preset function returns a substitute character corresponding to the identifier, that is, the association relationship between the placeholder and the substitute character is established through the preset function.
And the attribute symbol is used for representing the identifier attribute. For example indicating whether the identifier is a string of characters or an expression.
In some embodiments, as shown in FIG. 2, placeholders may be generated from the identifiers by the following steps.
S201: it is determined whether the character found in the target line is located between a pair of html tags.
S202: determining an element for generating a placeholder according to a mustache syntax format under the condition that the character searched in the target line is positioned between the pair of html tags; the elements include: the attribute symbol, the function name of the preset function, the position relation between the attribute symbol and the identifier, and the position relation between the function name of the preset function and the identifier.
S203: a placeholder is generated from the identifier and the element.
For example, if the content in the original code file is "< tag > xxx company < tag >", the attribute symbol may be determined to be "{ } } according to the syntax format of mustache, the function name of the preset function is" $ t ", and a placeholder { $ t (" XH0001 ") } is generated, that is, the modified code is" < tag > { $ t ("XH 0001") } } < tag > ", and the function $ t (" XH0001 ") is used for searching for and returning a character corresponding to the identifier XH0001, that is, a substitute character.
In some embodiments, as shown in FIG. 3, placeholders may be generated from the identifiers by the following steps.
S301: it is determined whether the character found in the target line is located between a pair of script tags.
S302: determining an element for generating a placeholder according to the JS grammar under the condition that the character searched in the target line is positioned between the pair of script tags; the elements include: and the function name of the preset function, and the position relation between the function name of the preset function and the identifier.
S303: a placeholder is generated from the identifier and the element.
For example, if the content in the original code file is "xxx company", the function name of the preset function is determined to be "$ t" according to the JS syntax, and a placeholder $ t ("XH 0002") is generated. I.e., the modified code is "$ t (" XH0002 ")", and the function $ t ("XH 0002") is used to find and return the character corresponding to identifier XH0002, i.e., the substitute character.
In some embodiments, the placeholder includes a function name of the custom function.
Different from the preset function, the self-defined function refers to a function which is not defined in the original code item, and a function for defining a code needs to be written additionally on the basis of the original code item.
In some embodiments, as shown in fig. 4, the above step S105 may be implemented by the following steps.
S401: and determining whether the character found in the target line is the attribute of the html tag.
html tags may possess attributes. Attributes provide more information about html elements. Attributes always appear in the form of name/value pairs, such as: name is "value". The attributes are always specified in the start tag of the html element. For example, < h1> defines the beginning of a title, < h1 align ═ center "> possesses additional information about the alignment.
S402: and under the condition that whether the character searched in the target line is the attribute of the html tag or not, acquiring a function template, wherein the function template contains preset characters and is used for returning a substitute character corresponding to the preset characters.
S403: an identifier corresponding to the target character is obtained.
The identifier is an identification of the target character to be modified. The identifiers corresponding to the plurality of target characters may be sequentially numbered or randomly numbered.
In some embodiments, the identifier is predetermined. For example, in the configuration file in which the target character and the substitute character are in one-to-one correspondence, the target character and the substitute character also correspond to one identifier.
In some embodiments, the identifier is generated temporarily. For example, before the first identifier needs to be used, a first identifier identified as "XH 0001" is generated; before the second identifier needs to be used, a second identifier identified as "XH 0002" is generated, and so on for each identifier.
S404: and replacing preset characters in the template of the custom function with the identifiers to obtain definition codes of the custom function, and writing the definition codes of the custom function into a code file associated with the target code segment.
S405: and replacing the characters searched in the target line with the calling codes of the custom functions.
For example, the content in the original code file is "< a title ═ xxx company home page" href ═ xxx ">, the modified code is" < a: "transformTitle" href ═ xxx ">, and a function definition code with a function name of transformtite is generated in the code file, and may be, for example, { return this. $ t (" XH0001 ") + 'home page' }, and the static attribute is modified into the dynamic binding attribute.
In the method for processing code data provided in the embodiments of the present description, after a target character to be changed and a substitute character for replacing the target character in a target code segment are obtained, the target character is searched from a text type node of a syntax tree of the target code segment, a target row of the searched character in the target code segment is determined according to the syntax tree, the character in the target row is replaced with a placeholder, and the syntax tree node is directly operated, so that the target character can be accurately identified, a syntax environment where the target character is located is identified, and a situation that a code is abnormal due to a replacement error and omission does not occur; the workload of searching and replacing can be completed by a computer, and the workload of manpower is less.
The position of the searched character in the code file is determined according to the node position of the searched character in the grammar tree, the placeholder meeting the corresponding grammar specification is automatically generated according to the target line of the searched character in the code file, namely the grammar context environment where the searched character is located, and when the device is subsequently adapted to multi-subject adjustment, only the configuration file written with the corresponding relation between the placeholder and the substitute character needs to be adjusted, so that the device is simple and visual and has good maintainability.
In some embodiments, the identifier of the placeholder is a first field in the configuration file, the substitute character is a second field in the configuration file, the configuration file comprises at least one second field, and the content of the first field and the content of the second field are in one-to-one correspondence.
For example, there are three fields in the configuration file, the first field is a placeholder identifier, the third field is a target character to be changed, such as a character corresponding to company a, and the second field is a substitute character of the target character, such as a character corresponding to company B.
The identifier of the placeholder is an identifier for generating the placeholder. The identifier of the placeholder may be present in the configuration file before the steps described in fig. 1 are performed, or may be generated and written into the configuration file when the steps described in fig. 1 are performed. The first field, the second field and the third field in the application are only used for distinguishing the content of each field, and do not represent the sequence existing in the configuration file.
The configuration file may refer to a configuration file having a first field (i.e., the identifier of the placeholder), a third field (i.e., the target character to be changed), and at least one second field (i.e., the character to be replaced by the target character).
The configuration file may also refer to a plurality of configuration files, each configuration file includes a first field (i.e., identifier of placeholder), a second field (i.e., substitute character of target character), and some configuration files may further include a third field (i.e., target character to be changed).
As shown in fig. 5, the following steps may be further included after step S105.
S106: and receiving a login request of a target user, wherein the login request carries identification information of the target user.
S107: and obtaining the identification character associated with the target user according to the identification information matching.
The target user may be pre-associated with the identification character via a configuration file. For example, the target users are divided into a group, the identification of the group is used as the identification of the user subject, and the identification of the user subject is associated with the second field, for example, the second field "B" is associated with the identification of company B, and the second field "C" is associated with the identification of company C. Therefore, the identification of the user main body can be determined according to the target user, and then which specific second field needs to be adopted is determined. That is, through the corresponding relationship between each second field and the identifier of the user body, the front end of the code item can display different contents according to different users.
S108: in response to the login request, the target code is executed with the identification character associated with the target user as a replacement character.
Through the steps S106 to S108, after the substitute characters corresponding to each user subject are configured, the personnel under each user subject enter the system, and can display the corresponding subject document according to the user subject to which the personnel belongs, without repeatedly deploying multiple sets of systems, thereby considering data unification and differentiated display, and improving the expandability and maintainability of the system.
Based on the same inventive concept, an embodiment of the present specification further provides a device for processing code data, as described in the following embodiments. Because the principle of solving the problem of the processing device of the code data is similar to the processing method of the code data, the implementation of the processing device of the code data can refer to the implementation of the processing method of the code data, and repeated details are not repeated. As used hereinafter, the term "unit" or "module" may be a combination of software and/or hardware that implements a predetermined function. Although the means described in the embodiments below are preferably implemented in software, an implementation in hardware, or a combination of software and hardware is also possible and contemplated. Fig. 6 is a block diagram of a structure of a code data processing apparatus according to an embodiment of the present disclosure, and as shown in fig. 6, includes a first obtaining module 10, a second obtaining module 20, a searching module 30, a determining module 40, and a replacing module 50. The structure of the apparatus will be explained below.
The first obtaining module 10 is used for obtaining a target character to be changed in a target code segment and a substitute character for replacing the target character.
The second obtaining module 20 is configured to obtain a syntax tree of the target code segment.
The search module 30 is used to search the target character from the text type node of the syntax tree.
The determining module 40 is configured to determine a target line of the searched character in the target code segment according to the syntax tree.
The replacing module 50 is configured to replace the character found in the target line with a placeholder, and establish an association relationship between the placeholder and the replaced character, so that the placeholder is replaced with the replaced character when the target code segment is compiled or executed.
In some embodiments, the placeholders include at least one of: an identifier, a function name of a preset function, and an attribute symbol for representing an attribute of the identifier.
In some embodiments, the apparatus further comprises a third obtaining module 60 and a generating module 70.
The third obtaining module 60 is configured to, after determining a target line of the searched character in the target code segment according to the syntax tree, replace the searched character in the target line with a placeholder, and obtain an identifier before establishing an association relationship between the placeholder and the replaced character.
The generation module 70 is configured to generate a placeholder based on the identifier.
In some embodiments, the generation module 70 includes a first determination submodule 71, a second determination submodule 72, and a first generation submodule 73.
The first determination sub-module 71 is used to determine whether the character found in the target line is located between a pair of html tags.
The second determining submodule 72 is configured to determine, according to the mustache syntax format, an element used for generating a placeholder when the character found in the target line is located between the pair of html tags; the elements include: the attribute symbol, the function name of the preset function, the position relation between the attribute symbol and the identifier, and the position relation between the function name of the preset function and the identifier.
The first generation submodule 73 is configured to generate a placeholder from the identifier and the element.
In some embodiments, the generation module 70 includes a third determination submodule 74, a fourth determination submodule 75, and a second generation submodule 76.
The third determination sub-module 74 is used to determine whether the character found in the target line is located between a pair of script tags.
The fourth determining submodule 75 is configured to determine, according to the JS syntax, an element for generating a placeholder when the character found in the target line is located between the pair of script tags; the elements include: and the function name of the preset function, and the position relation between the function name of the preset function and the identifier.
The second generation submodule 76 is arranged to generate placeholders from the identifiers and the elements.
In some embodiments, the placeholder includes a function name of the custom function.
In some embodiments, the replacement module 50 includes a fifth determination submodule 51, a first acquisition submodule 52, an acquisition submodule 53, an encoding submodule 54, and a replacement submodule 55.
The fifth determining sub-module 51 is used to determine whether the character found in the target line is an attribute of the html tag.
The first obtaining sub-module 52 is configured to obtain a function template in a case that the character found in the target line is an attribute of the html tag, where the function template includes a preset character and is used to return a substitute character corresponding to the preset character.
The obtaining sub-module 53 is used to obtain an identifier corresponding to the target character.
The encoding submodule 54 is configured to replace a preset character in a template of the custom function with an identifier to obtain a definition code of the custom function, and write the definition code of the custom function into a code file associated with the target code segment.
The replacement submodule 55 is used to replace the characters found in the target line with the calling code of the custom function.
In some embodiments, the determination module 40 includes a sixth determination submodule 41, a seventh determination submodule 42, an eighth determination submodule 43, and a ninth determination submodule 44.
The sixth determining submodule 41 is configured to determine the node position of the searched character in the syntax tree.
The seventh determining submodule 42 is configured to determine context nodes according to the node positions.
The eighth determining submodule 43 is configured to determine the context of the searched character in the target code segment according to the content of the context node.
The ninth determining sub-module 44 is configured to determine a target row of the searched character in the target code segment according to the context of the searched character in the target code segment.
In some embodiments, the apparatus further comprises a receiving module 80, a matching module 90, and a response module 100.
The receiving module 80 is configured to receive a login request of a target user, where the login request carries identification information of the target user.
The matching module 90 is configured to obtain an identification character associated with the target user according to the identification information matching.
The response module 100 is configured to execute the target code in response to the login request, using the identification character associated with the target user as a substitute character.
An embodiment of the present invention further provides an electronic device, as shown in fig. 7, the electronic device may include a processor 701 and a memory 702, where the processor 701 and the memory 702 may be connected by a bus or in another manner, and fig. 7 takes the connection by the bus as an example.
Processor 701 may be a Central Processing Unit (CPU). The Processor 701 may also be other general purpose processors, Digital Signal Processors (DSPs), Application Specific Integrated Circuits (ASICs), Field Programmable Gate Arrays (FPGAs) or other Programmable logic devices, discrete Gate or transistor logic devices, discrete hardware components, or combinations thereof.
The memory 702, which is a non-transitory computer-readable storage medium, may be used to store non-transitory software programs, non-transitory computer-executable programs, and modules, such as program instructions/modules corresponding to the code data processing method in the embodiment of the present invention (for example, the first obtaining module 10, the second obtaining module 20, the searching module 30, the determining module 40, and the replacing module 50 shown in fig. 6). The processor 701 executes various functional applications and data classification of the processor, i.e., implements the processing method of the code data in the above-described method embodiments, by executing the non-transitory software program, instructions and modules stored in the memory 702.
The memory 702 may include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required for at least one function; the storage data area may store data created by the processor 701, and the like. Further, the memory 702 may include high-speed random access memory, and may also include non-transitory memory, such as at least one magnetic disk storage device, flash memory device, or other non-transitory solid state storage device. In some embodiments, memory 702 may optionally include memory located remotely from processor 701, which may be connected to processor 701 via a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The one or more modules are stored in the memory 702, and when executed by the processor 701, perform a processing method of code data as in the embodiments shown in fig. 1 to 5.
The details of the electronic device can be understood with reference to the descriptions and effects in the corresponding embodiments of fig. 1 to 5, and are not described herein again.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by a computer program, which can be stored in a computer-readable storage medium, and when executed, can include the processes of the embodiments of the methods described above. The storage medium may be a magnetic Disk, an optical Disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a Flash Memory (Flash Memory), a Hard Disk (Hard Disk Drive, abbreviated as HDD), a Solid State Drive (SSD), or the like; the storage medium may also comprise a combination of memories of the kind described above.
In the 90 s of the 20 th century, improvements in a technology could clearly distinguish between improvements in hardware (e.g., improvements in circuit structures such as diodes, transistors, switches, etc.) and improvements in software (improvements in process flow). However, as technology advances, many of today's process flow improvements have been seen as direct improvements in hardware circuit architecture. Designers almost always obtain the corresponding hardware circuit structure by programming an improved method flow into the hardware circuit. Thus, it cannot be said that an improvement in the process flow cannot be realized by hardware physical modules. For example, a Programmable Logic Device (PLD), such as a Field Programmable Gate Array (FPGA), is an integrated circuit whose Logic functions are determined by programming the Device by a user. A digital system is "integrated" on a PLD by the designer's own programming without requiring the chip manufacturer to design and fabricate a dedicated integrated circuit chip 2. Furthermore, nowadays, instead of manually making an Integrated Circuit chip, such Programming is often implemented by "logic compiler" software, which is similar to a software compiler used in program development and writing, but the original code before compiling is also written by a specific Programming Language, which is called Hardware Description Language (HDL), and HDL is not only one but many, such as abel (advanced Boolean Expression Language), ahdl (alternate Language Description Language), traffic, pl (core unified Programming Language), HDCal, JHDL (Java Hardware Description Language), langue, Lola, HDL, laspam, hardbyscript Description Language (vhr Description Language), and the like, which are currently used by Hardware compiler-software (Hardware Description Language-software). It will also be apparent to those skilled in the art that hardware circuitry that implements the logical method flows can be readily obtained by merely slightly programming the method flows into an integrated circuit using the hardware description languages described above.
The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments can be referred to each other, and each embodiment focuses on the differences from the other embodiments.
The systems, devices, modules or units described in the above embodiments may be implemented by a computer chip or an entity, or by a product with certain functions.
For convenience of description, the above devices are described as being divided into various units by function, and are described separately. Of course, the functionality of the units may be implemented in one or more software and/or hardware when implementing the present application.
From the above description of the embodiments, it is clear to those skilled in the art that the present application can be implemented by software plus necessary general hardware platform. Based on such understanding, the technical solutions of the present application may be essentially or partially implemented in the form of software products, which may be stored in a storage medium, such as ROM/RAM, magnetic disk, optical disk, etc., and include instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the methods of some parts of the embodiments of the present application.
The application is operational with numerous general purpose or special purpose computing system environments or configurations. For example: personal computers, server computers, hand-held or portable devices, tablet-type devices, multiprocessor systems, microprocessor-based systems, set top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments that include any of the above systems or devices, and the like.
The application may be described in the general context of computer-executable instructions, such as program modules, being executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform particular tasks or implement particular abstract data types. The application may also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules may be located in both local and remote computer storage media including memory storage devices.
The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for the hardware + program class embodiment, since it is substantially similar to the method embodiment, the description is simple, and the relevant points can be referred to the partial description of the method embodiment.
The foregoing description has been directed to specific embodiments of this disclosure. Other embodiments are within the scope of the following claims. In some cases, the actions or steps recited in the claims may be performed in a different order than in the embodiments and still achieve desirable results. In addition, the processes depicted in the accompanying figures do not necessarily require the particular order shown, or sequential order, to achieve desirable results. In some embodiments, multitasking and parallel processing may also be possible or may be advantageous.
Although the present specification provides method steps as described in the examples or flowcharts, additional or fewer steps may be included based on routine or non-inventive labor. The order of steps recited in the embodiments is merely one manner of performing the steps in a multitude of orders and does not represent the only order of execution. When an actual apparatus or client product executes, it may execute sequentially or in parallel (e.g., in the context of parallel processors or multi-threaded processing) according to the embodiments or methods shown in the figures.
The systems, devices, modules or units illustrated in the above embodiments may be implemented by a computer chip or an entity, or by a product with certain functions. One typical implementation device is a computer. In particular, the computer may be, for example, a personal computer, a laptop computer, a vehicle-mounted human-computer interaction device, a cellular telephone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
Although embodiments of the present description provide method steps as described in embodiments or flowcharts, more or fewer steps may be included based on conventional or non-inventive means. The order of steps recited in the embodiments is merely one manner of performing the steps in a multitude of orders and does not represent the only order of execution. When an actual apparatus or end product executes, it may execute sequentially or in parallel (e.g., parallel processors or multi-threaded environments, or even distributed data processing environments) according to the method shown in the embodiment or the figures. The terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, the presence of additional identical or equivalent elements in a process, method, article, or apparatus that comprises the recited elements is not excluded.
For convenience of description, the above devices are described as being divided into various modules by functions, and are described separately. Of course, in implementing the embodiments of the present description, the functions of each module may be implemented in one or more software and/or hardware, or a module implementing the same function may be implemented by a combination of multiple sub-modules or sub-units, and the like. The above-described embodiments of the apparatus are merely illustrative, and for example, the division of the units is only one logical division, and other divisions may be realized in practice, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
Those skilled in the art will also appreciate that, in addition to implementing the controller as pure computer readable program code, the same functionality can be implemented by logically programming method steps such that the controller is in the form of logic gates, switches, application specific integrated circuits, programmable logic controllers, embedded microcontrollers and the like. Such a controller may therefore be considered as a hardware component, and the means included therein for performing the various functions may also be considered as a structure within the hardware component. Or even means for performing the functions may be regarded as being both a software module for performing the method and a structure within a hardware component.
The description has been presented with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the description. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
In a typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
The memory may include forms of volatile memory in a computer readable medium, Random Access Memory (RAM) and/or non-volatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM). Memory is an example of a computer-readable medium.
Computer-readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), Digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, a computer readable medium does not include a transitory computer readable medium such as a modulated data signal and a carrier wave.
As will be appreciated by one skilled in the art, embodiments of the present description may be provided as a method, system, or computer program product. Accordingly, embodiments of the present description may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, embodiments of the present description may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and so forth) having computer-usable program code embodied therein.
The embodiments of this specification may be described in the general context of computer-executable instructions, such as program modules, being executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform particular tasks or implement particular abstract data types. The described embodiments may also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules may be located in both local and remote computer storage media including memory storage devices.
The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for the system embodiment, since it is substantially similar to the method embodiment, the description is simple, and for the relevant points, reference may be made to the partial description of the method embodiment. In the description herein, references to the description of the term "one embodiment," "some embodiments," "an example," "a specific example," or "some examples," etc., mean that a particular feature, structure, material, or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of an embodiment of the specification. In this specification, the schematic representations of the terms used above are not necessarily intended to refer to the same embodiment or example. Furthermore, the particular features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples. Furthermore, various embodiments or examples and features of different embodiments or examples described in this specification can be combined and combined by one skilled in the art without contradiction.
The above description is only an example of the embodiments of the present disclosure, and is not intended to limit the embodiments of the present disclosure. Various modifications and variations to the embodiments described herein will be apparent to those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the embodiments of the present specification should be included in the scope of the claims of the embodiments of the present specification.

Claims (18)

1. A method for processing code data, comprising:
acquiring a target character to be changed in a target code segment and a substitute character for replacing the target character;
acquiring a syntax tree of the target code segment;
searching the target character from a text type node of the grammar tree;
determining a target line of the searched character in the target code segment according to the syntax tree;
replacing the characters searched in the target line with placeholders, and establishing an association relation between the placeholders and the replaced characters so as to replace the placeholders with the replaced characters when the target code segment is compiled or executed.
2. The method of claim 1, wherein the placeholder comprises at least one of: an identifier, a function name of a preset function, and an attribute symbol for representing an attribute of the identifier.
3. The method according to claim 2, wherein after determining a target row of the searched character in the target code segment according to the syntax tree, before replacing the searched character in the target row with a placeholder and establishing an association relationship between the placeholder and the replaced character, further comprising:
acquiring an identifier;
a placeholder is generated from the identifier.
4. The method of claim 3, wherein generating placeholders from the identifiers comprises:
determining whether the character found in the target line is located between a pair of html tags;
determining an element for generating a placeholder according to a mustache syntax format under the condition that the character searched in the target line is positioned between the pair of html tags; the elements include: the attribute symbol, the function name of the preset function, the position relation between the attribute symbol and the identifier, and the position relation between the function name of the preset function and the identifier;
a placeholder is generated from the identifier and the element.
5. The method of claim 3, wherein generating placeholders from the identifiers comprises:
determining whether the character found in the target line is located between a pair of script tags;
determining an element for generating a placeholder according to the JS grammar under the condition that the character searched in the target line is located between a pair of script tags; the elements include: presetting a function name of a function, and presetting a position relation between the function name of the function and an identifier;
a placeholder is generated from the identifier and the element.
6. The method of claim 1, wherein the placeholder comprises a function name of a custom function.
7. The method of claim 6, wherein replacing the characters found in the target line with placeholders and establishing an association between the placeholders and the replaced characters comprises:
determining whether the character searched in the target line is the attribute of the html tag;
under the condition that the character found in the target line is the attribute of the html tag, acquiring a function template, wherein the function template contains preset characters and is used for returning a substitute character corresponding to the preset characters;
acquiring an identifier corresponding to the target character;
replacing preset characters in the template of the custom function with the identifiers to obtain definition codes of the custom function, and writing the definition codes of the custom function into a code file associated with the target code segment;
and replacing the characters searched in the target line with the calling codes of the custom function.
8. The method of claim 1, wherein determining a target line of the located character in the target code segment according to the syntax tree comprises:
determining the node position of the searched character in the grammar tree;
determining a context node according to the node position;
determining the context of the searched character in the target code segment according to the content of the context node;
and determining a target line of the searched character in the target code segment according to the context of the searched character in the target code segment.
9. The method of claim 1, wherein the target code segment, when executed, replaces the placeholder with the replacement character, comprising:
receiving a login request of a target user, wherein the login request carries identification information of the target user;
obtaining an identification character associated with the target user according to the identification information matching;
in response to the login request, executing the target code with an identification character associated with the target user as a replacement character.
10. An apparatus for processing code data, comprising:
the first acquisition module is used for acquiring a target character to be changed in a target code segment and a substitute character for replacing the target character;
the second acquisition module is used for acquiring the syntax tree of the target code segment;
the searching module is used for searching the target character from the text type node of the grammar tree;
the determining module is used for determining a target line of the searched character in the target code segment according to the syntax tree;
and the replacing module is used for replacing the characters found in the target line with placeholders and establishing the association relationship between the placeholders and the replaced characters so as to replace the placeholders with the replaced characters when the target code segment is compiled or executed.
11. The apparatus of claim 10, wherein the placeholder comprises at least one of: an identifier, a function name of a preset function, and an attribute symbol for representing an attribute of the identifier.
12. The apparatus of claim 11, further comprising:
a third obtaining module, configured to, after determining a target line of the searched character in the target code segment according to the syntax tree, replace the searched character in the target line with a placeholder, and obtain an identifier before establishing an association relationship between the placeholder and the replaced character;
a generating module to generate a placeholder according to the identifier.
13. The apparatus of claim 12, wherein the generating module comprises:
the first determining submodule is used for determining whether the characters searched in the target line are positioned between a pair of html tags or not;
a second determining submodule, configured to determine, according to a mustache syntax format, an element used for generating a placeholder when a character found in the target line is located between a pair of html tags; the elements include: the attribute symbol, the function name of the preset function, the position relation between the attribute symbol and the identifier, and the position relation between the function name of the preset function and the identifier;
a first generation submodule to generate a placeholder based on the identifier and the element.
14. The apparatus of claim 12, wherein the generating module comprises:
a third determining submodule, configured to determine whether a character found in the target line is located between a pair of script tags;
a fourth determining submodule, configured to determine, according to the JS syntax, an element used for generating a placeholder when the character found in the target line is located between the pair of script tags; the elements include: presetting a function name of a function, and presetting a position relation between the function name of the function and an identifier;
a second generation submodule to generate a placeholder based on the identifier and the element.
15. The apparatus of claim 10, wherein the placeholder comprises a function name of a custom function.
16. The apparatus of claim 15, wherein the replacement module comprises:
a fifth determining submodule, configured to determine whether the character found in the target line is an attribute of an html tag;
the first obtaining sub-module is used for obtaining a function template under the condition that the character found in the target line is the attribute of the html tag, wherein the function template contains preset characters and is used for returning a substitute character corresponding to the preset characters;
the acquisition submodule is used for acquiring an identifier corresponding to the target character;
the coding submodule is used for replacing preset characters in the template of the user-defined function by the identifier to obtain a definition code of the user-defined function, and writing the definition code of the user-defined function into a code file associated with the target code segment;
and the replacing submodule is used for replacing the characters searched in the target line with the calling codes of the custom function.
17. An electronic device, comprising:
a memory and a processor, the processor and the memory being communicatively connected to each other, the memory having stored therein computer instructions, the processor implementing the steps of the method of any one of claims 1 to 9 by executing the computer instructions.
18. A computer storage medium storing computer program instructions which, when executed, implement the steps of the method of any one of claims 1 to 9.
CN202111333092.1A 2021-11-11 2021-11-11 Code data processing method and device and electronic equipment Pending CN113961192A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111333092.1A CN113961192A (en) 2021-11-11 2021-11-11 Code data processing method and device and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111333092.1A CN113961192A (en) 2021-11-11 2021-11-11 Code data processing method and device and electronic equipment

Publications (1)

Publication Number Publication Date
CN113961192A true CN113961192A (en) 2022-01-21

Family

ID=79470044

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111333092.1A Pending CN113961192A (en) 2021-11-11 2021-11-11 Code data processing method and device and electronic equipment

Country Status (1)

Country Link
CN (1) CN113961192A (en)

Similar Documents

Publication Publication Date Title
US11797298B2 (en) Automating identification of code snippets for library suggestion models
US10705943B2 (en) Automating identification of test cases for library suggestion models
CN102804147B (en) Perform the code check executive system of the code check of ABAP source code
CN110688307B (en) JavaScript code detection method, device, equipment and storage medium
US20140331203A1 (en) Analysis of source code changes
CN106293675B (en) System static resource loading method and device
CN109308254B (en) Test method, test device and test equipment
CN112015430A (en) JavaScript code translation method and device, computer equipment and storage medium
CN111126019B (en) Report generation method and device based on mode customization and electronic equipment
US20120143893A1 (en) Pattern Matching Framework for Log Analysis
CN111831384A (en) Language switching method and device, equipment and storage medium
CN112162915A (en) Test data generation method, device, equipment and storage medium
Jiang et al. Towards reengineering web sites to web-services providers
CN110990274A (en) Data processing method, device and system for generating test case
US20090083300A1 (en) Document processing device and document processing method
CN115599359A (en) Code generation method, device, equipment and medium
CN108073401B (en) Method and device for executing business logic and electronic equipment
US20160266875A1 (en) Software automatic configuration apparatus, software automatic configuration method, and storage media
CN117008920A (en) Engine system, request processing method and device, computer equipment and storage medium
US20080005085A1 (en) Server Device and Search Method
Atsumi et al. An XML C source code interchange format for CASE tools
CN115757174A (en) Database difference detection method and device
CN113961192A (en) Code data processing method and device and electronic equipment
CN114816364A (en) Method, device and application for dynamically generating template file based on Swagger
US9471569B1 (en) Integrating information sources to create context-specific documents

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