Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
finesse
pykat
Commits
4967a580
Commit
4967a580
authored
Dec 01, 2013
by
Andreas Freise
Browse files
removing comments from input file (except for %%% which is needed for FTBlock etc).
parent
f8854255
Changes
1
Hide whitespace changes
Inline
Side-by-side
pykat/finesse.py
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
)
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