Commit 4967a580 authored by Andreas Freise's avatar Andreas Freise
Browse files

removing comments from input file (except for %%% which is needed for FTBlock etc).

parent f8854255
......@@ -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:
def parseKatCode(self, code):
#commands = code.split("\n")
def parseCommands(self, commands):
blockComment = False
self.__currentTag= ""
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 is not None:
return "" # so we will return empty to remove the comment
else: # otherwise, we will return the 1st group
return # captured quoted-string
return regex.sub(_replacer, string)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment