A data processing method, device and storage medium
By generating and matching operator strings in Javascript, custom operator syntax is supported, the problem of not supporting custom operators in Javascript is solved, the readability of programming logical order is improved and special character naming is allowed, and the implementation of the Compatibility of normal operators.
Patent Information
- Application Number
- CN202011214884.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-11-04
- Publication Date
- 2024-12-10
- Estimated Expiration
- 2040-11-04
AI Technical Summary
Javascript does not support custom operators, which leads to poor readability of logical order in programming. Especially when using function simulation operators, the logical order of statements is not as clear as that of operators, and function naming is limited to specified characters, so special characters cannot be named. .
By obtaining the input string, generating the operator string, and matching and calling the corresponding operator functions in the registered operators, it supports custom operator syntax, increases the logical order readability of the operators, and allows the use of special Character naming.
It implements the use of custom operators in Javascript, improves the readability of programming logical order, and supports parameter nesting and mixed operations with ordinary operators, which is in line with the logical order readability similar to ordinary operators.
Smart Images

Figure CN113779311B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a data processing method, device and storage medium. Background Art
[0002] Operators are very common in programming languages. Usually, each language provides several built-in operators, such as "+, -, !, =", etc. However, the operators provided by each language are not exactly the same. For example, the ".." operator supported by Swift is not supported by Javascript. Because Javascript does not support custom operator functions, it is not feasible to use the ".." operator in Javascript.
[0003] In this case, you can achieve the same effect by creating a function in Javascript that has the same function as the ".." operator. For example, you can define range(1,100), and its calculation result is the same as the calculation result of 1..100 in Swift, both of which are arrays with values from 1 to 100, that is, [1,2,4,…,100]. However, compared with using functions and operators, the logical order of function syntax is not as clear as that of operators. For example, the expression (1..<100).count..1000 in Swift is simulated in Javascript as range(closedRange(1,100).length),1000). It can be seen that since functions can only pass parameters in parentheses, the logical order of statements is not as clear as operators, especially for longer statements. In addition, the semantics of operators are often a special calculation or logical judgment, while existing Javascript functions can only be named with characters supported by regulations (letters, Chinese, underscores, dollar signs), so functions cannot be named with special characters and are not specific. Summary of the invention
[0004] The embodiment of the present application provides a method for data processing, which overcomes the problem that custom operators cannot be used in the Javascript language.
[0005] The method includes:
[0006] Get the input string;
[0007] Using the acquired input string, generating an operator string corresponding to the input string, wherein the operator string includes the operator in the input string, and actual variable parameters in the input string are presented as character items in a first data format;
[0008] matching said operator in said operator string among said operators registered;
[0009] When a registered operator is matched, the operator function created for the specified operator is called to process the character items in the operator string, wherein the operator function is a function function that matches the function of the operator corresponding to the registered operator function.
[0010] Optionally, for each of the operators, the function function matching the function of the operator is used as the corresponding operator function, and a key-value pair including the function name of the operator function and the operator name of the operator is created;
[0011] The created mapping relationship between the key-value pairs is saved.
[0012] Optionally, the input string is parsed by executing a function through an operator to generate a first string array after removing the actual variable parameters, and each of the actual variable parameters in the input string extracted in sequence is used as a second string array;
[0013] Loop the first string array and add character items of the first data format at positions corresponding to the actual variable parameters of the first string array, wherein x starts from 0 and increases by 1 in each loop until the first string loop ends, so as to generate the operator string corresponding to the input string.
[0014] Optionally, an operator abstract structure with the operator string as the first index value is searched in the operator abstract structure library, and when the corresponding operator abstract structure is not found, the operator abstract structure is created for the operator string and saved in the operator abstract structure library with the operator string as the first index value.
[0015] Optionally, in the operator string, character items in the first data format directly connected to the operator except the first character item in the first data format are screened out, and a separator is added between the operator and the character item in the first data format;
[0016] In the operator character string, a structure character string consisting of the operator containing the space symbol and the character item of the first data format is screened out, and the operator name corresponding to the operator contained in the structure character string is used as the name attribute of the structure character string;
[0017] The x in the character item of the first data format of each of the structured character strings is stored as the second index value of the actual variable parameter.
[0018] Optionally, determine whether the leftmost side of the first character item in the first data format is a non-blank character, and if it is not a non-blank character, add the multi-operator identifier to the operator abstract structure, wherein the multi-operator identifier is the index value of the actual variable parameter corresponding to the x in the first character item in the first data format.
[0019] Optionally, when the matched operator abstract structure does not carry the multi-operator identifier, the structure string is obtained in the operator abstract structure, and based on the name attribute of the structure string, the corresponding operator function is obtained in the mapping relationship between the key-value pairs;
[0020] Based on the second index value contained in each structure string in the operator abstract structure, searching for the corresponding actual variable parameter in the second string array, and placing the actual variable parameter at the position where the corresponding character item of the first data format is located;
[0021] The operator function including the actual variable parameter is executed cyclically, and the operation result of the previous operator function is used as the first parameter of the next operator function.
[0022] Optionally, when the matched operator abstract structure carries the multi-operator identifier, the structure string is obtained in the operator abstract structure, and based on the name attribute of the structure string, the corresponding operator function is obtained in the mapping relationship between the key-value pairs;
[0023] Searching the corresponding actual variable parameter in the second string array based on the multi-operator identifier, and using the actual variable parameter as the first parameter of the first operator function;
[0024] Based on the second index value contained in each structure string in the operator abstract structure, searching for the corresponding actual variable parameter in the second string array, and placing the actual variable parameter at the position where the corresponding character item of the first data format is located;
[0025] The operator function including the actual variable parameter is executed cyclically, and the operation result of the previous operator function is used as the first parameter of the next operator function.
[0026] Optionally, the running result of the last operator function is output as the running result corresponding to the input string.
[0027] Optionally, the first data format is ${x} format.
[0028] In another embodiment of the present invention, a data processing device is provided, the device comprising:
[0029] The acquisition module is used to obtain the input string;
[0030] A generating module, configured to generate an operator string corresponding to the input string using the acquired input string, wherein the operator string includes the operator in the input string and actual variable parameters in the input string presented as character items in a first data format;
[0031] a matching module, for matching the operator in the operator string among the registered operators;
[0032] A calling module is used to call the operator function created for the specified operator to process the character items in the operator string when a registered operator is matched, wherein the operator function is a function function that matches the function of the operator corresponding to the registered operator function.
[0033] In another embodiment of the present invention, a non-transitory computer-readable storage medium is provided, wherein the non-transitory computer-readable storage medium stores instructions, and when the instructions are executed by a processor, the processor executes each step in the above-mentioned data processing method.
[0034] In another embodiment of the present invention, a terminal device is provided, including a processor, wherein the processor is used to execute each step in the above-mentioned data processing method.
[0035] Based on the above embodiment, firstly, an input string is obtained, and an operator string corresponding to the input string is generated using the obtained input string, wherein the operator string includes the operator in the input string, and the actual variable parameter in the input string is presented as a character item in the first data format, and the operator in the operator string is matched in the registered operators, and when the registered operator is matched, the operator function created for the specified operator is called to process the character item in the operator string, wherein the operator function is a function function that matches the function of the operator corresponding to the registered operator function. The embodiment of the present application supports encapsulation of various custom operator logics and custom operator function names by adding custom operator syntax, thereby improving the readability of the logical order of the operator. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0037] Figure 1 A schematic flow chart of a data processing method provided for embodiment 100 of the present application is shown;
[0038] Figure 2 A schematic diagram showing a specific process of registering an operator provided by embodiment 200 of the present application;
[0039] Figure 3 A schematic diagram showing a specific process of creating an operator abstract structure provided in Embodiment 300 of the present application;
[0040] Figure 4 A schematic diagram showing a specific process of a data processing method provided by embodiment 400 of the present application;
[0041] Figure 5 A schematic diagram showing a data processing device further provided by the embodiment 500 of the present application;
[0042] Figure 6 A schematic diagram of a terminal device provided in embodiment 600 of the present application is shown. DETAILED DESCRIPTION
[0043] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0044] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the implementation of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0045] Based on the problems in the prior art, the embodiments of the present application provide a method for data processing, which is mainly applicable to the field of computer technology. By utilizing the existing Tagged Templates syntax of Javascript and independently designing a new custom operator syntax, it supports the encapsulation of various custom operator logics, and supports necessary features such as parameter nesting and mixed operations with ordinary Javascript operators. The overall readability is similar to that of ordinary operators to implement a method for data processing. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The application scenarios of the embodiments of the present application are mainly based on the JavaScript language environment. JavaScript (abbreviated as "JS") is a lightweight, interpreted or just-in-time compiled high-level programming language with function priority. It is the main programming language for front-end development technology and is widely used. As Figure 1 As shown, it is a flow chart of a method for data processing provided by embodiment 100 of the present application. Among them, the first data format in the embodiment of the present application is ${x} format. The detailed steps of the method are as follows:
[0046] Step S11, obtaining an input character string.
[0047] In this step, after registering the function function matching the function of at least one operator as the corresponding operator function, the input string consisting of the operator and the actual variable parameters to be operated is used. The operator in the input string can be a registered custom operator or a common operator in the Javascript language.
[0048] Step S12: Generate an operator string corresponding to the input string using the acquired input string, wherein the operator string includes the operator in the input string and the actual variable parameters in the input string are presented as character items in the first data format.
[0049] In this step, the input string is initially processed using the operator execution function. Specifically, the operator is retained by filtering out the actual variable parameters in the input string, and the actual variable parameters are replaced with character items in the first data format. Among them, the initial value of x in the first data is 0, and it is cyclically added by 1 according to the number of operators. Further, the string including the operator and the character items in the first data format after the above processing is determined as the operator string corresponding to the input string. Among them, the first data format in the embodiment of the present application is ${x} format.
[0050] Step S13, matching the operator in the operator string among the registered operators.
[0051] In this step, based on the generated operator string, if it contains a custom operator, it is necessary to match the operator with the registered operators to determine the operation logic of the operator, and use the operator function corresponding to the operator to process the operator in the operator string.
[0052] Step S14, when a registered operator is matched, the operator function created for the specified operator is called to process the character items in the operator string, wherein the operator function is a function function that matches the function of the operator corresponding to the registered operator function.
[0053] In this step, before obtaining the input string, a function function matching the function of at least one operator is registered as the corresponding operator function. Furthermore, when the operator execution function matches the registered operator, it calls the operator function and extracts the corresponding actual variable parameters, processes the character items in the operator string according to the nested logic of each operator in the operator string, and generates an operation result.
[0054] As described above, based on the above embodiment, specifically, firstly, an input string is obtained, and an operator string corresponding to the input string is generated using the obtained input string, wherein the operator string includes the operator in the input string, and the actual variable parameter in the input string is presented as a character item in the first data format, and the operator in the operator string is matched in the registered operators, and when the registered operator is matched, the operator function created for the specified operator is called to process the character item in the operator string, wherein the operator function is a function function that matches the function of the operator corresponding to the registered operator function. The embodiment of the present application supports encapsulation of various custom operator logics and custom operator function names by adding custom operator syntax, thereby improving the readability of the logical order of the operator.
[0055] For ease of description, the following first explains how the operators in the embodiments of the present application are used in various scenarios:
[0056] (1) The most commonly used binary operators:
[0057]
[0058]
[0059] (2) Binary operators with multiple parameters on the right side:
[0060]
[0061] (3) Nested scenarios:
[0062]
[0063] Nested execution is provided by default for Tagged Templates syntax, and there is no need to implement it yourself. By using nesting, you can implement a variety of syntax logics with very strong adaptability, for example:
[0064] o`${o`${1}..<(${o`${100}..${o`${100}..${200}`.length}`})`.length}..${1000}`; In addition, the o function can also be mixed with common JavaScript operators:
[0065] o`${100}..${200}`.length+100*2>=1000
[0066] (4) Scenarios with unary operators:
[0067]
[0068]
[0069] (5) Mixed execution with normal Javascript operators:
[0070] o`${o`${1}..<${100}`.length}..${1000}`;
[0071]
[0072] Furthermore, in the embodiment of the present application, the user-defined operator is first registered, such as Figure 2 As shown, it is a schematic diagram of the specific process of registering an operator provided by the embodiment 200 of the present application. The detailed process of the specific process is as follows:
[0073] S201, write a functional function as an operator function.
[0074] Here, for each operator, a function matching the function of the operator is used as the corresponding operator function. Specifically, the operator function can be written using a Javascript function. For example, the ".." operator in o`${1}..${10}` can be written as the following function:
[0075]
[0076] The function name of the operator function and the operator name of the operator can be written arbitrarily.
[0077] S202, register the operator function using the registerOperator method.
[0078] Here, each operator is essentially a Javascript function. Use the registerOperator method to globally register the custom operator function, as shown below:
[0079] function registerOperator(operatorName,operatorFunc){
[0080] OperatorMap[operatorName]=operatorFunc;
[0081] }
[0082] Use it to register the operator:
[0083] registerOperator('..',range), where "range" is the function name of the operator function of '..'.
[0084] S203: Save the mapping relationship between the created key-value pairs.
[0085] Here, a key-value pair containing the function name of the operator function and the operator name of the operator is created. Specifically, the OperatorMap in the aforementioned step S202 is an operator function Map, which is a global Javascript object structure that can be used to save the mapping relationship between the registered operator functions and key-value pairs:
[0086]
[0087]
[0088] The embodiment of the present application completes the specific process of registering an operator based on the above steps.
[0089] In addition, the steps to create the corresponding operator abstract structure for the operator string are as follows Figure 3 As shown, it is a schematic diagram of the specific process of creating an operator abstract structure provided in the embodiment 300 of the present application. The detailed process of the specific process is as follows:
[0090] S301, input the operator string and initialize it.
[0091] Here, if the operator string is Initialize an AST object using the Javascript empty object for the operator string: const ast = {}.
[0092] S302, generating an expression including a structure character string.
[0093] Here, in the operator string, the character items of the first data format directly connected to the operator except the first character item of the first data format are filtered out, and a separator is added between the operator and the character items of the first data format. The operator string is processed to generate a structure string of the format "xxx(${x})". Specifically, the "${x}" string "${0}" at the far left of the operator string is extracted. Note that there cannot be non-blank characters on its left side. The extracted string is Furthermore, use regular expressions to extract all strings in the format of "xxx${x}" and generate an array ['..${1}','..<${2}']. Add a separator such as parentheses to the outside of "${x}" of all items in the array, and then fill in the string again This generates an expression containing a structured string.
[0094] S303, filter out the structure character string.
[0095] Here, in the operator string, the structure string consisting of the operator containing the space symbol and the character item of the first data format is screened out. Specifically, the regular expression is used to extract all the structure strings of "xxx(${x})", and the result is an array
[0096] S304: Determine whether a multi-operator identifier should be added.
[0097] In this step, it is determined whether the leftmost character of the first character item of the first data format is a non-blank character, and if it is not a non-blank character, a multi-operator identifier is added to the operator abstract structure, where the multi-operator identifier is the index value of the actual variable parameter corresponding to x in the first character item of the first data format. The multi-operator identifier is used to indicate whether the operator string contains a multi-operator.
[0098] In addition to conventional binary operators, the embodiments of the present application can also support unary operators. Examples of operator strings are as follows:
[0099]
[0100] In the above example It is a unary operator, which is located on the left side of the parameter when used. After conversion to the operator abstract structure, the parameters are described as follows:
[0101]
[0102] Unary operators are usually set at the far left of the operator execution function, as shown in the following example:
[0103]
[0104]
[0105] Furthermore, it is checked whether "${x}" can be extracted from the leftmost portion of the operator string. If so, it is determined that the first operator is a binary operator; otherwise, the first operator is a unary operator.
[0106] This example is "${x}" with a non-blank character on the left: At this time, no multiple operator identifier is added to the operator abstract structure. If the first operator is a binary operator, a multiple operator identifier needs to be added to the outermost layer of the operator abstract structure, with the value of "${x}" where x means the parameter number:
[0107] const ast={
[0108] argIndex:0
[0109] }
[0110] S305, setting the name attribute of the structure string.
[0111] In this step, the operator name corresponding to the operator contained in the structure string is used as the name attribute of the structure string. Specifically, an operators array structure is created in the operator abstract structure, an operator object structure is created for each structure string in the array, and the non-parentheses part is extracted from each "xxx(${x})" and the leading and trailing spaces are removed to obtain the operator name:
[0112]
[0113]
[0114] S306: Store x in the character item of the first data format of each structured character string as the second index value of the actual variable parameter.
[0115] Here, each operator generally has at least one actual variable parameter, usually two, namely the left and right sides of the binary operator (the startTime and endTime below are parameters):
[0116]
[0117] The operator in the embodiment of the present application may also have a third or more actual variable parameters, in which case parentheses need to be added to the right of the operator:
[0118]
[0119] The operator function parameters are also changed to 3:
[0120]
[0121] Furthermore, in each structure string, check whether there is a comma in the parentheses. If there is a comma, the right side of the operator contains multiple actual variable parameters; if there is no comma, the right side of the operator has only one actual variable parameter. If there are multiple parameters on the right side of the operator, separate each parameter object with a comma, and then put multiple parameter objects in the params array in the operator object structure, and set the second index value, which is x of "${x}".
[0122] For operator string The abstract structure of the operator is:
[0123]
[0124]
[0125] If there is only one actual variable parameter on the right side of the operator, then there is only one parameter object in the params array of each operator object structure, and the AST is changed as follows:
[0126]
[0127]
[0128] Take the following operator string:
[0129]
[0130] After conversion to the operator abstract structure, the parameters are described as follows:
[0131]
[0132]
[0133] Let's take another example of a multi-parameter operator. When multiple parameters are passed to the right side of the operator, parentheses are required:
[0134]
[0135] After conversion to the operator abstract structure, the parameters are described as follows:
[0136]
[0137]
[0138] The embodiment of the present application completes the specific process of creating an operator abstract structure based on the above steps.
[0139] Furthermore, the operator executes a function to process the input string. Figure 4 As shown, it is a schematic diagram of a specific process of a data processing method provided by embodiment 400 of the present application. The detailed process of the specific process is as follows:
[0140] S401, inputting a first string array and a second string array of strings to be input into an operator execution function.
[0141] Here, after obtaining the input string, the input string is parsed through the operator execution function to generate a first string array after removing the actual variable parameters, and the actual variable parameters in the input string extracted in sequence are used as the second string array. Specifically, the operator execution function is implemented based on the TaggedTemplates syntax of Javascript. The way to use it is as follows:
[0142]
[0143] Among them, the o function only needs to be defined once globally, and is the operator execution function. Its parameter definition structure follows the provisions of the Tagged Templates syntax:
[0144] function o(operatorExprs,...args){
[0145] }
[0146] The operatorExprs is the first string array, and its value is the string array corresponding to the string to be input after removing the actual variable parameters:
[0147] args is the second string array, and its value is the actual variable parameter corresponding to each first data extracted in sequence: [startTime, endTime].
[0148] S402, generating an operator string corresponding to the input string.
[0149] Here, the first string array is looped, and character items of the first data format are added to the positions corresponding to the actual variable parameters of the first string array, where x starts from 0 and increases by 1 each time the loop ends until the first string loop ends, so as to generate an operator string corresponding to the input string. Specifically, the first string array operatorExprs of the string execution function, i.e., the function o, is used to generate an operator string corresponding to the input string. For example, for the first string array operatorExprs, The generated operator string is Among them, the first string array operatorExprs is looped, and a character item of the first data format is added at the position of each actual variable parameter (x starts from 0 and increases by 1 in each loop), and no addition is made when the last item is determined, so as to generate an operator string containing the operator in the input string and the actual variable parameters in the input string presented as character items of the first data format.
[0150] S403: Search the operator abstract structure with the operator string as the first index value in the operator abstract structure library.
[0151] Here, the operator abstract structure is the abstract syntax tree (abstract syntaxcode, AST) method after the operator string is parsed. AST is a tree representation of the abstract syntax structure of the source code, and each node on the tree represents a structure in the source code. If the operator string has generated a corresponding operator abstract structure, the operator string will be mapped to the corresponding operator abstract structure as the first index value to facilitate search. Specifically, when the o function (operator execution function) is executed, if the same operator string is parsed into the operator abstract structure each time, there may be repeated operations, which will reduce the operating efficiency. Therefore, an operator abstract structure library is established to cache the operator strings that have been converted into operator abstract structures. An AST Map object can be created globally as an operator abstract structure library for storage, and the operator string can be used as the first index value. For example:
[0152]
[0153] Furthermore, when found, the operator abstract structure is directly used.
[0154] S404: When the operator is not found, create a corresponding operator abstract structure for the operator string.
[0155] Here, when the corresponding operator abstract structure is not found, an operator abstract structure is created for the operator string, and the operator string is saved in the operator abstract structure library with the operator string as the first index value. The step of creating the operator abstract structure is described in Example 300.
[0156] S405, determining whether the operator abstract structure carries a multi-operator identifier.
[0157] Here, the multi-operator identifier is used to indicate whether the operator abstract structure contains a multi-operator. Specifically, in the operator abstract structure, it is determined whether the leftmost character of the first character item of the first data format is a non-blank character, and if it is not a non-blank character, a multi-operator identifier is added to the operator abstract structure, wherein the multi-operator identifier is the index value of the actual variable parameter corresponding to x in the first character item of the first data format. Furthermore, the process of adding a multi-operator is added when creating a corresponding operator abstract structure for the operator string.
[0158] S406, obtaining the operator function corresponding to the operator abstract structure.
[0159] In this step, when the matched operator abstract structure does not carry a multi-operator identifier, a structure string is obtained in the operator abstract structure, and based on the name attribute of the structure string, a corresponding operator function is obtained in the mapping relationship between key-value pairs.
[0160] S407, obtaining actual variable parameters corresponding to the operator abstract structure.
[0161] Here, based on the second index value contained in each structure string in the operator abstract structure, the corresponding actual variable parameter is searched in the second string array, and the actual variable parameter is placed at the position where the corresponding character item of the first data format is located.
[0162] S408, determining whether the current operator function is the last operator function of the input string.
[0163] Here, the operator functions containing actual variable parameters are executed cyclically, and the operation result of the previous operator function is used as the first parameter of the next operator function. If not, return to continue to execute steps S406 to S408.
[0164] S409, obtaining actual variable parameters corresponding to the multivariate operation identifier.
[0165] Here, when the matched operator abstract structure carries a multiple operator identifier, the corresponding actual variable parameter is searched in the second string array based on the multiple operator identifier, and the actual variable parameter is used as the first parameter of the first operator function. Specifically, if it is judged to be a binary operator, that is, there is a first operation result, then after the step of obtaining the operator function corresponding to the operator abstract structure, first use the multiple operation identifier argIndex to take out the corresponding parameter from the second string array args array according to the index value, and place it in the first parameter of the first operator function. And this step is only executed once. Further, the step of obtaining the actual variable parameter corresponding to the operator abstract structure and the subsequent steps are executed.
[0166] S410, outputting the running result of the last operator function as the running result corresponding to the input string.
[0167] This application implements the above-mentioned data processing method based on the above-mentioned steps.
[0168] The embodiment of the present application provides a feasible implementation scheme for the Javascript custom operator function. Based on the existing Tagged Templates syntax implementation of Javascript, the logical order readability of the operator syntax can be maintained. For example, (1..<100).count..1000 in Swift can be written as o`${o`${1}..<${100}`.length}..${1000}`. At the same time, it also supports mixed use with various common Javascript operators, and the syntax can adapt to various complex scenarios, such as o`${startTime+1000}..(${endTime-1000},${o`sqrt${2500}`*1000})`.
[0169] In addition, the operators in the embodiments of the present application can also process multiple actual variable parameters, and support the nested use of operators in parameters, which can be written as: o`${1}>...<(${100},${o`${50}..${10}`})`. The operators can be named with various special characters, such as emoji icons. For example, if you want to find the number of milliseconds between the start time and the end time, you can write ( is an operator):
[0170] The operator syntax design scheme adopted in the embodiment of this application is a self-developed design that adds a new custom operator syntax based on the existing TaggedTemplates syntax of Javascript, supports the encapsulation of various custom operator logics, and supports parameter nesting and mixed operations with ordinary Javascript operators and other necessary features. The overall readability of the logical sequence is similar to that of ordinary operators, and it is a good enhancement scheme for Javascript syntax. The custom operator implementation scheme adopted is a self-developed design, that is, it includes the AST process for creating and caching a dedicated string abstract structure, the design of each attribute of the AST, and the implementation logic of the final operator execution function.
[0171] In addition, the operator execution order priority processing scheme used in the embodiment of the present application is also relatively unique. Its priority rule is mainly: the operation order of multiple operators is from left to right. If you want to run one of the operators first, you can nest it with "${}", which is very convenient. For example:
[0172] 1. Run from left to right by default
[0173]
[0174] 2. Let the right side run first
[0175]
[0176] 3. Run the left side first (for example, other operations need to be superimposed after the operator result is obtained on the left side)
[0177]
[0178] Based on the same inventive concept, the embodiment 500 of the present application further provides a data processing device, wherein: Figure 5 As shown, the device comprises:
[0179] An acquisition module 51 is used to acquire an input string;
[0180] A generating module 52, configured to generate an operator string corresponding to the input string using the acquired input string, wherein the operator string includes the operator in the input string and the actual variable parameter in the input string presented as a character item in a first data format;
[0181] A matching module 53, for matching the operator in the operator string among the registered operators;
[0182] The calling module 54 is used to call the operator function created for the specified operator to process the character items in the operator string when a registered operator is matched, wherein the operator function is a function function that matches the function of the operator corresponding to the registered operator function.
[0183] In this embodiment, the specific functions and interaction methods of the acquisition module 51, the generation module 52, the matching module 53 and the calling module 54 can be found in Figure 1 The description of the corresponding embodiments will not be repeated here.
[0184] like Figure 6 As shown, another embodiment 600 of the present application further provides a terminal device, including a processor 601, wherein the processor 601 is used to execute the steps of the above-mentioned data processing method. Figure 6 It can also be seen that the terminal device provided in the above embodiment further includes a non-transitory computer-readable storage medium 602, on which a computer program is stored, and the computer program executes the steps of the above data processing method when it is run by the processor 601. In practical applications, the terminal device can be one or more computers, as long as it includes the above computer-readable medium and processor.
[0185] Specifically, the storage medium can be a general storage medium, such as a mobile disk, a hard disk, and FLASH, etc. When the computer program on the storage medium is run, each step in the above-mentioned data processing method can be executed. In practical applications, the computer-readable medium can be included in the device / apparatus / system described in the above embodiments, or it can exist independently without being assembled into the device / apparatus / system. The above-mentioned computer-readable storage medium carries one or more programs, and when the above-mentioned one or more programs are executed, each step in the above-mentioned data processing method can be executed.
[0186] According to the embodiments disclosed in the present application, the computer-readable storage medium may be a non-volatile computer-readable storage medium, for example, it may include but is not limited to: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof, but it is not used to limit the scope of protection of the present application. In the embodiments disclosed in the present application, the computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system, apparatus, or device.
[0187] The flow chart and block diagram in the accompanying drawings of the present application show the possible architecture, function and operation of the system, method and computer program product according to the various embodiments disclosed in the present application. In this regard, each box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the above-mentioned module, program segment or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the box can also occur in the order marked in different drawings. For example, the boxes represented by two connections can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0188] Those skilled in the art will appreciate that the features described in the various embodiments and / or claims of the present disclosure may be combined and / or combined in a variety of ways, even if such combinations or combinations are not explicitly described in the present application. In particular, without departing from the spirit and teachings of the present application, the features described in the various embodiments and / or claims of the present application may be combined and / or combined in a variety of ways, and all of these combinations and / or combinations fall within the scope disclosed in the present application.
[0189] Finally, it should be noted that the above-described embodiments are only specific implementation methods of the present application, which are used to illustrate the technical solutions of the present application, rather than to limit them. The protection scope of the present application is not limited thereto. Although the present application is described in detail with reference to the above-described embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still change the technical solutions recorded in the above-described embodiments within the technical scope disclosed in the present application, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these changes, modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.
Claims
1. A method of data processing, It is characterized in that The method includes: Get the input string; Using the acquired input string, generating an operator string corresponding to the input string, wherein the operator string includes the operator in the input string and the actual variable parameters in the input string are presented as character items in a first data format; matching said operator in said operator string among said operators registered; When a registered operator is matched, calling an operator function created for the specified operator to process the character item in the operator string, wherein the operator function is a function function that matches the function of the operator corresponding to the registered operator function; The step of generating an operator string corresponding to the input string includes: Parsing the input string by executing a function through an operator to generate a first string array after removing the actual variable parameters, and using each of the actual variable parameters in the input string extracted in sequence as a second string array; Loop the first string array, and add character items of the first data format at the positions corresponding to the actual variable parameters of the first string array, wherein the first data format is in the format of ${x}, and x starts from 0 and increases by 1 in each loop until the first string loop ends, so as to generate the operator string corresponding to the input string.
2. The method according to claim 1, It is characterized in that Before obtaining the input string, the method further includes: For each of the operators, taking the function function that matches the function of the operator as the corresponding operator function, and creating a key-value pair including the function name of the operator function and the operator name of the operator; The created mapping relationship between the key-value pairs is saved.
3. The method according to claim 2, It is characterized in that The step of matching the operator in the operator string among the registered operators comprises: An operator abstract structure with the operator string as the first index value is searched in the operator abstract structure library, and when the corresponding operator abstract structure is not found, the operator abstract structure is created for the operator string, and is saved in the operator abstract structure library with the operator string as the first index value.
4. The method according to claim 3, It is characterized in that The step of creating the operator abstract structure for the operator string comprises: In the operator string, character items in the first data format directly connected to the operator except the first character item in the first data format are screened out, and a separator is added between the operator and the character item in the first data format; In the operator character string, a structure character string consisting of the operator containing the space symbol and the character item of the first data format is screened out, and the operator name corresponding to the operator contained in the structure character string is used as the name attribute of the structure character string; The x in the character item of the first data format of each of the structured character strings is stored as the second index value of the actual variable parameter.
5. The method according to claim 4, It is characterized in that Before the step of filtering out the character items in the first data format directly connected to the operator except the first character item in the first data format, the method further comprises: Determine whether the leftmost side of the first character item in the first data format is a non-blank character, and if it is not a non-blank character, add a multi-operator identifier to the operator abstract structure, wherein the multi-operator identifier is the index value of the actual variable parameter corresponding to the x in the first character item in the first data format.
6. The method according to claim 5, It is characterized in that The step of calling the operator function created for the specified operator to process the character item in the operator string comprises: When the matched operator abstract structure does not carry the multi-operator identifier, obtaining the structure string in the operator abstract structure, and based on the name attribute of the structure string, obtaining the corresponding operator function in the mapping relationship between the key-value pairs; Based on the second index value contained in each structure string in the operator abstract structure, searching for the corresponding actual variable parameter in the second string array, and placing the actual variable parameter at the position where the corresponding character item of the first data format is located; The operator function including the actual variable parameter is executed cyclically, and the operation result of the previous operator function is used as the first parameter of the next operator function.
7. The method according to claim 5, It is characterized in that The step of calling the operator function created for the specified operator to process the character item in the operator string also includes: When the matched operator abstract structure carries the multi-operator identifier, the structure string is obtained in the operator abstract structure, and based on the name attribute of the structure string, the corresponding operator function is obtained in the mapping relationship between the key-value pairs; Searching the corresponding actual variable parameter in the second string array based on the multi-operator identifier, and using the actual variable parameter as the first parameter of the first operator function; Based on the second index value contained in each structure string in the operator abstract structure, searching for the corresponding actual variable parameter in the second string array, and placing the actual variable parameter at the position where the corresponding character item of the first data format is located; The operator function including the actual variable parameter is executed cyclically, and the operation result of the previous operator function is used as the first parameter of the next operator function.
8. The method according to claim 6 or 7, It is characterized in that After the step of calling the operator function created for the specified operator to process the character item in the operator string, the method further comprises: The running result of the last operator function is output as the running result corresponding to the input string.
9. A data processing device, It is characterized in that The device includes: The acquisition module is used to obtain the input string; A generating module, configured to generate an operator string corresponding to the input string using the acquired input string, wherein the operator string includes the operator in the input string and actual variable parameters in the input string presented as character items in a first data format; a matching module, for matching the operator in the operator string among the registered operators; A calling module, for calling an operator function created for a specified operator to process the character item in the operator string when a registered operator is matched, wherein the operator function is a function function that matches the function of the operator corresponding to the registered operator function; The generating module generates an operator string corresponding to the input string, including: Parsing the input string by executing a function through an operator to generate a first string array after removing the actual variable parameters, and using each of the actual variable parameters in the input string extracted in sequence as a second string array; Loop the first string array, and add character items of the first data format at the positions corresponding to the actual variable parameters of the first string array, wherein the first data format is in the format of ${x}, and x starts from 0 and increases by 1 in each loop until the first string loop ends, so as to generate the operator string corresponding to the input string.
10. A non-transitory computer-readable storage medium, It is characterized in that The non-transitory computer-readable storage medium stores instructions, which, when executed by a processor, cause the processor to perform each step in the data processing method according to any one of claims 1 to 8.
11. A terminal device, It is characterized in that The method comprises a processor, wherein the processor is used to execute each step in the data processing method according to any one of claims 1 to 8.
