Parser Internals¶
This page documents the parser classes used inside gmshparser. They are exposed for compatibility and development, but application code should normally use gmshparser.read() or gmshparser.parse().
Main dispatch¶
gmshparser.main_parser.MainParser
¶
Route MSH sections to version-specific parsers with source context.
Source code in gmshparser/main_parser.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
parsers = parsers
instance-attribute
¶
version_detected = False
instance-attribute
¶
__init__(parsers=None)
¶
_get_parsers_for_version(mesh)
¶
Return the parser set for the detected major MSH version.
Source code in gmshparser/main_parser.py
_parse_section(parser, mesh, source, section)
staticmethod
¶
Source code in gmshparser/main_parser.py
parse(mesh, io)
¶
Parse an MSH stream and populate mesh.
All section failures are exposed as structured ParseError subclasses
carrying the source name, current section, line number, and line text.
Source code in gmshparser/main_parser.py
MainParser detects the MSH version, selects a version-specific parser registry, and dispatches recognized section headers. Unknown sections are skipped.
Parser interface¶
gmshparser.abstract_parser.AbstractParser
¶
AbstractParser is a superclass of section parsers.
Section parsers inherit AbstractParser and implement the static methods
parse and get_section_name.
The first argument of parse is a mutable mesh object that the parser
modifies in place. The second argument is the text stream. A section parser
consumes input through its matching end marker, such as $EndNodes.
Source code in gmshparser/abstract_parser.py
get_section_name()
staticmethod
¶
Section parsers receive a mutable parser target and a text stream positioned immediately after the section header. The compatibility Mesh and ModernMeshBuilder implement the shared target operations.
Common sections¶
gmshparser.mesh_format_parser.MeshFormatParser
¶
Bases: AbstractParser
Parse and validate the $MeshFormat section.
Source code in gmshparser/mesh_format_parser.py
get_section_name()
staticmethod
¶
parse(mesh, io)
staticmethod
¶
Source code in gmshparser/mesh_format_parser.py
gmshparser.physical_names_parser.PhysicalNamesParser
¶
Bases: AbstractParser
Parse optional $PhysicalNames declarations.
Source code in gmshparser/physical_names_parser.py
get_section_name()
staticmethod
¶
parse(mesh, io)
staticmethod
¶
Source code in gmshparser/physical_names_parser.py
MSH 1.0¶
gmshparser.nodes_parser_v1.NodesParserV1
¶
Bases: AbstractParser
Parse the legacy MSH 1.0 $NOD section.
Source code in gmshparser/nodes_parser_v1.py
get_section_name()
staticmethod
¶
parse(mesh, io)
staticmethod
¶
Source code in gmshparser/nodes_parser_v1.py
gmshparser.elements_parser_v1.ElementsParserV1
¶
Bases: AbstractParser
Parse the legacy MSH 1.0 $ELM section.
Source code in gmshparser/elements_parser_v1.py
get_section_name()
staticmethod
¶
parse(mesh, io)
staticmethod
¶
Source code in gmshparser/elements_parser_v1.py
MSH 2.x¶
gmshparser.nodes_parser_v2.NodesParserV2
¶
Bases: AbstractParser
Parse flat MSH 2.x node records.
Source code in gmshparser/nodes_parser_v2.py
get_section_name()
staticmethod
¶
parse(mesh, io)
staticmethod
¶
Source code in gmshparser/nodes_parser_v2.py
gmshparser.elements_parser_v2.ElementsParserV2
¶
Bases: AbstractParser
Parse flat MSH 2.x element records.
Source code in gmshparser/elements_parser_v2.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
get_section_name()
staticmethod
¶
parse(mesh, io)
staticmethod
¶
Source code in gmshparser/elements_parser_v2.py
MSH 4.x¶
gmshparser.entities_parser.EntitiesParser
¶
Bases: AbstractParser
Parse MSH 4.0 and 4.1 entity records and physical assignments.
Source code in gmshparser/entities_parser.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
get_section_name()
staticmethod
¶
parse(mesh, io)
staticmethod
¶
Source code in gmshparser/entities_parser.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
gmshparser.nodes_parser.NodesParser
¶
Bases: AbstractParser
Parse entity-block nodes from MSH 4.0 and 4.1 files.
Source code in gmshparser/nodes_parser.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
get_section_name()
staticmethod
¶
parse(mesh, io)
staticmethod
¶
Source code in gmshparser/nodes_parser.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
gmshparser.elements_parser.ElementsParser
¶
Bases: AbstractParser
Parse entity-block elements from MSH 4.0 and 4.1 files.
Source code in gmshparser/elements_parser.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
get_section_name()
staticmethod
¶
parse(mesh, io)
staticmethod
¶
Source code in gmshparser/elements_parser.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
Version registries¶
The parser lists are defined in gmshparser.main_parser:
Add a section parser only to the format families whose record layout it understands. See Writing Parsers for the implementation and test checklist.