Skip to content
This repository has been archived by the owner on Dec 11, 2022. It is now read-only.

Commit

Permalink
string indentation preservation
Browse files Browse the repository at this point in the history
  • Loading branch information
SK1Y101 committed Apr 2, 2021
1 parent 422242c commit af85ead
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions ExampleCode/strings_across_lines.skiy
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
print("This string
print("This string
has been written
across several
across several
lines.")
6 changes: 4 additions & 2 deletions PySkiylia/Lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def findIdentifier(self):

#define a way of fetching a string from sourcecode
def findString(self):
startIndent = self.char
si = self.char
#keep going until we hit the end of the code, or the string terminator
while not self.match('"', peek=True):
#we support multi-line strings, so if we find a newline, increment the line counter
Expand All @@ -224,7 +224,9 @@ def findString(self):
#fetch the contents of the string, removing the leading and trailing identifiers
stringVal = self.source[self.start+1:self.current-1]
#remove any whitespace that occured due to newlines
stringVal = " \n".join([x.strip() for x in stringVal.split("\n")])
if "\n" in stringVal:
sv = stringVal.split("\n")
stringVal = " \n".join([sv[0]]+[x[si:] for x in sv[1:]])
#create the token and return it
return self.addToken("String", stringVal)

Expand Down

0 comments on commit af85ead

Please sign in to comment.