CN112748988A - Custom function operation method and system based on domain-specific language - Google Patents

Custom function operation method and system based on domain-specific language Download PDF

Info

Publication number
CN112748988A
CN112748988A CN202110110928.5A CN202110110928A CN112748988A CN 112748988 A CN112748988 A CN 112748988A CN 202110110928 A CN202110110928 A CN 202110110928A CN 112748988 A CN112748988 A CN 112748988A
Authority
CN
China
Prior art keywords
typescript
function
original code
user
preset
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
CN202110110928.5A
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.)
Zhejiang Taimei Medical Technology Co Ltd
Original Assignee
Zhejiang Taimei Medical Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Zhejiang Taimei Medical Technology Co Ltd filed Critical Zhejiang Taimei Medical Technology Co Ltd
Priority to CN202110110928.5A priority Critical patent/CN112748988A/en
Publication of CN112748988A publication Critical patent/CN112748988A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45504Abstract machines for programme code execution, e.g. Java virtual machine [JVM], interpreters, emulators
    • G06F9/45508Runtime interpretation or emulation, e g. emulator loops, bytecode interpretation
    • G06F9/45512Command shells
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • G06F8/315Object-oriented languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • Stored Programmes (AREA)

Abstract

The application provides a custom function operation method, a custom function operation system and a computer readable medium based on a domain specific language. The method comprises the following steps: receiving an original code input by a user and a function type of the original code, wherein the original code uses a preset domain-specific language based on a TypeScript language and calls a packaged logic unit in a resource manager; registering the TypeScript declaration file in a TypeScript compiler; processing the original code based on the TypeScript declaration file, the first preset grammar and the second preset grammar, and outputting a script and a second custom logic unit declaration file; adding the second self-defined logic unit declaration file into the first self-defined logic unit declaration file; uploading the script to the running tool; triggering an operation tool to operate a script; and receiving the returned operation result. The method can realize and operate the user-defined complex function with lower learning cost of the user.

Description

Custom function operation method and system based on domain-specific language
Technical Field
The present application relates to the field of computer technologies, and in particular, to a method and a system for operating a custom function based on a domain specific language, and a computer readable medium.
Background
When a user uses functions in a system, the problem that the default processing flow or function of the system cannot meet the requirements of the user is often encountered. In this case, the user needs to implement the functions required by the user by the custom functions, but there is a limit to the functions that can be customized in the system.
In the prior art, the most common processing method for a user to realize a custom function is realized by a general programming language, for example, Java, JavaScript, C # and the like, and the system only needs to provide one library for the user to call. The common programming language approach enables the definition of complex logic. However, the learning cost of the general-purpose programming language is high for the general-purpose user. The user also needs to learn a programming language in order to use the system, which is too difficult to use.
In some cases, the rules that the user wants to use may be executed by standard functions built in the system, but the number of standard functions is limited, and cannot cover all practical application scenarios. Therefore, those skilled in the art need a method for running a customized function, which can implement and run a customized complex function with a low user learning cost, and is suitable for a larger-scale system, in which the user use cost does not rapidly increase with the expansion of the system scale.
Disclosure of Invention
The technical problem to be solved by the application is a custom function operation method, which can realize and operate a custom complex function with lower user learning cost.
In order to solve the above problem, the present application provides a method for running a custom function based on a domain-specific language, running in a JavaScript virtual machine, including: receiving original code input by a user and a function type of the original code, wherein the original code uses a preset domain-specific language based on a TypeScript language and calls one or more encapsulated logic units in a resource manager, the grammar of the preset domain-specific language comprises a first preset grammar and a second preset grammar, the first preset grammar is used for restoring asynchronous operation, the second preset grammar is used for judging the function type, and the encapsulated logic units comprise attributes and methods of classes; registering a TypeScript declaration file into the TypeScript compiler, wherein the TypeScript declaration file contains grammar rules of the preset domain-specific language, the TypeScript declaration file including any one or more of: the system logic unit declaration file, the tool logic unit declaration file and the first custom logic unit declaration file; processing the original code based on the TypeScript declaration file, the first preset grammar and the second preset grammar and outputting a corresponding executable JavaScript script and a second custom logic unit declaration file; adding the second custom logic unit declaration file into the first custom logic unit declaration file; uploading the executable JavaScript script to a running tool; triggering the running tool to run the executable JavaScript and obtain a corresponding running result; and receiving the operation result returned by the operation tool.
In an embodiment of the application, the step of processing the original code based on the TypeScript declaration file, the first preset syntax, and the second preset syntax and outputting a corresponding executable JavaScript script and a second custom logic unit declaration file includes: converting the original code into a corresponding abstract syntax tree; verifying the original code according to the TypeScript declaration file based on the TypeScript compiler, and outputting error information and ending if the verification fails; verifying whether the function type of the abstract syntax tree is consistent with the function type of the original code input by the user or not according to the second preset syntax, and if not, outputting error information and ending; converting the abstract syntax tree according to the first preset syntax; and outputting a corresponding executable JavaScript script and a second custom logic unit statement file according to the converted abstract syntax tree.
In an embodiment of the application, the grammar of the preset domain-specific language further includes a preset translation grammar, and the method further includes: and translating the converted abstract syntax tree according to the preset translation syntax, and outputting a translation result for a user to check.
In an embodiment of the application, the converting the abstract syntax tree according to the first preset syntax is performed by a Babel compiler; the converting the abstract syntax tree according to the first preset syntax includes: traversing all functions in the abstract syntax tree and judging whether each function is an asynchronous function, if so, adding an await keyword for the function, otherwise, not adding the await keyword for the function; and adding a corresponding packaging function body for the abstract syntax tree, and judging whether each function in the abstract syntax tree is added with the await keywords, if so, adding the async keywords for the function, and if not, not adding the async keywords for the function.
In an embodiment of the application, the verifying whether the function type of the abstract syntax tree is consistent with the function type of the original code input by the user according to the second preset syntax is performed by a Babel compiler; the verifying whether the function type of the abstract syntax tree is consistent with the function type of the original code input by the user according to the second preset syntax includes: searching a return state type through a traversal module of the Babel compiler, and judging a function type of an original code input by the user; when the function type of the original code input by the user is a condition type, if the return state type cannot be found, the verification is not passed, if the return state type is found, whether the parameter of the return state type is a Boolean type or not is judged, if the parameter is the Boolean type, the verification is passed, and if the parameter is not the Boolean type, the verification is not passed; when the function type of the original code input by the user is a calculation type, if the return state type cannot be found, the verification is passed, and if the return state type is found, the verification is not passed; and when the function type of the original code input by the user is the action type, if the return state type is found, the verification is passed, and if the return state type is not found, the verification is not passed.
In an embodiment of the application, the method further runs in a TypeScript editor, wherein the TypeScript editor comprises an edit box; the receiving of the original code input by the user and the function type of the original code are receiving the original code input by the user and the function type of the original code sent by the TypeScript editor; the method further comprises the following steps: registering the TypeScript declaration file in the TypeScript editor; responding to an input request of a user, and loading the edit box; receiving an original code input in the edit box by a user and a function type of the original code; converting the original code into a corresponding abstract syntax tree; verifying the abstract syntax tree according to the TypeScript declaration file, and outputting error information and ending if the abstract syntax tree is not verified; and responding to a saving request of a user, and sending the original code, the function type of the original code and the TypeScript declaration file to the TypeScript compiler.
In an embodiment of the present application, the method further includes: and when the original code is input into the edit box by the user, matching in the TypeScript declaration file according to the content currently input by the user, and displaying a matching result in the edit box to perform logic unit prompting on the user.
In an embodiment of the application, the TypeScript editor includes a first error reporting function and a second error reporting function, where the first error reporting function is an error reporting function of the TypeScript editor, and the second error reporting function is a preset custom error reporting function, and is configured to determine whether an error is related to the second preset syntax according to the error information; the method further comprises the following steps: when the error information appears, calling the second error reporting function to judge whether the error is related to the second preset grammar according to the error information; if so, eliminating the error information; and if the error message is not relevant, calling the first error reporting function and sending the error message to the first error reporting function.
In an embodiment of the present application, the error information includes an error prompt message and error location information, where the error prompt message is used to prompt a user that an error occurs in the edit box, and the error location information is used to prompt a location of the error where the user is located in the edit box.
In an embodiment of the application, before the registering the TypeScript declaration file in the TypeScript compiler, the method further includes: and receiving the TypeScript declaration file sent by the TypeScript editor.
In order to solve the above technical problem, the present application further provides a custom function operating system based on the domain specific language, including: a memory for storing instructions executable by the processor; and a processor for executing the instructions to implement the method as described above.
To solve the above technical problem, the present application also provides a computer readable medium storing computer program code, which when executed by a processor implements the method as described above.
Compared with the prior art, the method, the system and the computer readable medium for operating the custom function based on the domain-specific language realize the custom function of the user and operate by using the DSL language and the resource manager, so that common users can realize the custom function and operate the function with lower learning cost. Moreover, when the system scale is enlarged to a certain degree, the DSL language and the resource manager still have higher use efficiency, and the use cost of a user cannot rapidly rise along with the enlargement of the system scale, so that the DSL language and the resource manager are very suitable for a larger-scale system.
Drawings
The accompanying drawings, which are included to provide a further understanding of the application and are incorporated in and constitute a part of this application, illustrate embodiment(s) of the application and together with the description serve to explain the principle of the application. In the drawings:
FIG. 1 is a flow chart diagram illustrating a method for running a custom function based on a domain-specific language according to an embodiment of the present application;
FIG. 2 is a flow chart illustrating a method for implementing step 105 according to an embodiment of the present application;
FIG. 3 is a flowchart illustrating a method for implementing step 106 according to an embodiment of the present application;
FIGS. 4 and 5 are schematic flow diagrams illustrating a method for executing a custom function based on a domain-specific language according to another embodiment of the present application;
FIG. 6 is an interface diagram illustrating logical unit prompting according to an embodiment of the present application;
FIG. 7 is a schematic diagram illustrating an error reporting flow of a custom function execution method based on a domain-specific language according to an embodiment of the present application;
FIG. 8 is a system block diagram illustrating a domain specific language based custom function execution system according to one embodiment of the present application;
FIG. 9 is an interface diagram illustrating a custom function execution system based on a domain specific language according to an embodiment of the application.
Detailed Description
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings used in the description of the embodiments will be briefly introduced below. It is obvious that the drawings in the following description are only examples or embodiments of the application, from which the application can also be applied to other similar scenarios without inventive effort for a person skilled in the art. Unless otherwise apparent from the context, or otherwise indicated, like reference numbers in the figures refer to the same structure or operation.
As used in this application and the appended claims, the terms "a," "an," "the," and/or "the" are not intended to be inclusive in the singular, but rather are intended to be inclusive in the plural unless the context clearly dictates otherwise. In general, the terms "comprises" and "comprising" merely indicate that steps and elements are included which are explicitly identified, that the steps and elements do not form an exclusive list, and that a method or apparatus may include other steps or elements.
The relative arrangement of the components and steps, the numerical expressions, and numerical values set forth in these embodiments do not limit the scope of the present application unless specifically stated otherwise. Meanwhile, it should be understood that the sizes of the respective portions shown in the drawings are not drawn in an actual proportional relationship for the convenience of description. Techniques, methods, and apparatus known to those of ordinary skill in the relevant art may not be discussed in detail but are intended to be part of the specification where appropriate. In all examples shown and discussed herein, any particular value should be construed as merely illustrative, and not limiting. Thus, other examples of the exemplary embodiments may have different values. It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, further discussion thereof is not required in subsequent figures.
Flow charts are used herein to illustrate operations performed by systems according to embodiments of the present application. It should be understood that the preceding or following operations are not necessarily performed in the exact order in which they are performed. Rather, various steps may be processed in reverse order or simultaneously. Meanwhile, other operations are added to or removed from these processes.
The application provides a custom function running method based on a domain-specific language, which runs in a JavaScript virtual machine. Fig. 1 is a flowchart illustrating a custom function execution method based on a domain-specific language according to an embodiment of the present application. As shown in fig. 1, the method for running a custom function based on a domain-specific language of the present embodiment includes the following steps 101-108:
step 101, receiving an original code input by a user and a function type of the original code, wherein the original code uses a preset domain-specific language based on a TypeScript language and calls one or more encapsulated logic units in a resource manager, syntax of the preset domain-specific language comprises a first preset syntax and a second preset syntax, the first preset syntax is used for restoring asynchronous operation, the second preset syntax is used for judging the function type, and the encapsulated logic unit comprises a class attribute and a method;
step 102, registering the TypeScript declaration file into a TypeScript compiler, wherein the TypeScript declaration file contains grammar rules of a preset domain-specific language, and the TypeScript declaration file comprises any one or more of the following: the system logic unit declaration file, the tool logic unit declaration file and the first custom logic unit declaration file;
step 112, processing the original code based on the TypeScript declaration file, the first preset grammar and the second preset grammar and outputting a corresponding executable JavaScript script and a second custom logic unit declaration file;
step 108, adding the second self-defined logic unit declaration file into the first self-defined logic unit declaration file;
step 109, uploading the executable JavaScript script to an operation tool;
step 110, triggering the running tool to run the executable JavaScript and obtaining corresponding running results; and
and step 111, receiving the operation result returned by the operation tool.
Wherein step 112 may comprise the following steps 103-107:
step 103, converting the original code into a corresponding abstract syntax tree;
step 104, verifying the original code according to the TypeScript declaration file based on the TypeScript compiler, and outputting error information and ending if the verification fails;
105, verifying whether the function type of the abstract syntax tree is consistent with the function type of the original code input by the user according to a second preset syntax, and if not, outputting error information and ending;
step 106, converting the abstract syntax tree according to the first preset syntax; and
and step 107, outputting the corresponding executable JavaScript script and the second custom logic unit statement file according to the converted abstract syntax tree.
Step 101 and step 112 described above are executed in a JavaScript virtual machine, which in an example may be node. js, where node. js is a JavaScript runtime based on Chrome V8 engine. The following describes the steps 101-112 in detail:
in step 101, a user inputs an original code using a preset domain-specific language based on the TypeScript language, and inputs a function type of the original code, and then the custom logic system receives the original code input by the user and the function type of the original code. The raw code calls one or more logical units encapsulated in the resource manager, the encapsulated logical units including attributes and methods of the class. By providing the encapsulated logic unit in the resource manager, a user can directly call the self-defined function when writing the self-defined function, and the compiling efficiency is improved.
Domain-Specific Language (DSL), also known as Domain-Specific Language, refers to a computer Language that is dedicated to a certain application Domain. Unlike the common cross-domain general-purpose computer language (GPL), domain-specific languages are used in only certain specific domains. Such as HTML for displaying web pages, and the Emac LISP language used by Emacs. The DSL language mentioned in the present application is a DSL language which is specially designed in advance for a specific scenario and a specific system, taking TypeScript as a basic language, removing some grammars that are difficult to understand and grasp by a general user (referring to a person without professional programming ability), and adding a grammar rule that can be conveniently used by the general user. It should be noted that those skilled in the art can design DSL languages suitable for other specific scenarios and specific systems without departing from the spirit of the present application, which is not limited herein.
The syntax of the preset domain specific language in this embodiment at least includes a first preset syntax and a second preset syntax, where the first preset syntax is used to restore the asynchronous operation in the subsequent step, and the second preset syntax is used to determine the function type in the subsequent step.
In step 102, the system registers the TypeScript declaration file in the TypeScript compiler. The TypeScript declaration file contains a part of grammar rules of the preset domain-specific language and does not contain the first preset grammar and the second preset grammar. The TypeScript declaration file includes any one or more of: a system logical unit declaration file, a tool logical unit declaration file, and a first custom logical unit declaration file. A logical unit refers to the smallest indivisible logic that can be executed, and is part of the syntax. That is, the grammar rules of the preset domain-specific language may be saved in the TypeScript declaration file in the form of logical units. The TypeScript Declaration File is a d.ts File (TypeScript Declaration File) and is a definition File in TypeScript. Accordingly, the system logical unit declaration file, the tool logical unit declaration file, and the first custom logical unit declaration file may be a system.d.ts file, a tools.d.ts file, and a custom.d.ts file, respectively.
The system logical unit refers to a logical unit unique to a specific system, and all the system logical units can be all stored in a system logical unit declaration file. The tool logic unit refers to common tool logic, the tool logic can be applied to other systems, not only is used in a specific system, but also all the tool logic units can be all stored in a tool logic unit declaration file. The custom logic unit is a logic unit generated by the user custom logic, and all the custom logic units can be stored in a custom logic unit declaration file. After the three logic units are stored in the TypeScript declaration file and registered in the TypeScript compiler, the grammar rules in the logic units are used as a part of the grammar rules of the preset domain-specific language for the user to use directly, and the user does not need to import (import) nor define. By dividing the logic units into the above three categories, the logic units can be managed and used simply and quickly.
In step 103, the system converts the original code into a corresponding abstract syntax tree. The system cannot verify whether the original code conforms to the first preset syntax or the second preset syntax, so that the original code needs to be converted into a corresponding abstract syntax tree and then subjected to the first preset syntax verification or the second preset syntax verification.
In step 104, the system verifies the original code according to the TypeScript declaration file based on the TypeScript compiler, and outputs error information if the verification fails and ends. Because the TypeScript declaration document contains a portion of the grammar rules of the pre-set domain-specific language, the system needs to verify that the original code conforms to the grammar contained in the TypeScript declaration document. If the verification is passed, namely the original code conforms to the grammar contained in the TypeScript declaration file, the system continues to execute the next step; if the verification is not passed, namely the original code does not conform to the grammar contained in the TypeScript declaration file, the system does not continue to execute the next step, but outputs error information and ends. The order of step 103 and step 104 may be interchanged, that is, step 104 may be performed before step 103, which is not limited in this application.
In step 105, the second preset syntax is used to determine the function type of the code, and the system verifies whether the function type of the abstract syntax tree is consistent with the function type of the original code input by the user according to the second preset syntax of the preset DSL language. If the verification is consistent, the function type of the original code input by the user can be confirmed to be correct, and the system continues to execute the next step; if the verification is inconsistent, the function type of the original code input by the user can be confirmed to be wrong, and the system does not continue to execute the next step, but outputs error information and ends.
In an embodiment of the present application, step 105 may be performed by a Babel compiler. Fig. 2 is a flowchart illustrating an implementation method of step 105 according to the present embodiment. As shown in fig. 2, the step 105 of verifying whether the function type of the abstract syntax tree is consistent with the function type of the original code input by the user according to the second preset syntax may include the following steps 201 and 204:
step 201, the system searches for a return state type (Return State) through a traversal module (@ base/transition) of a Babel compiler;
step 202, judging the function type of an original code input by a user;
step 203, when the function type of the original code input by the user is a condition type, if the return state type cannot be found, the verification is not passed, if the return state type is found, whether the parameter of the return state type is a Boolean type or not is judged, if the parameter is the Boolean type, the verification is passed, and if the parameter is not the Boolean type, the verification is not passed;
step 204, when the function type of the original code input by the user is a calculation type, if the return state type cannot be found, the verification is passed, and if the return state type is found, the verification is not passed; and
in step 205, when the function type of the original code input by the user is the action type, if the return state type is found, the verification is passed, and if the return state type is not found, the verification is not passed.
Through the above step 201-. The order of steps 201 and 202 may be interchanged, and this application is not intended to limit this.
In step 106, the first preset syntax is used to restore the asynchronous operation, and the system converts the abstract syntax tree according to the first preset syntax and obtains the converted abstract syntax tree. Generally, asynchronous operations in JavaScript need to use callback or async/wait, but it is difficult for ordinary users to grasp the usage of asynchronous operations, and the learning cost of ordinary users is high. Therefore, by using the first preset grammar for restoring the asynchronous operation, the common user can directly use the asynchronous operation without mastering the keywords of the asynchronous operation, the learning cost of the user is greatly reduced, and the efficiency of user-defined logic is improved.
In an embodiment of the present application, step 106 may be performed by a Babel compiler. Fig. 3 is a flowchart illustrating an implementation method of step 106 according to an embodiment of the present application. As shown in fig. 3, the step 106 of converting the abstract syntax tree according to the first preset syntax may include the following steps 301 and 302:
step 301, traversing all functions in the abstract syntax tree and judging whether each function is an asynchronous function, if so, adding an await keyword for the function, otherwise, not adding the await keyword for the function; and
and 302, adding a corresponding packaging function body to the abstract syntax tree, and judging whether each function in the abstract syntax tree is added with an await keyword, if so, adding an async keyword to the function, and if not, not adding an async keyword to the function.
The above steps 301-302 are described as a specific example. The code shown below is a piece of original code entered by the user:
Figure BDA0002916565780000111
the above-mentioned original code is converted into a corresponding abstract syntax tree in step 103. It should be noted that, the execution object in steps 301-302 is an abstract syntax tree, not the original code. For reading and understanding, the abstract syntax tree corresponding to the original code segment is omitted, and the code is directly used to replace the abstract syntax tree to schematically illustrate the conversion performed by the first preset syntax.
The code shown below is the code after the first preset syntax conversion:
Figure BDA0002916565780000112
Figure BDA0002916565780000121
as can be seen from the code converted by the first preset syntax, the system determines that context, sendemail toaddress ([ to ], title, body) is an asynchronous function, and adds an await keyword in front of the function; the system adds a corresponding packing function body in the code, and the function name in the packing function body can be a name self-defined by a user; and the system judges that the function is added with the await and adds an async keyword to the function.
In step 107, the system outputs the corresponding executable JavaScript script and the second custom logic unit declaration file according to the converted abstract syntax tree. The JavaScript script is used to execute the logic defined by the original code by the user. The second custom logic unit declaration file contains the logic unit defined by the original code.
In step 108, the system adds the second custom logical unit declaration file to the first custom logical unit declaration file. And if the TypeScript declaration file does not comprise the first custom logic unit declaration file, newly establishing the first custom logic unit declaration file, and then adding the second custom logic unit declaration file into the first custom logic unit declaration file. And adding a second custom logic unit declaration file generated by the original code into the first custom logic unit declaration file, so that the first custom logic unit declaration file contains the logic unit defined by the original code by a user. That is to say, the logic unit customized by the user can be stored for the next direct use without redefining again, thereby simplifying the use mode of the customized logic and improving the efficiency of the customized logic.
In step 109, the system uploads the executable JavaScript script to the Run (Run) tool. The running tool is used for running the executable JavaScript and obtaining a corresponding running result, and returning the running result to the system. In one example, the running tool may be an optional third party running tool.
In step 110, the system triggers the running tool to run the executable JavaScript script and obtain a corresponding running result. In one example, the system may be triggered with triggering function execution, including Operation Support System (OSS), API web management, log services, table storage, and function computation API, SDK, and the like.
In step 111, the system receives the operation result returned by the operation tool.
FIG. 9 is an interface diagram of a custom function execution system based on a domain-specific language according to an embodiment of the application. As shown in fig. 9, the custom function execution system based on the domain-specific language can enable a user to directly execute a preset custom function and call a function execution result, such as "create a question" of an action function, by calling a logic unit encapsulated in the resource manager.
To sum up, in step 101-112, the method for running the custom function based on the domain-specific language according to the present application implements the custom function of the user and runs the function by using the DSL language and the resource manager, so that the ordinary user can implement the custom function and run the function with lower learning cost. Moreover, when the system scale is enlarged to a certain degree, the DSL language and the resource manager still have higher use efficiency, and the use cost of a user cannot rapidly rise along with the enlargement of the system scale, so that the DSL language and the resource manager are very suitable for a larger-scale system.
In another embodiment of the present application, a method for running a custom function based on a domain-specific language runs in a TypeScript compiler and a TypeScript editor, and the method may further include the following steps 401 and 415 as shown in fig. 4 and 5:
step 401, registering the TypeScript declaration file in a TypeScript editor;
step 402, responding to an input request of a user, and loading an edit box;
step 403, receiving an original code and a function type of the original code, which are input by a user in an edit box;
step 404, verifying the original code according to the TypeScript declaration file based on the TypeScript compiler;
step 405, outputting error information and ending if the verification fails, and continuing if the verification passes;
step 406, responding to a saving request of a user, and sending the original code, the function type of the original code and the TypeScript declaration file to a TypeScript compiler;
step 407, receiving an original code input by a user and a function type of the original code, where the original code uses a preset domain-specific language based on a TypeScript language, where syntax of the preset domain-specific language includes a first preset syntax and a second preset syntax, the first preset syntax is used for restoring asynchronous operation, and the second preset syntax is used for judging the function type;
step 408, registering the TypeScript declaration file into a TypeScript compiler, wherein the TypeScript declaration file contains the grammar rules of the preset domain-specific language, and the TypeScript declaration file includes any one or more of the following: the system logic unit declaration file, the tool logic unit declaration file and the first custom logic unit declaration file;
step 409, converting the original code into a corresponding abstract syntax tree;
step 410, verifying the original code according to the TypeScript declaration file based on the TypeScript compiler, and outputting error information and ending if the verification fails;
step 411, verifying whether the function type of the abstract syntax tree is consistent with the function type of the original code input by the user according to a second preset syntax, and if not, outputting error information and ending;
step 412, converting the abstract syntax tree according to a first preset syntax;
step 413, outputting a corresponding executable JavaScript script and a second custom logic unit declaration file according to the converted abstract syntax tree; and
step 414, adding the second custom logic unit declaration file into the first custom logic unit declaration file; and
step 415, translating the converted abstract syntax tree according to the preset translation syntax, and outputting a translation result for a user to check.
The above steps 401 and 406 are run in a TypeScript editor, wherein the TypeScript editor comprises an edit box for receiving user input. The steps 407 and 415 are executed in the JavaScript compiler. The "receive original code and function type of original code input by user" in step 407 is the receipt by the TypeScript compiler of the function type of original code and original code input by user sent by the TypeScript editor. The steps 407 and 414 can refer to the description of the steps 101 and 108 in the embodiment of fig. 1, and are not described herein again.
Steps 401, 406 and 415 are described in detail below:
in step 401, the custom logic system registers the TypeScript declaration file in the TypeScript editor. By registering the TypeScript declaration file in the TypeScript editor, the TypeScript editor can acquire various types of logic units in the TypeScript declaration file.
In step 402, in response to a user input request, the system loads an edit box. The user may make an input in the edit box.
In step 403, the system receives the original code and the function type of the original code entered by the user in the edit box.
In step 404, the system validates the original code against the TypeScript declaration file based on the TypeScript compiler.
In step 405, if the verification is passed, the system continues to execute the next step; and if the verification fails, outputting error information and ending. For a specific verification method, reference may be made to the detailed description of step 104 in the embodiment of fig. 1, which is not described herein again.
In step 406, in response to the user's save request, the system sends the original code, the function type of the original code, and the TypeScript declaration file to the TypeScript compiler. By sending the original code to the TypeScript compiler, the TypeScript compiler can receive the original code and the function type of the original code input by the user to perform the subsequent steps 407-415. By sending the TypeScript declaration file to the TypeScript compiler along with the original code, the TypeScript compiler can receive the TypeScript declaration file associated with the original code at the same time the original code is received. In this way, when the TypeScript compiler needs to serve a plurality of TypeScript editors as the front end at the same time as the back end, it can be determined which TypeScript declaration files each piece of original code is respectively related to.
In an embodiment of the present application, the method further comprises: when the user enters the original code in the edit box, the system matches in the TypeScript declaration file according to what the user is currently entering. When the names of one or more logic units in the TypeScript declaration file can be matched with the content part currently input by the user, the logic units are considered as the current matching result, and the matching result is displayed in the edit box to prompt the user about the logic units, so that the user can accurately and quickly input the original codes according to the prompt of the logic units. Fig. 6 is an interface diagram of the logical unit hint shown according to the present embodiment. As shown in FIG. 6, the user enters two letters "da" in the edit box, and the editor can match in the TypeScript declaration file based on the two letters "da" and present the current match in the drop-down box.
In an embodiment of the present application, the TypeScript editor may include a first error reporting function and a second error reporting function. The first error reporting function can be an error reporting function carried by a TypeScript editor; the second error reporting function may be a predefined custom error reporting function for determining whether the error is associated with the second predefined syntax according to the error information. The custom function operating method based on the domain-specific language may further include the following steps 701 and 703 as shown in fig. 7:
step 701, when error information occurs, the system calls a second error reporting function to judge whether the error is related to a second preset syntax according to the error information;
step 702, if relevant, the system eliminates error information; and
step 703, if the function is not related, the system invokes the first error reporting function and sends the error message to the first error reporting function.
In one example, the TypeScript Editor can be a Monaco Editor and the first error-reporting function can be setModelMarkers within the Monaco Editor. The second error reporting function may be a user-defined error reporting function setModelMarkers 'preset by the user, and the second error reporting function setModelMarkers' may be capable of determining whether the error is related to the second preset syntax according to the error information, that is, whether the error meets the rule of the second preset syntax. In general, the error reporting function of the editor can only judge the error which does not conform to the syntax of the general programming language, but cannot judge the error which does not conform to the syntax of the general programming language but conforms to the syntax of the DSL language. When the error information occurs, the system determines whether the error is related to the second preset syntax by calling the second error reporting function setModelMarkers'. If the error information is related to the second preset grammar, the error accords with the grammar of the DSL language, and the system eliminates the error information; if not, the system calls a first error reporting function, sends an error message to the first error reporting function and transmits the error parameter to the first error reporting function. By using the second error reporting function to judge the error information which does not conform to the general programming language grammar but conforms to the DSL language grammar, the error information caused by the error conforming to the DSL language grammar can be avoided, thereby realizing accurate error reporting when the DSL language is used.
In an embodiment of the present application, the error information may include an error prompt message and error location information, where the error prompt message is used to prompt a user of an error in the edit box, and the error location information is used to prompt the user of a location of the error in the edit box. In one example, the system may prompt the user for an error by marking the error in the form of a red, underlined wavy line in the edit box based on the error prompt information and the error location information.
In an embodiment of the present application, before "registering the TypeScript declaration file in the TypeScript compiler" in step 408, a method for running a custom function based on a domain-specific language may further include: the system receives the TypeScript declaration file sent by the TypeScript editor. By receiving the TypeScript declaration file sent by the TypeScript editor, the system can know the TypeScript declaration file used by the TypeScript editor. In this way, when the system has a plurality of different, mutually independent TypeScript editors, it can be determined which TypeScript declaration files each TypeScript editor is respectively associated with.
In step 415, the grammar of the preset domain-specific language further includes a preset translation grammar, and the system translates the converted abstract grammar tree according to the preset translation grammar and outputs the translation result for the user to view. And translating the converted abstract syntax tree corresponding to the original code to output a translation result which is easy to read and understand, so that a user who cannot directly understand the original code can know the logic defined by the original code through the translation result. In one example, the preset translation grammar can include the following five types of translation rules:
1. translating IF: if { condition } the n { branch one } else { branch two } translates to { branch one } if { condition } then { branch two } otherwise;
2. translation of BinaryExpression: a > translation is greater than, < translation is less than, + translation is plus, -translation is minus, # translation is multiply,/translation is divide, | translation is or, & is and;
3. translation UnaryExpression: | A Translation is not;
4. translation CallExpression: the call is in the form of call (param1, param2) and translates into calling "custom function call with parameters param1, param 2";
5. translation isReturnStatement: the form of return is return ret, which is translated into a result or judgment returned to ret;
the application also provides a custom function operating system based on the domain specific language, which comprises: a memory for storing instructions executable by the processor; and a processor for executing the instructions to implement the method for running the custom function based on the domain-specific language as described above.
FIG. 8 illustrates a system block diagram of a domain specific language based custom function execution system according to an embodiment of the present application. The domain-specific language based custom function execution system 800 may include an internal communication bus 801, a Processor (Processor)802, a Read Only Memory (ROM)803, a Random Access Memory (RAM)804, and a communication port 805. When applied to a personal computer, the domain-specific language based custom function execution system may also include a hard disk 807. The internal communication bus 801 may enable data communication between the custom function execution system 800 components based on the domain specific language. The processor 802 may make the determination and issue the prompt. In some embodiments, the processor 802 may be comprised of one or more processors. The communication port 805 can implement the custom function execution system 800 based on the domain-specific language to communicate data with the outside. In some embodiments, the domain specific language based custom function runtime system 800 can send and receive information and data from a network through the communication port 805. The domain-specific language based custom function execution system 800 may also include various forms of program storage units and data storage units, such as a hard disk 807, Read Only Memory (ROM)803 and Random Access Memory (RAM)804, capable of storing various data files used for computer processing and/or communications, and possibly program instructions executed by the processor 802. The processor executes these instructions to implement the main parts of the method. The results processed by the processor are communicated to the user device through the communication port and displayed on the user interface.
The above-mentioned method for operating a customized function based on a domain-specific language can be implemented as a computer program, stored in the hard disk 807, and recorded in the processor 802 for execution, so as to implement any method for operating a customized function based on a domain-specific language in the present application.
The present application also provides a computer readable medium having stored thereon computer program code which, when executed by a processor, implements a method of custom function execution based on a domain-specific language as described above.
When the custom function operation method based on the domain-specific language is implemented as a computer program, the custom function operation method can also be stored in a computer readable storage medium as an article of manufacture. For example, computer-readable storage media can include but are not limited to magnetic storage devices (e.g., hard disk, floppy disk, magnetic strips), optical disks (e.g., Compact Disk (CD), Digital Versatile Disk (DVD)), smart cards, and flash memory devices (e.g., electrically Erasable Programmable Read Only Memory (EPROM), card, stick, key drive). In addition, various storage media described herein can represent one or more devices and/or other machine-readable media for storing information. The term "machine-readable medium" can include, without being limited to, wireless channels and various other media (and/or storage media) capable of storing, containing, and/or carrying code and/or instructions and/or data.
It should be understood that the above-described embodiments are illustrative only. The embodiments described herein may be implemented in hardware, software, firmware, middleware, microcode, or any combination thereof. For a hardware implementation, the processing units may be implemented within one or more Application Specific Integrated Circuits (ASICs), Digital Signal Processors (DSPs), Digital Signal Processing Devices (DSPDs), Programmable Logic Devices (PLDs), Field Programmable Gate Arrays (FPGAs), processors, controllers, micro-controllers, microprocessors, and/or other electronic units designed to perform the functions described herein, or a combination thereof.
Having thus described the basic concept, it will be apparent to those skilled in the art that the foregoing disclosure is by way of example only, and is not intended to limit the present application. Various modifications, improvements and adaptations to the present application may occur to those skilled in the art, although not explicitly described herein. Such modifications, improvements and adaptations are proposed in the present application and thus fall within the spirit and scope of the exemplary embodiments of the present application.
Also, this application uses specific language to describe embodiments of the application. Reference throughout this specification to "one embodiment," "an embodiment," and/or "some embodiments" means that a particular feature, structure, or characteristic described in connection with at least one embodiment of the present application is included in at least one embodiment of the present application. Therefore, it is emphasized and should be appreciated that two or more references to "an embodiment" or "one embodiment" or "an alternative embodiment" in various places throughout this specification are not necessarily all referring to the same embodiment. Furthermore, some features, structures, or characteristics of one or more embodiments of the present application may be combined as appropriate.
Aspects of the present application may be embodied entirely in hardware, entirely in software (including firmware, resident software, micro-code, etc.) or in a combination of hardware and software. The above hardware or software may be referred to as "data block," module, "" engine, "" unit, "" component, "or" system. The processor may be one or more Application Specific Integrated Circuits (ASICs), Digital Signal Processors (DSPs), digital signal processing devices (DAPDs), Programmable Logic Devices (PLDs), Field Programmable Gate Arrays (FPGAs), processors, controllers, microcontrollers, microprocessors, or a combination thereof. Furthermore, aspects of the present application may be represented as a computer product, including computer readable program code, embodied in one or more computer readable media. For example, computer-readable media may include, but are not limited to, magnetic storage devices (e.g., hard disk, floppy disk, magnetic strips … …), optical disks (e.g., Compact Disk (CD), Digital Versatile Disk (DVD) … …), smart cards, and flash memory devices (e.g., card, stick, key drive … …).
Similarly, it should be noted that in the preceding description of embodiments of the application, various features are sometimes grouped together in a single embodiment, figure, or description thereof for the purpose of streamlining the disclosure aiding in the understanding of one or more of the embodiments. This method of disclosure, however, is not intended to require more features than are expressly recited in the claims. Indeed, the embodiments may be characterized as having less than all of the features of a single embodiment disclosed above.
Although the present application has been described with reference to the present specific embodiments, it will be recognized by those skilled in the art that the foregoing embodiments are merely illustrative of the present application and that various changes and substitutions of equivalents may be made without departing from the spirit of the application, and therefore, it is intended that all changes and modifications to the above-described embodiments that come within the spirit of the application fall within the scope of the claims of the application.

Claims (12)

1. A custom function operation method based on a domain-specific language runs in a JavaScript virtual machine and comprises the following steps:
receiving original code input by a user and a function type of the original code, wherein the original code uses a preset domain-specific language based on a TypeScript language and calls one or more encapsulated logic units in a resource manager, the grammar of the preset domain-specific language comprises a first preset grammar and a second preset grammar, the first preset grammar is used for restoring asynchronous operation, the second preset grammar is used for judging the function type, and the encapsulated logic units comprise attributes and methods of classes;
registering a TypeScript declaration file into the TypeScript compiler, wherein the TypeScript declaration file contains grammar rules of the preset domain-specific language, the TypeScript declaration file including any one or more of: the system logic unit declaration file, the tool logic unit declaration file and the first custom logic unit declaration file;
processing the original code based on the TypeScript declaration file, the first preset grammar and the second preset grammar and outputting a corresponding executable JavaScript script and a second custom logic unit declaration file;
adding the second custom logic unit declaration file into the first custom logic unit declaration file;
uploading the executable JavaScript script to a running tool;
triggering the running tool to run the executable JavaScript and obtain a corresponding running result; and
and receiving the operation result returned by the operation tool.
2. The method of claim 1, wherein the step of processing the original code based on the TypeScript declaration file, the first preset syntax, and the second preset syntax and outputting corresponding executable JavaScript script and second custom logic unit declaration files comprises:
converting the original code into a corresponding abstract syntax tree;
verifying the original code according to the TypeScript declaration file based on the TypeScript compiler, and outputting error information and ending if the verification fails;
verifying whether the function type of the abstract syntax tree is consistent with the function type of the original code input by the user or not according to the second preset syntax, and if not, outputting error information and ending;
converting the abstract syntax tree according to the first preset syntax; and
and outputting a corresponding executable JavaScript script and a second custom logic unit statement file according to the converted abstract syntax tree.
3. The method of claim 2, wherein the grammar of the predetermined domain-specific language further comprises a predetermined translation grammar, the method further comprising: and translating the converted abstract syntax tree according to the preset translation syntax, and outputting a translation result for a user to check.
4. The method of claim 2, wherein the transforming the abstract syntax tree according to the first preset syntax is performed by a Babel compiler; the converting the abstract syntax tree according to the first preset syntax includes:
traversing all functions in the abstract syntax tree and judging whether each function is an asynchronous function, if so, adding an await keyword for the function, otherwise, not adding the await keyword for the function; and adding a corresponding packaging function body for the abstract syntax tree, and judging whether each function in the abstract syntax tree is added with the await keywords, if so, adding the async keywords for the function, and if not, not adding the async keywords for the function.
5. The method of claim 2, wherein the verifying whether the function type of the abstract syntax tree is consistent with the function type of the original code input by the user according to the second preset syntax is performed by a Babel compiler; the verifying whether the function type of the abstract syntax tree is consistent with the function type of the original code input by the user according to the second preset syntax includes:
searching a return state type through a traversal module of the Babel compiler, and judging a function type of an original code input by the user;
when the function type of the original code input by the user is a condition type, if the return state type cannot be found, the verification is not passed, if the return state type is found, whether the parameter of the return state type is a Boolean type or not is judged, if the parameter is the Boolean type, the verification is passed, and if the parameter is not the Boolean type, the verification is not passed;
when the function type of the original code input by the user is a calculation type, if the return state type cannot be found, the verification is passed, and if the return state type is found, the verification is not passed; and
and when the function type of the original code input by the user is the action type, if the return state type is found, the verification is passed, and if the return state type cannot be found, the verification is not passed.
6. The method of claim 2, wherein the method further runs in a TypeScript editor, wherein the TypeScript editor comprises an edit box;
the receiving of the original code input by the user and the function type of the original code are receiving the original code input by the user and the function type of the original code sent by the TypeScript editor;
the method further comprises the following steps:
registering the TypeScript declaration file in the TypeScript editor;
responding to an input request of a user, and loading the edit box;
receiving an original code input in the edit box by a user and a function type of the original code;
converting the original code into a corresponding abstract syntax tree;
verifying the abstract syntax tree according to the TypeScript declaration file, and outputting error information and ending if the abstract syntax tree is not verified; and
and sending the original code, the function type of the original code and the TypeScript declaration file to the TypeScript compiler in response to a saving request of a user.
7. The method of claim 6, further comprising:
and when the original code is input into the edit box by the user, matching in the TypeScript declaration file according to the content currently input by the user, and displaying a matching result in the edit box to perform logic unit prompting on the user.
8. The method of claim 6, wherein the TypeScript editor comprises a first error-reporting function and a second error-reporting function, wherein the first error-reporting function is an error-reporting function of the TypeScript editor, and the second error-reporting function is a predefined custom error-reporting function for determining whether an error is associated with the second predefined syntax according to the error information;
the method further comprises the following steps:
when the error information appears, calling the second error reporting function to judge whether the error is related to the second preset grammar according to the error information;
if so, eliminating the error information; and
if not, the first error reporting function is called, and the error message is sent to the first error reporting function.
9. The method of claim 6, wherein the error information comprises an error prompt message for prompting a user for an error in the edit box and error location information for prompting a user for a location of the error in the edit box.
10. A method as recited in claim 6, wherein, prior to the registering the TypeScript declaration file in the TypeScript compiler, the method further comprises:
and receiving the TypeScript declaration file sent by the TypeScript editor.
11. A custom function operating system based on a domain specific language, comprising:
a memory for storing instructions executable by the processor; and a processor for executing the instructions to implement the method of any one of claims 1-10.
12. A computer-readable medium having stored thereon computer program code which, when executed by a processor, implements the method of any of claims 1-10.
CN202110110928.5A 2021-01-26 2021-01-26 Custom function operation method and system based on domain-specific language Pending CN112748988A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110110928.5A CN112748988A (en) 2021-01-26 2021-01-26 Custom function operation method and system based on domain-specific language

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110110928.5A CN112748988A (en) 2021-01-26 2021-01-26 Custom function operation method and system based on domain-specific language

Publications (1)

Publication Number Publication Date
CN112748988A true CN112748988A (en) 2021-05-04

Family

ID=75653206

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110110928.5A Pending CN112748988A (en) 2021-01-26 2021-01-26 Custom function operation method and system based on domain-specific language

Country Status (1)

Country Link
CN (1) CN112748988A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115220727A (en) * 2022-06-07 2022-10-21 清华大学 Optimization method and device for irregular tensor program written by Python language

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112231068A (en) * 2020-12-18 2021-01-15 浙江太美医疗科技股份有限公司 Custom logic method, system and readable medium using domain specific language

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112231068A (en) * 2020-12-18 2021-01-15 浙江太美医疗科技股份有限公司 Custom logic method, system and readable medium using domain specific language

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115220727A (en) * 2022-06-07 2022-10-21 清华大学 Optimization method and device for irregular tensor program written by Python language
CN115220727B (en) * 2022-06-07 2024-05-28 清华大学 Optimization method and device for irregular tensor program written by Python language

Similar Documents

Publication Publication Date Title
CN112231068B (en) Custom logic method, system and readable medium using domain specific language
CN106919434B (en) Code generation method and device
CN106547527B (en) JavaScript file construction method and device
CN110704064B (en) Method and device for compiling and executing intelligent contract
CN110825430A (en) API document generation method, device, equipment and storage medium
US9207915B2 (en) Methods for detecting plagiarism in software code implementing a design pattern, including detecting a design pattern implemented in the software code and creating a representation that implements program logic associated with at least one function implementing the design pattern
US20210397422A1 (en) Software code converter for resolving conflicts during code development
CN114968807A (en) Code detection method and device, electronic equipment and readable storage medium
CN114153459A (en) Interface document generation method and device
CN111427578B (en) Data conversion method, device and equipment
CN115599359A (en) Code generation method, device, equipment and medium
CN115509904A (en) Assertion generation method and device of interface test case
CN112748988A (en) Custom function operation method and system based on domain-specific language
US20210397421A1 (en) Software code vectorization converter
CN110489124B (en) Source code execution method, source code execution device, storage medium and computer equipment
US20230418566A1 (en) Programmatically generating evaluation data sets for code generation models
US20230419036A1 (en) Random token segmentation for training next token prediction models
CN112230895B (en) EL expression analysis method, device, equipment and storage medium
CN113900657A (en) Method for reading data rule, electronic device and storage medium
CN114358596A (en) Index calculation method and device
CN110674355B (en) DSL application system for describing data labeling task and method thereof
CN113076084A (en) Resource file processing method, device, equipment and storage medium
CN108255802B (en) Universal text parsing architecture and method and device for parsing text based on architecture
CN117075912B (en) Method for program language conversion, compiling method and related equipment
US12014155B2 (en) Constrained prefix matching for generating next token predictions

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
RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20210504