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
3b1e99df
Commit
3b1e99df
authored
Oct 28, 2019
by
Savva Golubitsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
First parser implementation
parent
1b6fe950
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
0 deletions
+59
-0
parser.py
comsdk/parser.py
+59
-0
No files found.
comsdk/parser.py
0 → 100644
View file @
3b1e99df
import
re
from
typing
import
NamedTuple
from
enum
import
Enum
,
auto
# Ключевые слова, описывающие граф
scope
=
[
"__BEGIN__"
,
"__END__"
]
class
Stmt
():
__slots__
=
(
'name'
,
'module'
,
'entry_func'
,
'predicate'
,
'selector'
,
'function'
,
'morphism'
,
'parallelism'
)
def
__init__
(
self
,
name
):
for
slot
in
self
.
__slots__
:
setattr
(
self
,
slot
,
None
)
self
.
name
=
name
def
__str__
(
self
):
stri
=
""
for
s
in
self
.
__slots__
:
stri
+=
s
+
": {}, "
.
format
(
getattr
(
self
,
s
))
return
stri
# ent = [{"name":{"module":"val" , "entr_func":"val"...}}]
dotfile
=
open
(
"./testgr.adot"
,
"r"
)
.
read
()
graphcheck
=
re
.
match
(
r"\A(digraph)\s+\w*\n{(.*\s)*}\Z"
,
dotfile
)
if
graphcheck
is
None
:
print
(
"Incorrect graph, check syntax!"
)
exit
()
# Все что до __BEGIN__ считается объявлением
beg
=
re
.
search
((
scope
[
0
]),
dotfile
)
.
start
()
stmts
=
[]
rawstmts
=
re
.
findall
(
r"\w+\s\[.*\]"
,
dotfile
[:
beg
])
for
raw
in
rawstmts
:
res
=
raw
.
split
(
r" "
,
1
)
st
=
Stmt
(
res
[
0
])
rs
=
res
[
1
][
1
:
-
1
]
.
split
(
r", "
)
for
r
in
rs
:
r
=
r
.
split
(
r"="
,
1
)
for
s
in
st
.
__slots__
:
if
s
==
r
[
0
]:
setattr
(
st
,
s
,
r
[
1
])
print
(
st
)
stmts
.
append
(
st
)
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