Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pycomsdk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
com
pycomsdk
Commits
20635758
Commit
20635758
authored
Oct 29, 2019
by
Savva Golubitsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
topology regexp and line after line processing
parent
fcfb8126
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
14 deletions
+72
-14
parser.py
comsdk/parser.py
+72
-14
No files found.
comsdk/parser.py
View file @
20635758
...
@@ -8,7 +8,7 @@ scope = [
...
@@ -8,7 +8,7 @@ scope = [
"__END__"
"__END__"
]
]
class
Stmt
():
class
Parms
():
__slots__
=
(
__slots__
=
(
'module'
,
'module'
,
'entry_func'
,
'entry_func'
,
...
@@ -28,33 +28,91 @@ class Stmt():
...
@@ -28,33 +28,91 @@ class Stmt():
stri
+=
s
+
": {}, "
.
format
(
getattr
(
self
,
s
))
stri
+=
s
+
": {}, "
.
format
(
getattr
(
self
,
s
))
return
stri
return
stri
#Props is line "[prop=smth, ...]"
def
parm_from_props
(
props
):
parm
=
Parms
()
rs
=
re
.
split
(
r",\s*"
,
props
[:
-
1
])
#.split(r", ")
for
r
in
rs
:
r
=
r
.
split
(
r"="
,
1
)
for
s
in
parm
.
__slots__
:
if
s
==
r
[
0
]:
setattr
(
parm
,
s
,
r
[
1
])
return
parm
def
parm_from_entln
(
raw
):
res
=
re
.
split
(
r"\["
,
raw
,
1
)
return
res
[
0
],
parm_from_props
(
res
[
1
])
def
parm_from_topln
(
raw
):
print
(
raw
)
spl
=
re
.
split
(
r"\s*(=>|->|\[)\s*"
,
raw
)
print
(
spl
)
# ent = [{"name":{"module":"val" , "entr_func":"val"...}}]
# ent = [{"name":{"module":"val" , "entr_func":"val"...}}]
dotfile
=
open
(
"./testgr.adot"
,
"r"
)
.
read
()
file
=
open
(
"./testgr.adot"
,
"r"
)
graphcheck
=
re
.
match
(
r"\A(digraph)\s+\w*\n{(.*\s)*}\Z"
,
dotfile
)
dot
=
file
.
read
()
graphcheck
=
re
.
fullmatch
(
r"\A(digraph)\s+\w*\n{(.*\s)*}\Z"
,
dot
)
if
graphcheck
is
None
:
if
graphcheck
is
None
:
print
(
"Incorrect graph, check syntax!"
)
print
(
"Incorrect graph, check syntax!"
)
exit
()
exit
()
file
.
seek
(
0
)
dotfile
=
file
.
readlines
()
entities
=
{}
topology
=
{}
# ent_re - regular expr for edges, states, functions properties
ent_re
=
re
.
compile
(
r"^\w+\[.*\]$"
)
# top_re - regular expr for topology properties, most time consuming one
top_re
=
re
.
compile
(
r"^(\w+,?)+(->|=>)(\w+,?)+(\[(\w+=(\(?\w+,?\)?)+,?)+\])?"
)
# (r"^\w[\w\s,]*(->|=>)\s*\w[\w\s,=\[\]()]*$")
# com_re - regular expr for comment
com_re
=
re
.
compile
(
r"^\s*//.*$"
)
for
i
,
ln
in
enumerate
(
dotfile
):
ln
=
re
.
sub
(
r"\s"
,
""
,
ln
)
#deleting all spaces
if
com_re
.
match
(
ln
)
or
len
(
ln
)
==
0
:
continue
elif
ent_re
.
match
(
ln
):
name
,
parm
=
parm_from_entln
(
ln
)
entities
[
name
]
=
parm
elif
top_re
.
match
(
ln
):
parm_from_topln
(
ln
)
#for e in entities:
# print(e, entities[e])
exit
()
# Все что до __BEGIN__ считается объявлением
# Все что до __BEGIN__ считается объявлением
beg
=
re
.
search
((
scope
[
0
]),
dotfile
)
.
start
()
beg
=
re
.
search
((
scope
[
0
]),
dotfile
)
.
start
()
stmt
s
=
{}
entitie
s
=
{}
rawstmts
=
re
.
findall
(
r"\w+\s\[.*\]"
,
dotfile
[:
beg
])
#Парсинг свойств переходов и состояний
for
raw
in
rawstmts
:
rawents
=
re
.
findall
(
r"\w+\s*?\[.*\]"
,
dotfile
[:
beg
])
res
=
raw
.
split
(
r" "
,
1
)
for
raw
in
rawents
:
st
=
Stmt
()
res
=
re
.
split
(
r"\s+"
,
raw
,
1
)
rs
=
res
[
1
][
1
:
-
1
]
.
split
(
r", "
)
ent
=
Parms
()
rs
=
re
.
split
(
r",\s*"
,
res
[
1
][
1
:
-
1
])
#.split(r", ")
for
r
in
rs
:
for
r
in
rs
:
r
=
r
.
split
(
r"="
,
1
)
r
=
r
.
split
(
r"="
,
1
)
for
s
in
s
t
.
__slots__
:
for
s
in
en
t
.
__slots__
:
if
s
==
r
[
0
]:
if
s
==
r
[
0
]:
setattr
(
st
,
s
,
r
[
1
])
setattr
(
ent
,
s
,
r
[
1
])
stmts
[
res
[
0
]]
=
st
entities
[
res
[
0
]]
=
ent
for
s
in
entities
:
print
(
s
,
entities
[
s
])
for
s
in
stmts
:
#Парсинг топологии графа
print
(
s
,
stmts
[
s
])
rawstmts
=
re
.
findall
(
r"\s*([\w,\s]*(->|=>)[\w,\s]*(\[.*\])?)\n"
,
dotfile
[
beg
:])
print
(
rawstmts
)
# for raw in rawstmts:
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment