A Regular Expression Extension Method and System for YAML and Pushdown Automata

By building a regular matching tree in YAML and using push-down automaton to process the state, the problem that traditional regular expressions are difficult to match string references and associations is solved, and the matching of complex regular expressions and the improvement of language capabilities is achieved.

CN114840723BActive Publication Date: 2025-06-10HANGZHOU BENMA NETWORK TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210439527.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-04-25
Publication Date
2025-06-10
Estimated Expiration
2042-04-25

AI Technical Summary

Technical Problem

Traditional regular expressions are difficult to solve the matching problems of pattern references, interrelated inclusions, etc. in strings, and there are problems that are difficult to read and maintain.

Method used

By writing regular expressions in YAML, a regular match tree is built, and state maintenance is used for processing the matching process by using push-down automatons to achieve the definition and matching of complex regular expressions.

Benefits of technology

It realizes matching of multiple string inclusion, recursion and loop relationships, solves the problems of mutual reference and interrelatedness, and improves the language ability and readability of regular expressions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114840723B_ABST
    Figure CN114840723B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and system for extending regular expressions of YAML and pushdown automata. The method includes: inputting prefabricated commands and nodes in YAML to construct a YAML regular matching tree, and generating a regular matcher according to the tree; the nodes include variable definition nodes, variable reference nodes, and variable expression nodes, and establishing a link between the variable definition nodes and the variable reference nodes; recursively matching the prefabricated nodes through the regular matcher, and executing the prefabricated commands according to the node types; constructing a pushdown matching logic, if the current node matches successfully, maintaining the matching status of the current node and the current child node according to the pushdown matching logic and the prefabricated commands; reading the contents of all successfully matched variable expression nodes, and calling corresponding regular expressions from the regular expression library of the language itself according to the contents.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of computer code regular expressions, and particularly to a method and system for extending regular expressions of YAML and pushdown automata. Background Art

[0002] Currently, there are two standards for traditional regular expressions. In addition to the POSIX standard, there is also a Perl standard. Among them, the POSIX standard is relatively classic and is also the built-in implementation of many other programming languages. The Perl standard expands the basic regular expressions and adds functions such as pattern recursive matching. However, neither the regular expressions of the POSIX standard nor the PCRE standard can solve the matching problems of patterns such as mutual reference and mutual associated inclusion in strings. If you want to borrow such regular expressions to match a certain structured programming language, it is also very complicated. In addition, traditional regular expressions also have problems of being difficult to understand, read, and maintain. Based on this background, the present invention proposes a modular and semantic scheme for matching based on regular expressions. Summary of the Invention

[0003] One of the invention objects of the present invention provides a method and system for extending regular expressions of YAML and pushdown automata. The method and system write regular expressions in YAML, form a regular matching tree through the regular expressions, and define and match complex regular expressions through the regular matching tree.

[0004] Another invention object of the present invention provides a method and system for extending regular expressions of YAML and pushdown automata. The method and system can make the regular expressions of the present invention not only match a single string pattern, but also match various inclusion, recursive, and cyclic relationships of multiple strings by providing modular and semantic regular expressions, and solve the problems of mutual reference and mutual association of strings through structured regular expressions.

[0005] Another invention object of the present invention provides a method and system for extending regular expressions of YAML and pushdown automata. The method and system introduce a pushdown automaton to handle the state maintenance during the matching process of regular expressions.

[0006] Another invention object of the present invention provides a method and system for extending regular expressions of YAML and pushdown automata. The method and system incorporate regular expressions into a YAML structured document, describe each rule module of each regular expression through the hierarchical relationship of the YAML structured document, can design and reference through custom command characters, and set conditional selection and "not" logic, greatly expanding the language ability of regular expressions.

[0007] To achieve at least one of the above-mentioned invention objectives, the present invention further provides a method for regular expression extension of YAML and pushdown automata. The method includes:

[0008] Input prefabricated commands and nodes in YAML, construct a YAML regular matching tree, and generate a regular matcher according to the regular matching tree;

[0009] The nodes include variable definition nodes, variable reference nodes, and variable expression nodes. Establish a link between the variable definition nodes and variable reference nodes;

[0010] Recursively match prefabricated nodes through the regular matcher, and execute prefabricated commands according to the node types;

[0011] Construct a pushdown matching logic. If the current node matches successfully, maintain the matching status of the current node and the corresponding child nodes of the current node according to the pushdown matching logic and prefabricated commands;

[0012] Read the contents of all successfully matched variable expression nodes, and call the corresponding regular expressions from the regular expression library of the language itself according to the contents.

[0013] According to one preferred embodiment of the present invention, the method includes: The method includes: using a regular compiler to read modular regular expression data from the YAML regular matching tree, storing the modular regular expression data in memory and converting it into a corresponding regular matching model, and further using the regular matcher to read the text and match it with the regular matching model.

[0014] According to another preferred embodiment of the present invention, the prefabricated nodes further include a logical NOT node, where the NOT logical node configures the NOT logic. Obtain the regular expression matching result at the NOT logical node. If the matching result is not a match, perform the matching of the lower-level nodes of the NOT logical node.

[0015] According to another preferred embodiment of the present invention, the prefabricated nodes further include an other logical node. When the regular matching results of all nodes at the same level are false, the result of the other logical node is true. Further recursively match the regular matching operations of the lower-level child nodes of the other logical node, otherwise perform the regular matching of the corresponding child nodes of the nodes at the same level whose regular matching results are true.

[0016] According to another preferred embodiment of the present invention, the prefabricated nodes further include a root node, where the root node is the root node of the regular matching tree, and start the regular matching operation of each layer of nodes of the regular matcher according to the root node.

[0017] According to another preferred embodiment of the present invention, the prefabricated node further includes different back logic nodes, where the back logic nodes are used to construct loop matches at different levels, configure integer values of the back logic nodes, and the integer values represent the levels to which the current node jumps back, and perform regular matching operations on the nodes at the corresponding levels according to the integer values of the current back logic nodes.

[0018] According to another preferred embodiment of the present invention, the method includes: constructing a push-down structure for each node using the next structure, obtaining variable values or reserved words of variable definition nodes, variable reference nodes, variable expression nodes, other logic nodes, and back logic nodes, and performing rules or regular matching on the corresponding nodes at the next level through the next structure.

[0019] According to another preferred embodiment of the present invention, the method includes configuring a unique identifier for each node, obtaining the node type, configuring the update range of each node, and when performing updates at each level according to the next structure, determining whether the unique identifier of the current node is within the update range, and if so, performing the update of the current node.

[0020] In order to achieve at least one of the above invention purposes, the present invention further provides a regular expression extension system for YAML and push-down automata, and the system executes the above regular expression extension method for YAML and push-down automata.

[0021] The present invention further provides a computer-readable storage medium, and the computer-readable storage medium stores a computer program, and the computer program can be executed by a processor to execute the above regular expression extension method for YAML and push-down automata. Description of the Drawings

[0022] Figure 1 It shows a flowchart of a regular expression extension method for YAML and push-down automata according to the present invention. Detailed Embodiments

[0023] The following description is used to disclose the present invention so that those skilled in the art can implement the present invention. The preferred embodiments in the following description are only examples, and those skilled in the art can think of other obvious variations. The basic principles defined in the following description can be applied to other implementation schemes, variation schemes, improvement schemes, equivalent schemes, and other technical schemes without departing from the spirit and scope of the present invention.

[0024] It can be understood that the term "one" should be understood as "at least one" or "one or more". That is, in one embodiment, the number of an element can be one, and in other embodiments, the number of the element can be multiple. The term "one" cannot be understood as a limitation on the number.

[0025] Please refer to Figure 1 , the present invention discloses a method and system for extending regular expressions of YAML and pushdown automata. The method mainly includes the following steps: First, it is necessary to define nodes and configure the types, quantities, and levels of the nodes, and establish a regular matcher. The regular matcher realizes the regular matcher by inputting prefabricated commands and nodes in the YAML document, constructs a regular matching tree through the preconfigured node types, quantities, and levels, and realizes complex regular matching through the regular matching tree. It should be noted that the regular matcher in the present invention is

[0026] Specifically, the node types include the root node, and the root node is the root node, which starts the matching operation of the regular matching tree through the root node. The node types also include the REG node, and the REG node is a variable expression node. The variable expression node can be recognized as a classic regular expression by the computer program of the system itself. When prefabricated commands and the REG node are input in the YAML document, the content in the REG node can be read and traditional regular matching can be performed.

[0027] The different types of nodes will perform compilation operations according to the input commands and corresponding compilation grammars. It should be noted that the compilation grammar is executed according to the existing language grammar rules. For example, the YAML regular that can be matched by using the grammar rules including but not limited to the Lua scripting language can be adopted. The regular compiler in the present invention is a program for processing regular matching tree expressions, which can read data from YAML and convert it into a regular matching model in memory. The regular matcher in the present invention is a program that performs matching between text and the regular matching model in memory.

[0028] It is worth mentioning that the node types also include DEF nodes and REF nodes, where the DEF nodes and REF nodes are variable definition nodes and variable reference nodes respectively. In the present invention, a link relationship needs to be established between the DEF nodes and the REF nodes, so that the REF nodes can reference the DEF nodes. The DEF nodes can implement variable naming for a certain regular rule. After variable naming through the DEF nodes, the regular rule of the DEF nodes will become the variable value. The REF nodes can replace the regular matching rule in the DEF nodes into the REF nodes through the link relationship, so as to achieve the reference of the regular matching rule. For example: The DEF node defines the search for the same string matching character ^ at the beginning, indicating that the same text under this beginning matching character is the matching success result. If the matching rule of the regular expression is ^one, then the DEF node defines the regular matching rule for searching all strings starting with one, and ^one is the variable value. Through the link relationship between the REF node and the DEF node, the variable value ^one corresponding to the DEF node can be referenced. Establish a connection relationship between the REF node and the REG node, and express the variable referenced by the REF node through the REG node. After the REG node obtains the variable value ^one, it performs regular matching of the strings in the text. For example, if there is a string one apple in the text, then the variable value ^one of the REG node and the string one apple match successfully. If there is two apple in the text, the variable value ^one of the REG node and the string two apple do not match. It should be noted that the above DEF nodes can redefine the regular rules to achieve the creation of custom regular rules. Through the reference relationship between the REF nodes and the corresponding DEF nodes, the regular expressions can be quickly expanded.

[0029] Furthermore, the nodes of the present invention also include not nodes. The not nodes are non-logical nodes, and the non-logical nodes are used for the non-logic of regular expressions. The not nodes and the REG nodes are also variable expression nodes. When the not nodes are set, if the current regular expression satisfies the non-logic, the regular matching is successful. For example, the defined non-logic is #, and the regular expression variable in the not node is #one. Then, traditional string non-logical regular matching is performed in the not node. If there is two apple in the string, the execution result of the non-logic in the not node is used to judge that the string twoapple satisfies the regular matching of the string. If the string matches one apple, then according to the non-logical regular matching of the not node, it is concluded that the string one apple does not match the regular expression. It should be noted that through the above configuration of the not nodes, the language ability of regular expressions can be greatly increased.

[0030] In the present invention, the node further includes other logical nodes, where the other logical nodes are conditional selection nodes. When the regular expression verification results of all nodes at the same level in the regular expression tree are all failures, the regular expression verification of the other logical nodes is successful. Therefore, the configuration of the other logical nodes can make the regular matching tree have a more complex and diverse regular matching effect. For example: There is an other logical node at the same level. If the other regular expressions of the nodes at the same level include ^one and #apple, which respectively represent matching strings starting with one and strings without apple. If the text to be matched only contains two apple, according to the matching results of the two regular expressions, both are judged as failures, then the other logical node at the same level is automatically matched successfully, and the regular expression matching of other child nodes under the other logical node is further executed.

[0031] In the present invention, the regular expression matching adopted by the corresponding node generally uses built-in library functions for matching. If the result of the regular expression matching of the current node is true, access to the child nodes of the current node is allowed, and the regular expression matching or conditional rules of the child nodes are further executed. The conditional rules include but are not limited to termination matching conditions and jump matching conditions. In the present invention, the termination matching condition can configure an end node in the regular expression tree, where the end node can be a user-defined node. When recursively matching each layer of nodes according to the node configuration of the regular expression tree, the regular expressions and corresponding conditional rules of each layer of nodes are read. If the current node is matched as an end node, the recursive matching of the branch where the end node is located in the regular expression tree is ended. In another preferred embodiment of the present invention, if there is no end node in the regular expression tree, the matching operation of the regular expression tree can be ended after the regular expression matching of all nodes is completed through recursive matching.

[0032] For example, the recursive matching can be implemented according to interface{} in the Go language. Multiple keys are configured in the interface{}, each key corresponds to a value, each key represents a regular expression, and the corresponding value represents the value of the regular expression. The for key, value statement is used to match each key in turn to obtain the value of the value matched by all keys.

[0033] It should be noted that in the present invention, a back node is also configured based on the YAML document. The back node is a jump node in the conditional selection node. Through the back node, the regular matcher can return to the specified node to perform cyclic regular matching operations. The back node can be configured with multiple levels of cyclic regular matching. The back node is configured with an integer value to specify the corresponding node at a specific level. For example, if the integer value configured for the back node is 1, it jumps to the parent node of the current back node to perform regular matching. If it is other integers, it jumps to the corresponding level node to perform regular matching. After the corresponding level node performs regular matching again, it goes through the jump operation of the back node again and returns to the corresponding level node for regular matching, thereby realizing cyclic regular matching. This continues until all nodes in the regular matching tree complete regular matching or the matching is illegal. When all nodes at all levels have completed matching, the results of the nodes that have successfully matched at all levels are output to the stack data structure for storage. And the data structure is stored in the stack data structure.

[0034] To better achieve the technical effects of the present invention, the present invention uses a pushdown automaton to implement pushdown matching. The pushdown matching is implemented using a next structure. The next structure is a stack structure. The implementation method of the pushdown matching is that after the current node of the regular matching tree completes matching, the data stack structure of the next structure is further used to perform regular matching on the next child node, realize the maintenance of regular matching data, obtain the output path of each node, and record the matching success data of each type of node in real time, and update the corresponding node path data according to the current node type in sequence.

[0035] One of the advantages of the present invention is that it can modularly call complex regular expressions. For example, the following nodes can be configured in the regular expression matching tree in sequence: (root, not, REG, back), generating the first node configuration. The nodes in the parentheses are the child nodes of the previous node in sequence, and root is the root node. By adding the corresponding strings or conditional rules to the node configuration of the above regular expression matching tree, the above node configuration can be used as a modular regular expression processor, and the above modular regular expression processor can achieve the effect of cyclic regular expression matching. Further, in another preferred embodiment of the present invention, the following node configuration is performed in the regular expression configuration tree: (root, not, DEF, REF, other, REG, end), generating the second node configuration. Each node from left to right in the second node configuration is the child node of the previous node. By adding strings or conditional rules to the nodes corresponding to the second node configuration, through the DEF and REF node configurations of the second node configuration, the creation of custom regular expression rules can be realized, thereby greatly expanding the language ability of regular expression matching. In still another preferred embodiment of the present invention, if the not node in the first node configuration is the same as the not node in the second node, then after passing in the corresponding strings and rules using the first node configuration and the second node configuration at the same time, complex regular expression matching with different inclusion relationships can be realized.

[0036] In particular, according to the embodiments disclosed in the present invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, an embodiment of the present disclosure includes a computer program product that includes a computer program carried on a computer-readable medium, and the computer program includes program code for performing the methods shown in the flowcharts. In such an embodiment, the computer program can be downloaded and installed from a network through a communication section and / or installed from a removable medium. When the computer program is executed by a central processing unit (CPU), the above-described functions defined in the methods of the present application are performed. It should be noted that the above computer-readable medium in the present application can be a computer-readable signal medium, a computer-readable storage medium, or any combination of the two. A computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples of the computer-readable storage medium can include, but are not limited to: an electrical connection having one or more wire segments, 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), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, the computer-readable storage medium can be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In the present application, a computer-readable signal medium can include a data signal propagated in a baseband or as part of a carrier wave, which carries computer-readable program code. Such a propagated data signal can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer-readable signal medium can also be any computer-readable medium other than the computer-readable storage medium, which can send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted by any suitable medium, including but not limited to: wireless segments, wire segments, optical cables, RF, etc., or any suitable combination of the above.

[0037] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architectures, functions, and operations of systems, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagram may represent a module, a segment of a program, or a part of code, which contains one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions denoted in the blocks may occur in a different order than that denoted in the accompanying drawings. For example, two consecutive blocks shown may actually be executed substantially in parallel, and they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram and / or flowchart, and combinations of blocks in the block diagram and / or flowchart, may be implemented by a dedicated hardware-based system that performs the specified functions or operations, or may be implemented by a combination of dedicated hardware and computer instructions.

[0038] Those skilled in the art should understand that the embodiments of the present invention described above and shown in the accompanying drawings are only examples and do not limit the present invention. The objectives of the present invention have been fully and effectively achieved. The functions and structural principles of the present invention have been demonstrated and explained in the embodiments. Without departing from the said principles, the embodiments of the present invention may have any variations or modifications.

Claims

1. A method for extending regular expressions of YAML and pushdown automata, characterized in that, the method includes: Input prefabricated commands and nodes in YAML, construct a YAML regular matching tree, and generate a regular matcher according to the regular matching tree; The node types of the nodes include variable definition nodes, variable reference nodes, and variable expression nodes, and a link is established between the variable definition nodes and the variable reference nodes; Recursively match the prefabricated nodes through the regular matcher, and execute the prefabricated commands according to the node types; Construct a pushdown matching logic. If the current node matches successfully, maintain the matching status of the current node and the current child node according to the pushdown matching logic and the prefabricated commands; Read the contents of all successfully matched variable expression nodes, and call the corresponding regular expressions from the regular expression library of the language itself according to the contents.

2. A method for extending regular expressions of YAML and pushdown automata according to claim 1, characterized in that, the method includes: using a regular compiler to read modular regular expression data from the YAML regular matching tree, storing the modular regular expression data in memory and converting it into a corresponding regular matching model, and further using the regular matcher to read the text and match it with the regular matching model.

3. A method for extending regular expressions of YAML and pushdown automata according to claim 1, characterized in that, The prefabricated nodes also include logical NOT nodes, where the logical NOT nodes configure non-logic. Obtain the regular expression matching result at the logical NOT nodes. If the matching result is not a match, perform the matching of the lower-layer nodes of the logical NOT nodes.

4. A method for extending regular expressions of YAML and pushdown automata according to claim 1, characterized in that, The prefabricated nodes also include other logical nodes. When the regular matching results of all nodes at the same level are false, the result of the other logical nodes is true, and further recursively match the regular matching operations of the lower-layer child nodes of the other logical nodes, otherwise perform the regular matching of the corresponding child nodes of the nodes with true regular matching results at other levels.

5. A method for extending regular expressions of YAML and pushdown automata according to claim 1, characterized in that, The prefabricated nodes also include root nodes, where the root nodes are the root nodes of the regular matching tree, and start the regular matching operations of each layer of nodes of the regular matcher according to the root nodes.

6. A method for extending regular expressions of YAML and pushdown automata according to claim 1, characterized in that, The prefabricated nodes also include different back logical nodes, where the back logical nodes are used to construct loop matching at different levels, configure the integer value of the back logical nodes, and the integer value represents the level to which the current node jumps back, and perform regular matching operations on the nodes at the corresponding level according to the integer value of the current back logical node.

7. A method for extending regular expressions of YAML and pushdown automata according to claim 1, characterized in that, The method includes: constructing a push-down structure for each node using the next structure, obtaining variable values or reserved words of variable definition nodes, variable reference nodes, variable expression nodes, other logical nodes, and back logical nodes, and performing rule or regular matching on corresponding nodes at the next level through the next structure.

8. A method for extending regular expressions of YAML and push-down automata according to claim 7, wherein, the method includes configuring a unique identifier for each node, obtaining the node type, configuring the update range of each node, and when performing updates for each level according to the next structure, determining whether the unique identifier of the current node is within the update range, and if so, performing the update of the current node.

9. A system for extending regular expressions of YAML and push-down automata, wherein, the system executes a method for extending regular expressions of YAML and push-down automata according to any one of claims 1-8.

10. A computer-readable storage medium, wherein, the computer-readable storage medium stores a computer program, and the computer program can be executed by a processor to execute a method for extending regular expressions of YAML and push-down automata according to any one of claims 1-8.

Citation Information

Patent Citations

  • Finite automaton generating method of regular expression with wildcards

    CN104407849A

  • Grammer for regular expressions

    US20040225999A1