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
Snippets
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
Show more breadcrumbs
Berk Onat
python-common
Commits
dccab323
Commit
dccab323
authored
8 years ago
by
Lauri Himanen
Browse files
Options
Downloads
Patches
Plain Diff
Added possibility for SimpleMatcher specific onClose and onOpen callbacks.
parent
ef36b89a
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
common/python/nomadcore/simple_parser.py
+30
-4
30 additions, 4 deletions
common/python/nomadcore/simple_parser.py
with
30 additions
and
4 deletions
common/python/nomadcore/simple_parser.py
+
30
−
4
View file @
dccab323
...
@@ -74,7 +74,9 @@ class SimpleMatcher(object):
...
@@ -74,7 +74,9 @@ class SimpleMatcher(object):
defLine
=
0
,
defLine
=
0
,
defFile
=
''
,
defFile
=
''
,
coverageIgnore
=
False
,
# mark line as ignored in coverage analysis
coverageIgnore
=
False
,
# mark line as ignored in coverage analysis
endAction
=
None
,
endAction
=
None
,
# A function that is called when this SimpleMatcher finishes
onClose
=
None
,
# A dictionary of onClose callbacks that are specific to this SimpleMatcher
onOpen
=
None
,
# A dictionary of onClose callbacks that are specific to this SimpleMatcher
):
):
self
.
index
=
-
1
self
.
index
=
-
1
self
.
startReStr
=
startReStr
self
.
startReStr
=
startReStr
...
@@ -94,6 +96,9 @@ class SimpleMatcher(object):
...
@@ -94,6 +96,9 @@ class SimpleMatcher(object):
self
.
name
=
name
self
.
name
=
name
self
.
fixedStartValues
=
fixedStartValues
self
.
fixedStartValues
=
fixedStartValues
self
.
fixedEndValues
=
fixedEndValues
self
.
fixedEndValues
=
fixedEndValues
self
.
endAction
=
endAction
self
.
onClose
=
onClose
self
.
onOpen
=
onOpen
self
.
keep
=
False
# Boolean flag used by the ParserOptimizer to determine which SimpleMatchers to keep
self
.
keep
=
False
# Boolean flag used by the ParserOptimizer to determine which SimpleMatchers to keep
# boolean flag to signal that this SimpleMatcher does not have any
# boolean flag to signal that this SimpleMatcher does not have any
# effect (besides progressing input file):
# effect (besides progressing input file):
...
@@ -119,7 +124,6 @@ class SimpleMatcher(object):
...
@@ -119,7 +124,6 @@ class SimpleMatcher(object):
"
and is marked as coverageIgnore
"
,
name
)
"
and is marked as coverageIgnore
"
,
name
)
self
.
coverageIgnore
=
coverageIgnore
self
.
coverageIgnore
=
coverageIgnore
self
.
endAction
=
endAction
caller
=
inspect
.
currentframe
()
caller
=
inspect
.
currentframe
()
if
(
defFile
==
''
)
and
(
defLine
==
0
):
if
(
defFile
==
''
)
and
(
defLine
==
0
):
if
(
caller
is
not
None
)
and
(
caller
.
f_back
is
not
None
):
if
(
caller
is
not
None
)
and
(
caller
.
f_back
is
not
None
):
...
@@ -1089,18 +1093,40 @@ class SimpleParser(object):
...
@@ -1089,18 +1093,40 @@ class SimpleParser(object):
compiledMatcher
=
self
.
parserBuilder
.
compiledMatchers
[
stateIndex
]
compiledMatcher
=
self
.
parserBuilder
.
compiledMatchers
[
stateIndex
]
sects
=
OrderedDict
()
sects
=
OrderedDict
()
for
s
in
compiledMatcher
.
matcher
.
sections
:
for
s
in
compiledMatcher
.
matcher
.
sections
:
sects
[
s
]
=
self
.
backend
.
openSection
(
s
)
gIndex
=
self
.
backend
.
openSection
(
s
)
sects
[
s
]
=
gIndex
# Call the matcher specific onOpen callbacks
if
compiledMatcher
.
matcher
.
onOpen
:
callback
=
compiledMatcher
.
matcher
.
onOpen
.
get
(
s
)
if
callback
:
section_manager
=
self
.
backend
.
sectionManagers
[
s
]
section
=
section_manager
.
openSections
[
gIndex
]
callback
(
self
.
backend
,
gIndex
,
section
)
self
.
context
.
append
(
ParsingContext
(
stateIndex
,
sects
,
compiledMatcher
,
ParsingContext
.
Start
))
self
.
context
.
append
(
ParsingContext
(
stateIndex
,
sects
,
compiledMatcher
,
ParsingContext
.
Start
))
def
contextClose
(
self
,
cNow
):
def
contextClose
(
self
,
cNow
):
# Handle end action before closing sections
# Handle end action before closing sections
# Call the end action
# Call the end action
if
cNow
.
compiledMatcher
.
matcher
.
endAction
:
if
cNow
.
compiledMatcher
.
matcher
.
endAction
:
cNow
.
compiledMatcher
.
matcher
.
endAction
()
cNow
.
compiledMatcher
.
matcher
.
endAction
()
if
cNow
.
startEnd
==
ParsingContext
.
Start
:
if
cNow
.
startEnd
==
ParsingContext
.
Start
:
for
s
,
gIndex
in
reversed
(
list
(
cNow
.
sections
.
items
())):
for
s
,
gIndex
in
reversed
(
list
(
cNow
.
sections
.
items
())):
# Call the matcher specific onClose callbacks
if
cNow
.
compiledMatcher
.
matcher
.
onClose
:
callback
=
cNow
.
compiledMatcher
.
matcher
.
onClose
.
get
(
s
)
if
callback
:
section_manager
=
self
.
backend
.
sectionManagers
[
s
]
section
=
section_manager
.
openSections
[
gIndex
]
callback
(
self
.
backend
,
gIndex
,
section
)
# Call the global onClose callbacks
self
.
backend
.
closeSection
(
s
,
gIndex
)
self
.
backend
.
closeSection
(
s
,
gIndex
)
cNow
.
startEnd
=
ParsingContext
.
End
cNow
.
startEnd
=
ParsingContext
.
End
return
True
return
True
else
:
else
:
...
...
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