Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F101727336
libmultiscale_doc_parser.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Feb 13, 02:56
Size
1 KB
Mime Type
text/x-python
Expires
Sat, Feb 15, 02:56 (2 d)
Engine
blob
Format
Raw Data
Handle
24222933
Attached To
rLIBMULTISCALE LibMultiScale
libmultiscale_doc_parser.py
View Options
#!/usr/bin/env python3
import
pyparsing
as
pp
class
LibMultiScaleParser
:
etag
=
pp
.
Literal
(
"*/"
)
tag_desc
=
pp
.
Literal
(
"/* LMDESC"
)
tag_keyword
=
pp
.
Literal
(
"/* LMKEYWORD"
)
tag_heritance
=
pp
.
Literal
(
"/* LMHERITANCE"
)
tag_example
=
pp
.
Literal
(
"/* LMEXAMPLE"
)
def
block
(
self
,
tag
):
_header
=
pp
.
SkipTo
(
tag
)
+
tag
_content
=
pp
.
SkipTo
(
self
.
etag
)
_block
=
_header
.
suppress
()
-
_content
_block
-=
self
.
etag
.
suppress
()
return
_block
def
named_block
(
self
,
tag
):
_header
=
pp
.
SkipTo
(
tag
)
+
tag
_header
+=
pp
.
ZeroOrMore
(
pp
.
White
())
_block
=
_header
.
suppress
()
-
pp
.
Word
(
pp
.
alphanums
+
"_"
)
_block
-=
pp
.
OneOrMore
(
pp
.
White
()
|
pp
.
LineEnd
())
.
suppress
()
_block
-=
pp
.
SkipTo
(
self
.
etag
)
_block
-=
self
.
etag
.
suppress
()
res
=
_block
return
res
def
parse
(
self
,
filename
,
internal_key_list
):
fin
=
open
(
filename
,
'r'
)
inp
=
fin
.
read
()
fin
.
close
()
_content
=
self
.
named_block
(
self
.
tag_desc
)
.
setResultsName
(
"description"
)
example
=
self
.
block
(
self
.
tag_example
)
_content
+=
pp
.
Optional
(
example
)
.
setResultsName
(
"example"
)
heritance
=
self
.
block
(
self
.
tag_heritance
)
_content
+=
pp
.
Optional
(
heritance
)
.
setResultsName
(
"heritance"
)
keyword
=
self
.
named_block
(
self
.
tag_keyword
)
_content
+=
pp
.
Group
(
pp
.
ZeroOrMore
(
keyword
))
.
setResultsName
(
"keywords"
)
res
=
_content
.
parseString
(
inp
)
return
dict
([(
k
,
res
.
get
(
k
))
for
k
in
res
.
keys
()])
Event Timeline
Log In to Comment