Disclosure of Invention
The invention provides a method and a device for generating a component document, electronic equipment and a computer medium, and aims to improve the generation efficiency of the component document.
In order to achieve the above object, the present invention provides a component document generating method, including:
acquiring a markdown component template document, component parameters, a component document title and a component source code;
analyzing the component parameters, the component document titles and the component source codes to generate parameter abstract syntax trees corresponding to the component parameters, title abstract syntax trees corresponding to the component document titles and source code abstract syntax trees corresponding to the component source codes;
acquiring component data from the parameter abstract syntax tree, the title abstract syntax tree and the source code abstract syntax tree;
acquiring the component configuration information of the markdown component template document, and importing the component data into the markdown component template document according to the component configuration information to obtain the component document.
Optionally, the parsing the component parameter, the component document header, and the component source code to generate a parameter abstract syntax tree corresponding to the component parameter, a header abstract syntax tree corresponding to the component document header, and a source code abstract syntax tree corresponding to the component source code includes:
acquiring a parameter character string corresponding to the component parameter, a title character string corresponding to the component document title and a source code character string corresponding to the component source code;
and respectively connecting the parameter character strings, the title character strings and the source code character strings according to a tree structure to generate a parameter abstract syntax tree corresponding to the component parameters, a title abstract syntax tree corresponding to the component document titles and a source code abstract syntax tree corresponding to the component source codes.
Optionally, the connecting the parameter character string, the title character string, and the source code character string according to a tree structure respectively includes:
performing lexical analysis on the parameter character string, the title character string and the source code character string respectively to obtain a parameter word sequence group included in the parameter character string, a title word sequence group included in the title character string and a source code word sequence group included in the source code character string;
and respectively connecting the parameter participle sequence group, the title participle sequence group and the source code participle sequence number group into a tree structure.
Optionally, the generating a parameter abstract syntax tree corresponding to the component parameter, a title abstract syntax tree corresponding to the component document title, and a source code abstract syntax tree corresponding to the component source code includes:
respectively carrying out syntactic analysis on a parameter word segmentation sequence group included by the parameter character string, a title word segmentation sequence group included by the title character string and a source code word segmentation sequence group included by the source code character string, and respectively converting the parameter word segmentation sequence group, the title word segmentation sequence group and the source code word segmentation sequence group into a parameter analysis tree, a title analysis tree and a source code analysis tree according to preset grammar;
and performing semantic analysis on the parameter parsing tree, the title parsing tree and the source code parsing tree respectively to generate a plurality of initial nodes of the parameter parsing tree, a plurality of initial nodes of the title parsing tree and a plurality of initial nodes of the source code parsing tree, and respectively constructing a parameter abstract syntax tree corresponding to the component parameter, a title abstract syntax tree corresponding to the component document title and a source code abstract syntax tree corresponding to the component source code according to the hierarchical relationship among the initial nodes of the parameter parsing tree, the hierarchical relationship among the initial nodes of the title parsing tree and the hierarchical relationship among the initial nodes of the source code parsing tree.
Optionally, the obtaining component data from the parameter abstract syntax tree, the title abstract syntax tree, and the source code abstract syntax tree includes:
performing depth traversal on the parameter abstract syntax tree, the title abstract syntax tree and the source code abstract syntax tree to obtain data of a plurality of tree nodes;
component data is obtained from data of a plurality of the tree nodes.
Optionally, the performing a deep traversal on the parameter abstract syntax tree, the header abstract syntax tree, and the source code abstract syntax tree to obtain data of a plurality of tree nodes includes:
respectively performing stack pressing operation on the parameter abstract syntax tree, the title abstract syntax tree and the source code abstract syntax tree to obtain fields corresponding to a plurality of tree nodes;
looping the push operation until the push operation becomes an empty stack;
when the stack pushing operation is changed into the empty stack, stopping circulation, and storing fields corresponding to all the tree nodes;
and converting the fields corresponding to all the tree nodes into data of a plurality of tree nodes.
Optionally, the inserting the component data into the markdown component template document according to the component configuration information to obtain a component document includes:
and displaying the corresponding component position of the component data in the markdown component template document according to the component configuration information, and inserting the component data into the component position to obtain a component document.
In order to solve the above problem, the present invention also provides a component document generating apparatus, including:
the component information acquisition module is used for acquiring markdown component template documents, component parameters, component document titles and component source codes;
the abstract syntax tree generating module is used for analyzing the component parameters, the component document titles and the component source codes and generating parameter abstract syntax trees corresponding to the component parameters, title abstract syntax trees corresponding to the component document titles and source code abstract syntax trees corresponding to the component source codes;
the component data acquisition module is used for acquiring component data from the parameter abstract syntax tree, the title abstract syntax tree and the source code abstract syntax tree;
and the component document generation module is used for acquiring the component configuration information of the markdown component template document, and importing the component data into the markdown component template document according to the component configuration information to obtain the component document.
In order to solve the above problem, the present invention also provides an electronic device, including:
a memory storing at least one computer program; and
and a processor executing the computer program stored in the memory to implement the component document generating method described above.
In order to solve the above problem, the present invention further provides a computer medium, in which at least one computer program is stored, and the at least one computer program is executed by a processor in an electronic device to implement the component document generating method described above.
In the embodiment of the invention, firstly, a markdown component template document, component parameters, a component document title and a component source code are obtained; secondly, generating a parameter abstract syntax tree corresponding to the component parameters, a title abstract syntax tree corresponding to the component document title and a source code abstract syntax tree corresponding to the component source code, wherein the abstract syntax tree comprises a plurality of initial nodes, and each node corresponds to different component data, so that hierarchically distinct component data can be obtained, a user can conveniently inquire or modify the component source code, and the generation efficiency of a subsequent component document is improved; and then, acquiring the component configuration information of the markdown component template document, importing the component data into the markdown component template document according to the component configuration information to obtain the component document, and directly generating the component document according to the configuration information to improve the generation efficiency of the component document. Therefore, the component document generation method, the device, the electronic equipment and the storage medium provided by the embodiment of the invention can improve the generation efficiency of the component document.
Detailed Description
It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
The embodiment of the invention provides a component document generation method. The execution subject of the component document generation method includes, but is not limited to, at least one of electronic devices such as a server and a terminal, which can be configured to execute the method provided by the embodiment of the present application. In other words, the component document generation method may be performed by software or hardware installed in a terminal device or a server device, and the software may be a blockchain platform. The server includes but is not limited to: a single server, a server cluster, a cloud server or a cloud server cluster, and the like.
Referring to fig. 1, which is a schematic flow diagram of a component document generating method according to an embodiment of the present invention, in an embodiment of the present invention, the component document generating method includes:
s1, acquiring markdown component template documents, component parameters, component document titles and component source codes.
In the embodiment of the present invention, the markdown component template document refers to a component template document in a plain text format written by markdown (a lightweight markup language), where a component refers to a component in which one or more code segments that complete their respective functions are packaged into one or more independent parts.
In an embodiment of the present invention, the markdown component template document may be obtained from a development platform or a web page.
In the embodiment of the present invention, the component parameter, the component document title, and the component source code are component-related information codes written in advance by a user using a preset programming language, and mainly function to implement display of a front-end page of the user, where the component parameter may be a specific code, and parameter page configuration may be performed on a component by using the component parameter, and then a preset compiler is used to filter component parameters unnecessary for display of the front-end page of the user, where the component parameter includes: parameter names, component descriptions, component types, component codes, and default values.
Preferably, the programming language may be an open source programming language TypeScript, and the compiler may be a React-Docgen-TypeScript compiler.
In an embodiment of the present invention, the component document header refers to a subdocument header of a plurality of components, and each component stores information by a corresponding subdocument.
In the embodiment of the present invention, the component source code refers to code written by a user according to rules of a specific programming language and used for executing a specified task, and may be used to describe types of components in the component source code and interaction relationships among the components.
S2, analyzing the component parameter, the component document title and the component source code, and generating a parameter abstract syntax tree corresponding to the component parameter, a title abstract syntax tree corresponding to the component document title and a source code abstract syntax tree document corresponding to the component source code.
In the embodiment of the present invention, an Abstract Syntax Tree (AST) refers to a Syntax structure that represents a programming language in a Tree form, each node on the Tree represents one structure in source codes, and the Abstract Syntax Tree mainly functions to embody the component parameters, the component document titles, and the logical relationships to be expressed by the component source codes in concrete codes.
In detail, the parsing the component parameter, the component document header, and the component source code to generate a parameter abstract syntax tree corresponding to the component parameter, a header abstract syntax tree corresponding to the component document header, and a source code abstract syntax tree corresponding to the component source code includes:
acquiring a parameter character string corresponding to the component parameter, a title character string corresponding to the component document title and a source code character string corresponding to the component source code;
and respectively connecting the parameter character strings, the title character strings and the source code character strings according to a tree structure to generate a parameter abstract syntax tree corresponding to the component parameters, a title abstract syntax tree corresponding to the component document titles and a source code abstract syntax tree corresponding to the component source codes.
In the embodiment of the present invention, the component parameter, the component document title, and the code corresponding to the component source code may be input into a preset converter, so as to obtain a parameter character string corresponding to the component parameter, a title character string corresponding to the component document title, and a source code character string corresponding to the component source code, which facilitates generation of an abstract syntax tree.
Preferably, the predetermined converter may be a Babel or Webpack loader.
Further, the connecting the parameter character string, the title character string, and the source code character string according to a tree structure respectively includes:
performing lexical analysis on the parameter character string, the title character string and the source code character string respectively to obtain a parameter word sequence group included in the parameter character string, a title word sequence group included in the title character string and a source code word sequence group included in the source code character string;
and respectively connecting the parameter participle sequence group, the title participle sequence group and the source code participle sequence number group into a tree structure.
In an embodiment of the present invention, the lexical analysis is to convert a code in a character string form into a word segmentation sequence array Tokens, and the essence of the lexical analysis is to program some rules. For example, for number recognition at 101, when the program scans the first numeric character, it starts to be treated as a number until a non-numeric character is encountered; for another example, for the character string identification of "abc", when a double quotation mark or a single quotation mark is scanned, it is considered as a character string until another double quotation mark or a single quotation mark is encountered.
In the embodiment of the present invention, the word sequence set token may be a number, a text label, a punctuation mark, a text content, an operator, and the like.
In detail, the generating of the parameter abstract syntax tree corresponding to the component parameter, the title abstract syntax tree corresponding to the component document title, and the source code abstract syntax tree corresponding to the component source code includes:
respectively carrying out syntactic analysis on a parameter word segmentation sequence group included by the parameter character string, a title word segmentation sequence group included by the title character string and a source code word segmentation sequence group included by the source code character string, and respectively converting the parameter word segmentation sequence group, the title word segmentation sequence group and the source code word segmentation sequence group into a parameter analysis tree, a title analysis tree and a source code analysis tree according to preset grammar;
and performing semantic analysis on the parameter parsing tree, the title parsing tree and the source code parsing tree respectively to generate a plurality of initial nodes of the parameter parsing tree, a plurality of initial nodes of the title parsing tree and a plurality of initial nodes of the source code parsing tree, and respectively constructing a parameter abstract syntax tree corresponding to the component parameter, a title abstract syntax tree corresponding to the component document title and a source code abstract syntax tree corresponding to the component source code according to the hierarchical relationship among the initial nodes of the parameter parsing tree, the hierarchical relationship among the initial nodes of the title parsing tree and the hierarchical relationship among the initial nodes of the source code parsing tree.
In an embodiment of the present invention, the parse tree is a tree structure including all syntax information, and some redundant syntax information (for example, colon, parenthesis, and semicolon) included in the parse tree is deleted after semantic analysis of the parse tree, so as to obtain a simpler abstract syntax tree.
In another embodiment of the present invention, the parsing refers to performing abstract representation on the word sequence set Tokens; for example, describing the content in Tokens by using a non-terminator < >, the content in the non-terminator < > represents a syntactic component, and the content in Tokens is a terminator, so that the information extraction of the source code can be better realized through syntactic analysis.
In an optional embodiment of the present invention, the parsing refers to converting the word sequence groups Tokens into a parsing tree form, and may generate initial nodes of a plurality of tree nodes by performing semantic analysis on the parsing tree, and construct an abstract syntax tree according to a hierarchical relationship among the plurality of tree nodes, so as to implement deep parsing of the abstract syntax tree.
And S3, acquiring component data from the parameter abstract syntax tree, the title abstract syntax tree and the source code abstract syntax tree.
In the embodiment of the invention, each node of the abstract syntax tree after semantic analysis is arranged according to the hierarchical relationship to display the data structure, priority and hierarchy in the source code, and the data in the source code also comprises blank grids, comments and repeated information, so that the abstract syntax tree can be deeply traversed to obtain the data corresponding to each node, the related information of a plurality of components can be obtained from the data, the component data with more distinct hierarchy can be obtained, and part of the component data required by a user can be directly obtained from a large amount of component data without searching one by one.
In the embodiment of the invention, the related data of the components comprises a plurality of component documents for displaying a front page of a user, a transmission mode of data corresponding to the components and related parameters for describing the functions of the components and realizing the functions.
In detail, the obtaining component data from the parameter abstract syntax tree, the title abstract syntax tree, and the source code abstract syntax tree includes:
performing depth traversal on the parameter abstract syntax tree, the title abstract syntax tree and the source code abstract syntax tree to obtain data of a plurality of tree nodes;
component data is obtained from data of a plurality of the tree nodes.
In the embodiment of the invention, the abstract syntax tree comprises a plurality of tree nodes, and the tree nodes comprise a plurality of leaf nodes; for the deep traversal of the abstract syntax tree, the tree node which is traversed first from the initial tree node to the last tree node and then upwards can be traversed by using the Babel, and then the tree node which is traversed and has a plurality of leaf nodes is traversed downwards from another leaf node, so that the deep traversal is achieved.
For example, the abstract syntax tree consists of A, B, C, D four tree nodes, tree node A in turn consisting of a1And a2Two leaf nodes, tree node C consisting of C1And c2Two leaf nodes, then the abstract syntax tree is traversed, firstly from the leaf node a in the tree node A1Traverse down to B, c1And c2And D; traverse A, B, c in the upward direction1And c2And D, traversing to A and then from another leaf node a2A downward traversal to D is started to reach a depth traversal.
Further, the performing a deep traversal on the parameter abstract syntax tree, the header abstract syntax tree, and the source code abstract syntax tree to obtain data of a plurality of tree nodes includes:
respectively performing stack pressing operation on the parameter abstract syntax tree, the title abstract syntax tree and the source code abstract syntax tree to obtain fields corresponding to a plurality of tree nodes;
looping the push operation until the push operation becomes an empty stack;
when the stack pushing operation is changed into the empty stack, stopping circulation, and storing fields corresponding to all the tree nodes;
and converting the fields corresponding to all the tree nodes into data of a plurality of tree nodes.
In this embodiment, the stack refers to a linear table that performs an insertion or deletion operation only at the end of the table. An empty table without an element is called an empty stack. And the fields corresponding to the tree nodes refer to the related data of all the component functions and the implementation principle.
S4, acquiring the component configuration information of the markdown component template document, and inserting the component data into the markdown component template document according to the component configuration information to obtain the component document.
In the embodiment of the present invention, the component configuration information refers to a calling process and a display sequence of the component data, and the configuration information of the markdown component template document may be obtained by using a preset regular rule or a preset document configuration language (for example, YAML language).
In detail, the inserting the component data into the markdown component template document according to the component configuration information to obtain a component document includes:
and displaying the corresponding component position of the component data in the markdown component template document according to the component configuration information, and inserting the component data into the component position to obtain a component document.
In an embodiment of the present invention, the component data may be connected to the preset interface by using a call function in the component parameter, and the component data is displayed as a user front-end page.
In the embodiment of the invention, the component document is used for recording the attribute relationship and the interaction relationship of each object in the component, the generated component document is an updated markdown document, the updated markdown document can be rendered through a calling function in the component parameter, and the component data is displayed as a user front-end page.
In the embodiment of the invention, firstly, a markdown component template document, component parameters, a component document title and a component source code are obtained; secondly, generating a parameter abstract syntax tree corresponding to the component parameters, a title abstract syntax tree corresponding to the component document title and a source code abstract syntax tree corresponding to the component source code, wherein the abstract syntax tree comprises a plurality of initial nodes, and each node corresponds to different component data, so that hierarchically distinct component data can be obtained, a user can conveniently inquire or modify the component source code, and the generation efficiency of a subsequent component document is improved; and then, acquiring the component configuration information of the markdown component template document, importing the component data into the markdown component template document according to the component configuration information to obtain the component document, and directly generating the component document according to the configuration information to improve the generation efficiency of the component document. Therefore, the component document generation method provided by the embodiment of the invention can improve the generation efficiency of the component document.
FIG. 2 is a functional block diagram of the document creation apparatus according to the present invention.
The component document generating apparatus 100 according to the present invention may be installed in an electronic device. According to the implemented functions, the component document generating apparatus may include a component information obtaining module 101, an abstract syntax tree generating module 102, a component data obtaining module 103, and a component document generating module 104, which may also be referred to as a unit, and refer to a series of computer program segments capable of being executed by a processor of an electronic device and performing fixed functions, and the computer program segments are stored in a memory of the electronic device.
In the present embodiment, the functions regarding the respective modules/units are as follows:
the component information obtaining module 101 is configured to obtain a markdown component template document, a component parameter, a component document header, and a component source code.
In the embodiment of the present invention, the markdown component template document refers to a component template document in a plain text format written by markdown (a lightweight markup language), where a component refers to a component in which one or more code segments that complete their respective functions are packaged into one or more independent parts.
In an embodiment of the present invention, the markdown component template document may be obtained from a development platform or a web page.
In the embodiment of the present invention, the component parameter, the component document title, and the component source code are component-related information codes written in advance by a user using a preset programming language, and mainly function to implement display of a front-end page of the user, where the component parameter may be a specific code, and parameter page configuration may be performed on a component by using the component parameter, and then a preset compiler is used to filter component parameters unnecessary for display of the front-end page of the user, where the component parameter includes: parameter names, component descriptions, component types, component codes, and default values.
Preferably, the programming language may be an open source programming language TypeScript, and the compiler may be a React-Docgen-TypeScript compiler.
In an embodiment of the present invention, the component document header refers to a subdocument header of a plurality of components, and each component stores information by a corresponding subdocument.
In the embodiment of the present invention, the component source code refers to code written by a user according to rules of a specific programming language and used for executing a specified task, and may be used to describe types of components in the component source code and interaction relationships among the components.
The abstract syntax tree generating module 102 is configured to parse the component parameters, the component document titles, and the component source codes to generate a parameter abstract syntax tree corresponding to the component parameters, a title abstract syntax tree corresponding to the component document titles, and a source code abstract syntax tree document corresponding to the component source codes.
In the embodiment of the present invention, an Abstract Syntax Tree (AST) refers to a Syntax structure that represents a programming language in a Tree form, each node on the Tree represents one structure in source codes, and the Abstract Syntax Tree mainly functions to embody the component parameters, the component document titles, and the logical relationships to be expressed by the component source codes in concrete codes.
In detail, the parsing the component parameter, the component document header, and the component source code to generate a parameter abstract syntax tree corresponding to the component parameter, a header abstract syntax tree corresponding to the component document header, and a source code abstract syntax tree corresponding to the component source code includes:
acquiring a parameter character string corresponding to the component parameter, a title character string corresponding to the component document title and a source code character string corresponding to the component source code;
and respectively connecting the parameter character strings, the title character strings and the source code character strings according to a tree structure to generate a parameter abstract syntax tree corresponding to the component parameters, a title abstract syntax tree corresponding to the component document titles and a source code abstract syntax tree corresponding to the component source codes.
In the embodiment of the present invention, the component parameter, the component document title, and the code corresponding to the component source code may be input into a preset converter, so as to obtain a parameter character string corresponding to the component parameter, a title character string corresponding to the component document title, and a source code character string corresponding to the component source code, which facilitates generation of an abstract syntax tree.
Preferably, the predetermined converter may be a Babel or Webpack loader.
Further, the abstract syntax tree generating module 102 connects the parameter character string, the header character string, and the source code character string according to a tree structure by performing the following operations, including:
performing lexical analysis on the parameter character string, the title character string and the source code character string respectively to obtain a parameter word sequence group included in the parameter character string, a title word sequence group included in the title character string and a source code word sequence group included in the source code character string;
and respectively connecting the parameter participle sequence group, the title participle sequence group and the source code participle sequence number group into a tree structure.
In an embodiment of the present invention, the lexical analysis is to convert a code in a character string form into a word segmentation sequence array Tokens, and the essence of the lexical analysis is to program some rules. For example, for number recognition at 101, when the program scans the first numeric character, it starts to be treated as a number until a non-numeric character is encountered; for another example, for the character string identification of "abc", when a double quotation mark or a single quotation mark is scanned, it is considered as a character string until another double quotation mark or a single quotation mark is encountered.
In the embodiment of the present invention, the word sequence set token may be a number, a text label, a punctuation mark, a text content, an operator, and the like.
In detail, the abstract syntax tree generating module 102 generates a parameter abstract syntax tree corresponding to the component parameter, a title abstract syntax tree corresponding to the component document title, and a source code abstract syntax tree corresponding to the component source code by performing the following operations, including:
respectively carrying out syntactic analysis on a parameter word segmentation sequence group included by the parameter character string, a title word segmentation sequence group included by the title character string and a source code word segmentation sequence group included by the source code character string, and respectively converting the parameter word segmentation sequence group, the title word segmentation sequence group and the source code word segmentation sequence group into a parameter analysis tree, a title analysis tree and a source code analysis tree according to preset grammar;
and performing semantic analysis on the parameter parsing tree, the title parsing tree and the source code parsing tree respectively to generate a plurality of initial nodes of the parameter parsing tree, a plurality of initial nodes of the title parsing tree and a plurality of initial nodes of the source code parsing tree, and respectively constructing a parameter abstract syntax tree corresponding to the component parameter, a title abstract syntax tree corresponding to the component document title and a source code abstract syntax tree corresponding to the component source code according to the hierarchical relationship among the initial nodes of the parameter parsing tree, the hierarchical relationship among the initial nodes of the title parsing tree and the hierarchical relationship among the initial nodes of the source code parsing tree.
In an embodiment of the present invention, the parse tree is a tree structure including all syntax information, and some redundant syntax information (for example, colon, parenthesis, and semicolon) included in the parse tree is deleted after semantic analysis of the parse tree, so as to obtain a simpler abstract syntax tree.
In another embodiment of the present invention, the parsing refers to performing abstract representation on the word sequence set Tokens; for example, describing the content in Tokens by using a non-terminator < >, the content in the non-terminator < > represents a syntactic component, and the content in Tokens is a terminator, so that the information extraction of the source code can be better realized through syntactic analysis.
In an optional embodiment of the present invention, the parsing refers to converting the word sequence groups Tokens into a parsing tree form, and may generate initial nodes of a plurality of tree nodes by performing semantic analysis on the parsing tree, and construct an abstract syntax tree according to a hierarchical relationship among the plurality of tree nodes, so as to implement deep parsing of the abstract syntax tree.
The component data obtaining module 103 is configured to obtain component data from the parameter abstract syntax tree, the header abstract syntax tree, and the source code abstract syntax tree.
In the embodiment of the invention, each node of the abstract syntax tree after semantic analysis is arranged according to the hierarchical relationship to display the data structure, priority and hierarchy in the source code, and the data in the source code also comprises blank grids, comments and repeated information, so that the abstract syntax tree can be deeply traversed to obtain the data corresponding to each node, the related information of a plurality of components can be obtained from the data, the component data with more distinct hierarchy can be obtained, and part of the component data required by a user can be directly obtained from a large amount of component data without searching one by one.
In the embodiment of the invention, the related data of the components comprises a plurality of component documents for displaying a front page of a user, a transmission mode of data corresponding to the components and related parameters for describing the functions of the components and realizing the functions.
In detail, the component data obtaining module 103 obtains component data from the parameter abstract syntax tree, the header abstract syntax tree and the source code abstract syntax tree by performing the following operations, including:
performing depth traversal on the parameter abstract syntax tree, the title abstract syntax tree and the source code abstract syntax tree to obtain data of a plurality of tree nodes;
component data is obtained from data of a plurality of the tree nodes.
In the embodiment of the invention, the abstract syntax tree comprises a plurality of tree nodes, and the tree nodes comprise a plurality of leaf nodes; for the deep traversal of the abstract syntax tree, the tree node which is traversed first from the initial tree node to the last tree node and then upwards can be traversed by using the Babel, and then the tree node which is traversed and has a plurality of leaf nodes is traversed downwards from another leaf node, so that the deep traversal is achieved.
For example, the abstract syntax tree consists of A, B, C, D four tree nodes, tree node A in turn consisting of a1And a2Two leaf nodes, tree node C consisting of C1And c2Two leaf nodes, then the abstract syntax tree is traversed, firstly from the leaf node a in the tree node A1Traverse down to B, c1And c2And D; traverse A, B, c in the upward direction1And c2And D, traversing to A and then from another leaf node a2A downward traversal to D is started to reach a depth traversal.
Further, the performing a deep traversal on the parameter abstract syntax tree, the header abstract syntax tree, and the source code abstract syntax tree to obtain data of a plurality of tree nodes includes:
respectively performing stack pressing operation on the parameter abstract syntax tree, the title abstract syntax tree and the source code abstract syntax tree to obtain fields corresponding to a plurality of tree nodes;
looping the push operation until the push operation becomes an empty stack;
when the stack pushing operation is changed into the empty stack, stopping circulation, and storing fields corresponding to all the tree nodes;
and converting the fields corresponding to all the tree nodes into data of a plurality of tree nodes.
In this embodiment, the stack refers to a linear table that performs an insertion or deletion operation only at the end of the table. An empty table without an element is called an empty stack. And the fields corresponding to the tree nodes refer to the related data of all the component functions and the implementation principle.
The component document generating module 104 is configured to obtain component configuration information of the markdown component template document, and insert the component data into the markdown component template document according to the component configuration information to obtain a component document.
In the embodiment of the present invention, the component configuration information refers to a calling process and a display sequence of the component data, and the configuration information of the markdown component template document may be obtained by using a preset regular rule or a preset document configuration language (for example, YAML language).
In detail, the inserting the component data into the markdown component template document according to the component configuration information to obtain a component document includes:
and displaying the corresponding component position of the component data in the markdown component template document according to the component configuration information, and inserting the component data into the component position to obtain a component document.
In an embodiment of the present invention, the component data may be connected to the preset interface by using a call function in the component parameter, and the component data is displayed as a user front-end page.
In the embodiment of the invention, the component document is used for recording the attribute relationship and the interaction relationship of each object in the component, the generated component document is an updated markdown document, the updated markdown document can be rendered through a calling function in the component parameter, and the component data is displayed as a user front-end page.
In the embodiment of the invention, firstly, a markdown component template document, component parameters, a component document title and a component source code are obtained; secondly, generating a parameter abstract syntax tree corresponding to the component parameters, a title abstract syntax tree corresponding to the component document title and a source code abstract syntax tree corresponding to the component source code, wherein the abstract syntax tree comprises a plurality of initial nodes, and each node corresponds to different component data, so that hierarchically distinct component data can be obtained, a user can conveniently inquire or modify the component source code, and the generation efficiency of a subsequent component document is improved; and then, acquiring the component configuration information of the markdown component template document, importing the component data into the markdown component template document according to the component configuration information to obtain the component document, and directly generating the component document according to the configuration information to improve the generation efficiency of the component document. Therefore, the component document generating device provided by the embodiment of the invention can improve the generating efficiency of the component document.
FIG. 3 is a schematic structural diagram of an electronic device implementing the component document generating method according to the present invention.
The electronic device may comprise a processor 10, a memory 11, a communication bus 12 and a communication interface 13, and may further comprise a computer program, such as a component documentation program, stored in the memory 11 and executable on the processor 10.
The memory 11 includes at least one type of media, which includes flash memory, removable hard disk, multimedia card, card type memory (e.g., SD or DX memory, etc.), magnetic memory, local disk, optical disk, etc. The memory 11 may in some embodiments be an internal storage unit of the electronic device, for example a removable hard disk of the electronic device. The memory 11 may also be an external storage device of the electronic device in other embodiments, such as a plug-in mobile hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like, which are provided on the electronic device. Further, the memory 11 may also include both an internal storage unit and an external storage device of the electronic device. The memory 11 may be used not only to store application software installed in the electronic device and various types of data, such as codes of a component document creation program, etc., but also to temporarily store data that has been output or is to be output.
The processor 10 may be composed of an integrated circuit in some embodiments, for example, a single packaged integrated circuit, or may be composed of a plurality of integrated circuits packaged with the same or different functions, including one or more Central Processing Units (CPUs), microprocessors, digital Processing chips, graphics processors, and combinations of various control chips. The processor 10 is a Control Unit (Control Unit) of the electronic device, connects various components of the whole electronic device by using various interfaces and lines, and executes various functions and processes data of the electronic device by running or executing programs or modules (e.g., component document creation programs, etc.) stored in the memory 11 and calling data stored in the memory 11.
The communication bus 12 may be a PerIPheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. The bus may be divided into an address bus, a data bus, a control bus, etc. The communication bus 12 is arranged to enable connection communication between the memory 11 and at least one processor 10 or the like. For ease of illustration, only one thick line is shown, but this does not mean that there is only one bus or one type of bus.
Fig. 3 shows only an electronic device having components, and those skilled in the art will appreciate that the structure shown in fig. 3 does not constitute a limitation of the electronic device, and may include fewer or more components than those shown, or some components may be combined, or a different arrangement of components.
For example, although not shown, the electronic device may further include a power supply (such as a battery) for supplying power to each component, and preferably, the power supply may be logically connected to the at least one processor 10 through a power management device, so that functions of charge management, discharge management, power consumption management and the like are realized through the power management device. The power supply may also include any component of one or more dc or ac power sources, recharging devices, power failure detection circuitry, power converters or inverters, power status indicators, and the like. The electronic device may further include various sensors, a bluetooth module, a Wi-Fi module, and the like, which are not described herein again.
Optionally, the communication interface 13 may include a wired interface and/or a wireless interface (e.g., WI-FI interface, bluetooth interface, etc.), which is generally used to establish a communication connection between the electronic device and other electronic devices.
Optionally, the communication interface 13 may further include a user interface, which may be a Display (Display), an input unit (such as a Keyboard (Keyboard)), and optionally, a standard wired interface, or a wireless interface. Alternatively, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, an OLED (Organic Light-Emitting Diode) touch device, or the like. The display, which may also be referred to as a display screen or display unit, is suitable, among other things, for displaying information processed in the electronic device and for displaying a visualized user interface.
It is to be understood that the described embodiments are for purposes of illustration only and that the scope of the appended claims is not limited to such structures.
The component document generation program stored in the memory 11 of the electronic device is a combination of a plurality of computer programs, which when executed in the processor 10, can implement:
acquiring a markdown component template document, component parameters, a component document title and a component source code;
analyzing the component parameters, the component document titles and the component source codes to generate parameter abstract syntax trees corresponding to the component parameters, title abstract syntax trees corresponding to the component document titles and source code abstract syntax trees corresponding to the component source codes;
acquiring component data from the parameter abstract syntax tree, the title abstract syntax tree and the source code abstract syntax tree;
acquiring the component configuration information of the markdown component template document, and importing the component data into the markdown component template document according to the component configuration information to obtain the component document.
Specifically, the processor 10 may refer to the description of the relevant steps in the embodiment corresponding to fig. 1 for a specific implementation method of the computer program, which is not described herein again.
Further, the electronic device integrated module/unit, if implemented in the form of a software functional unit and sold or used as a separate product, may be stored in a computer readable medium. The computer readable medium may be non-volatile or volatile. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U disk, removable hard disk, magnetic disk, optical disk, computer Memory, Read-Only Memory (ROM).
An embodiment of the present invention may further provide a computer medium, where the computer medium stores a computer program, and when the computer program is executed by a processor of an electronic device, the computer program may implement:
acquiring a markdown component template document, component parameters, a component document title and a component source code;
analyzing the component parameters, the component document titles and the component source codes to generate parameter abstract syntax trees corresponding to the component parameters, title abstract syntax trees corresponding to the component document titles and source code abstract syntax trees corresponding to the component source codes;
acquiring component data from the parameter abstract syntax tree, the title abstract syntax tree and the source code abstract syntax tree;
acquiring the component configuration information of the markdown component template document, and importing the component data into the markdown component template document according to the component configuration information to obtain the component document.
Further, the computer usable medium may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required for at least one function, and the like; the storage data area may store data created according to the use of the blockchain node, and the like.
In the embodiments provided in the present invention, it should be understood that the disclosed apparatus, device and method can be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the modules is only one logical functional division, and other divisions may be realized in practice.
The modules described as separate parts may or may not be physically separate, and parts displayed as modules may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment.
In addition, functional modules in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, or in a form of hardware plus a software functional module.
It will be evident to those skilled in the art that the invention is not limited to the details of the foregoing illustrative embodiments, and that the present invention may be embodied in other specific forms without departing from the spirit or essential attributes thereof.
The present embodiments are therefore to be considered in all respects as illustrative and not restrictive, the scope of the invention being indicated by the appended claims rather than by the foregoing description, and all changes which come within the meaning and range of equivalency of the claims are therefore intended to be embraced therein. Any reference signs in the claims shall not be construed as limiting the claim concerned.
The block chain is a novel application mode of computer technologies such as distributed data storage, point-to-point transmission, a consensus mechanism, an encryption algorithm and the like. A block chain (Blockchain), which is essentially a decentralized database, is a series of data blocks associated by using a cryptographic method, and each data block contains information of a batch of network transactions, so as to verify the validity (anti-counterfeiting) of the information and generate a next block. The blockchain may include a blockchain underlying platform, a platform product service layer, an application service layer, and the like.
Furthermore, it is obvious that the word "comprising" does not exclude other elements or steps, and the singular does not exclude the plural. A plurality of units or means recited in the system claims may also be implemented by one unit or means in software or hardware. The terms second, etc. are used to denote names, but not any particular order.
Finally, it should be noted that the above embodiments are only for illustrating the technical solutions of the present invention and not for limiting, and although the present invention is described in detail with reference to the preferred embodiments, it should be understood by those skilled in the art that modifications or equivalent substitutions may be made on the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention.