Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
python-common
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
nomad-lab
python-common
Commits
7dfa27d4
Commit
7dfa27d4
authored
9 years ago
by
Massimo Riello
Browse files
Options
Downloads
Patches
Plain Diff
Ancillary parsers can be compiled/executed during the main parser call
parent
4b91efce
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
common/python/nomadcore/simple_parser.py
+29
-17
29 additions, 17 deletions
common/python/nomadcore/simple_parser.py
with
29 additions
and
17 deletions
common/python/nomadcore/simple_parser.py
+
29
−
17
View file @
7dfa27d4
...
@@ -1049,13 +1049,38 @@ class SimpleParser(object):
...
@@ -1049,13 +1049,38 @@ class SimpleParser(object):
while
self
.
parseStep
():
while
self
.
parseStep
():
pass
pass
def
compileParser
(
simpleParser
,
metaInfo
,
metaInfoToKeep
):
"""
compiles the given simple parser
"""
parserBuilder
=
SimpleParserBuilder
(
simpleParser
,
metaInfo
,
metaInfoToKeep
)
if
logger
.
isEnabledFor
(
logging
.
DEBUG
):
s
=
StringIO
.
StringIO
()
s
.
write
(
"
matchers:
"
)
parserBuilder
.
writeMatchers
(
s
,
2
)
logger
.
debug
(
s
.
getvalue
())
if
not
parserBuilder
.
verifyMetaInfo
(
sys
.
stderr
):
sys
.
exit
(
1
)
parserBuilder
.
compile
()
if
logger
.
isEnabledFor
(
logging
.
DEBUG
):
s
=
StringIO
.
StringIO
()
s
.
write
(
"
compiledMatchers:
"
)
parserBuilder
.
writeCompiledMatchers
(
s
,
2
)
logger
.
debug
(
s
.
getvalue
())
return
parserBuilder
def
runParser
(
compiledParser
,
backend
,
superContext
,
fIn
):
"""
parses the open file fIn with the given compiledParser into the backend using superContext as parser SuperContext
"""
parser
=
compiledParser
.
buildParser
(
PushbackLineFile
(
fIn
),
backend
,
superContext
=
superContext
)
parser
.
parse
()
def
defaultParseFile
(
parserInfo
):
def
defaultParseFile
(
parserInfo
):
def
parseF
(
parserBuilder
,
uri
,
path
,
backend
,
superContext
):
def
parseF
(
parserBuilder
,
uri
,
path
,
backend
,
superContext
):
with
open
(
path
,
"
r
"
)
as
fIn
:
with
open
(
path
,
"
r
"
)
as
fIn
:
backend
.
startedParsingSession
(
uri
,
parserInfo
)
backend
.
startedParsingSession
(
uri
,
parserInfo
)
parser
=
parserBuilder
.
buildParser
(
PushbackLineFile
(
fIn
),
backend
,
try
:
superContext
=
superContext
)
superContext
.
startedParsing
(
path
)
parser
.
parse
()
except
AttributeError
:
pass
runParser
(
parserBuilder
,
backend
,
superContext
,
fIn
)
backend
.
finishedParsingSession
(
"
ParseSuccess
"
,
None
)
backend
.
finishedParsingSession
(
"
ParseSuccess
"
,
None
)
return
parseF
return
parseF
...
@@ -1152,20 +1177,7 @@ def mainFunction(mainFileDescription, metaInfoEnv, parserInfo,
...
@@ -1152,20 +1177,7 @@ def mainFunction(mainFileDescription, metaInfoEnv, parserInfo,
metaInfoToKeep
=
specializationInfo
.
get
(
"
metaInfoToKeep
"
)
metaInfoToKeep
=
specializationInfo
.
get
(
"
metaInfoToKeep
"
)
# initialize the parser builder
# initialize the parser builder
parserBuilder
=
SimpleParserBuilder
(
mainFileDescription
,
metaInfoEnv
,
metaInfoToKeep
)
parserBuilder
=
compileParser
(
mainFileDescription
,
metaInfoEnv
,
metaInfoToKeep
)
if
logger
.
isEnabledFor
(
logging
.
DEBUG
):
s
=
StringIO
.
StringIO
()
s
.
write
(
"
matchers:
"
)
parserBuilder
.
writeMatchers
(
s
,
2
)
logger
.
debug
(
s
.
getvalue
())
if
not
parserBuilder
.
verifyMetaInfo
(
sys
.
stderr
):
sys
.
exit
(
1
)
parserBuilder
.
compile
()
if
logger
.
isEnabledFor
(
logging
.
DEBUG
):
s
=
StringIO
.
StringIO
()
s
.
write
(
"
compiledMatchers:
"
)
parserBuilder
.
writeCompiledMatchers
(
s
,
2
)
logger
.
debug
(
s
.
getvalue
())
if
fileToParse
:
if
fileToParse
:
if
writeComma
:
if
writeComma
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment