Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pykat
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
finesse
pykat
Commits
4967a580
Commit
4967a580
authored
11 years ago
by
Andreas Freise
Browse files
Options
Downloads
Patches
Plain Diff
removing comments from input file (except for %%% which is needed for FTBlock etc).
parent
f8854255
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
pykat/finesse.py
+26
-3
26 additions, 3 deletions
pykat/finesse.py
with
26 additions
and
3 deletions
pykat/finesse.py
+
26
−
3
View file @
4967a580
...
...
@@ -32,6 +32,7 @@ import datetime
import
pickle
import
pykat
import
warnings
import
re
from
pykat.exceptions
import
*
...
...
@@ -116,14 +117,22 @@ class kat(object):
def
noxaxis
(
self
,
value
):
self
.
__noxaxis
=
bool
(
value
)
def
loadKatFile
(
self
,
katfile
):
with
open
(
katfile
)
as
f
:
self
.
parseCommands
(
f
.
readlines
())
commands
=
open
(
katfile
).
read
()
self
.
parseCommands
(
commands
)
def
parseKatCode
(
self
,
code
):
#commands = code.split("\n")
self
.
parseCommands
(
commands
)
def
parseCommands
(
self
,
commands
):
blockComment
=
False
self
.
__currentTag
=
""
commands
=
self
.
remove_comments
(
commands
)
for
line
in
commands
.
split
(
"
\n
"
):
print
line
#for line in commands:
if
len
(
line
.
strip
())
>=
2
:
line
=
line
.
strip
()
...
...
@@ -523,3 +532,17 @@ class kat(object):
def
__get_component
(
self
,
name
):
return
getattr
(
self
,
'
__comp_
'
+
name
)
def
remove_comments
(
self
,
string
):
pattern
=
r
"
(\".*?\"|\'.*?\'|%{3}[^\r\n]*$)|(/\*.*?\*/|%[^\r\n]*$|#[^\r\n]*$|//[^\r\n]*$)
"
# first group captures quoted strings (double or single)
# second group captures comments (//single-line or /* multi-line */)
regex
=
re
.
compile
(
pattern
,
re
.
MULTILINE
|
re
.
DOTALL
)
def
_replacer
(
match
):
# if the 2nd group (capturing comments) is not None,
# it means we have captured a non-quoted (real) comment string.
if
match
.
group
(
2
)
is
not
None
:
return
""
# so we will return empty to remove the comment
else
:
# otherwise, we will return the 1st group
return
match
.
group
(
1
)
# captured quoted-string
return
regex
.
sub
(
_replacer
,
string
)
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