CN113971044A - Component document generation method, device, equipment and readable storage medium - Google Patents

Component document generation method, device, equipment and readable storage medium Download PDF

Info

Publication number
CN113971044A
CN113971044A CN202111270920.1A CN202111270920A CN113971044A CN 113971044 A CN113971044 A CN 113971044A CN 202111270920 A CN202111270920 A CN 202111270920A CN 113971044 A CN113971044 A CN 113971044A
Authority
CN
China
Prior art keywords
component
abstract syntax
tree
document
source code
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
CN202111270920.1A
Other languages
Chinese (zh)
Inventor
董帮付
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ping An Technology Shenzhen Co Ltd
Original Assignee
Ping An Technology Shenzhen 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 Ping An Technology Shenzhen Co Ltd filed Critical Ping An Technology Shenzhen Co Ltd
Priority to CN202111270920.1A priority Critical patent/CN113971044A/en
Publication of CN113971044A publication Critical patent/CN113971044A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/73Program documentation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/10Text processing
    • G06F40/166Editing, e.g. inserting or deleting
    • G06F40/186Templates
    • 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)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Software Systems (AREA)
  • Computational Linguistics (AREA)
  • General Health & Medical Sciences (AREA)
  • Health & Medical Sciences (AREA)
  • Audiology, Speech & Language Pathology (AREA)
  • Artificial Intelligence (AREA)
  • Library & Information Science (AREA)
  • Document Processing Apparatus (AREA)

Abstract

The invention relates to the field of data processing, and discloses a component document generation method, which comprises the following steps: 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. The invention also relates to a blockchain technique, and the component document can be stored in a blockchain link point. The invention also provides a device, equipment and medium for generating the component document. The invention can improve the generation efficiency of the component document.

Description

Component document generation method, device, equipment and readable storage medium
Technical Field
The present invention relates to the field of data processing, and in particular, to a method and an apparatus for generating a component document, an electronic device, and a readable storage medium.
Background
With the development of the internet, more and more components are involved in the development process of the user interface, and when developers write the finished components, documents corresponding to the components need to be written so that other developers can use the components conveniently.
At present, a component document is generated by manually writing the component document by a developer, so that the generated component document is unclear in hierarchy and needs to be written at a high labor cost, and the generation efficiency of the component document is low.
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.
Drawings
FIG. 1 is a flowchart illustrating a component document generating method according to an embodiment of the present invention;
FIG. 2 is a block diagram of a component document generating apparatus according to an embodiment of the present invention;
FIG. 3 is a schematic diagram of an internal structure of an electronic device implementing a component document generating method according to an embodiment of the present invention;
the implementation, functional features and advantages of the objects of the present invention will be further explained with reference to the accompanying drawings.
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.

Claims (10)

1. A method for component document generation, the method comprising:
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.
2. The method for generating a component document according to claim 1, wherein 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.
3. The component document generating method according to claim 2, wherein the connecting the parameter character string, the title character string, and the source code character string in a tree structure respectively comprises:
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.
4. The component document generation method according to claim 2, wherein 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 comprises:
converting the parameter word sequence groups, the title word sequence groups and the source code word sequence groups into a parameter analysis tree, a title analysis tree and a source code analysis tree according to preset grammars respectively by using the parameter word sequence groups included by the parameter character strings, the title word sequence groups included by the title character strings and the source code word sequence groups included by the source code character strings;
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.
5. The component document generation method of claim 1, wherein the obtaining component data from the parameter abstract syntax tree, the title abstract syntax tree, and the source code abstract syntax tree comprises:
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.
6. The method of generating a component document according to claim 5, wherein the performing a deep traversal of 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 comprises:
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.
7. The method for generating a component document according to any one of claims 1 to 6, wherein the inserting the component data into the markdown component template document according to the component configuration information to obtain a component document comprises:
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.
8. An apparatus for generating a component document, the apparatus comprising:
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.
9. An electronic device, characterized in that the electronic device comprises:
at least one processor; and the number of the first and second groups,
a memory communicatively coupled to the at least one processor; wherein,
the memory stores computer program instructions executable by the at least one processor to enable the at least one processor to perform the component document generation method of any one of claims 1 to 7.
10. A computer medium storing a computer program, wherein the computer program, when executed by a processor, implements the component document generating method according to any one of claims 1 to 7.
CN202111270920.1A 2021-10-29 2021-10-29 Component document generation method, device, equipment and readable storage medium Pending CN113971044A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111270920.1A CN113971044A (en) 2021-10-29 2021-10-29 Component document generation method, device, equipment and readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111270920.1A CN113971044A (en) 2021-10-29 2021-10-29 Component document generation method, device, equipment and readable storage medium

Publications (1)

Publication Number Publication Date
CN113971044A true CN113971044A (en) 2022-01-25

Family

ID=79588955

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111270920.1A Pending CN113971044A (en) 2021-10-29 2021-10-29 Component document generation method, device, equipment and readable storage medium

Country Status (1)

Country Link
CN (1) CN113971044A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116048526A (en) * 2023-02-13 2023-05-02 中国南方航空股份有限公司 Method, device and storage medium for processing route availability document

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116048526A (en) * 2023-02-13 2023-05-02 中国南方航空股份有限公司 Method, device and storage medium for processing route availability document
CN116048526B (en) * 2023-02-13 2023-11-10 中国南方航空股份有限公司 Method, device and storage medium for processing route availability document

Similar Documents

Publication Publication Date Title
CN111813963B (en) Knowledge graph construction method and device, electronic equipment and storage medium
CN109086046A (en) A kind of front-end code automatic generation method and system based on interface specification document
CN111428451B (en) Text online editing method and device, electronic equipment and storage medium
CN111124379B (en) Page generation method and device, electronic equipment and storage medium
CN101859303A (en) Metadata management method and management system
CN112540862A (en) Interface document data generation method, device, equipment and storage medium
CN113672781A (en) Data query method and device, electronic equipment and storage medium
CN114090671A (en) Data import method and device, electronic equipment and storage medium
CN115358200A (en) Template document automatic generation method based on SysML meta model
CN115408399A (en) Blood relationship analysis method, device, equipment and storage medium based on SQL script
CN113687827B (en) Data list generation method, device and equipment based on widget and storage medium
CN114385167A (en) Front-end page generation method, device, equipment and medium
CN113434542B (en) Data relationship identification method and device, electronic equipment and storage medium
CN109947711B (en) Automatic multi-language file management method in IOS project development process
CN113971044A (en) Component document generation method, device, equipment and readable storage medium
CN114398282A (en) Test script generation method, device, equipment and storage medium
JP4724387B2 (en) Program conversion program, program conversion apparatus, and program conversion method
CN110175022B (en) Method and device for automatically generating POJO class, storage medium and computer equipment
JPH09146931A (en) Document type definition generating device
CN116431481A (en) Code parameter verification method and device based on multi-code condition
CN114385155A (en) vue project visualization tool generation method, device, equipment and storage medium
CN114625376A (en) Data transfer mode conversion method and device, electronic equipment and readable storage medium
CN114610807A (en) Data import template configuration method, device, equipment and storage medium
CN114253548A (en) XML document processing method and device, electronic equipment and storage medium
CN114637532A (en) Method for automatically obtaining comments and generating interface document according to fields

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