BYE BYE SEMICOLONS!
This commit is contained in:
parent
60028ed664
commit
2072f34d4c
|
@ -565,6 +565,8 @@ proc next(self: Lexer) =
|
||||||
elif self.match("\n"):
|
elif self.match("\n"):
|
||||||
# New line
|
# New line
|
||||||
self.incLine()
|
self.incLine()
|
||||||
|
if not self.getToken("\n").isNil():
|
||||||
|
self.createToken(Semicolon)
|
||||||
elif self.match("`"):
|
elif self.match("`"):
|
||||||
# Stropped token
|
# Stropped token
|
||||||
self.parseBackticks()
|
self.parseBackticks()
|
||||||
|
@ -599,7 +601,7 @@ proc next(self: Lexer) =
|
||||||
elif self.match("#"):
|
elif self.match("#"):
|
||||||
if not self.match("pragma["):
|
if not self.match("pragma["):
|
||||||
# Inline comments
|
# Inline comments
|
||||||
while not (self.check("\n") or self.done()):
|
while not (self.match("\n") or self.done()):
|
||||||
discard self.step()
|
discard self.step()
|
||||||
self.createToken(Comment)
|
self.createToken(Comment)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import strformat
|
import strformat
|
||||||
|
import strutils
|
||||||
|
|
||||||
|
|
||||||
type
|
type
|
||||||
|
@ -78,7 +79,7 @@ type
|
||||||
proc `$`*(self: Token): string =
|
proc `$`*(self: Token): string =
|
||||||
## Strinfifies
|
## Strinfifies
|
||||||
if self != nil:
|
if self != nil:
|
||||||
result = &"Token(kind={self.kind}, lexeme='{$(self.lexeme)}', line={self.line}, pos=({self.pos.start}, {self.pos.stop}), spaces={self.spaces})"
|
result = &"Token(kind={self.kind}, lexeme={($self.lexeme).escape()}, line={self.line}, pos=({self.pos.start}, {self.pos.stop}), spaces={self.spaces})"
|
||||||
else:
|
else:
|
||||||
result = "nil"
|
result = "nil"
|
||||||
|
|
||||||
|
|
|
@ -269,13 +269,13 @@ proc runFile(f: string, interactive: bool = false, fromString: bool = false) =
|
||||||
let relPos = tokenizer.getRelPos(exc.line)
|
let relPos = tokenizer.getRelPos(exc.line)
|
||||||
let line = tokenizer.getSource().splitLines()[exc.line - 1].strip()
|
let line = tokenizer.getSource().splitLines()[exc.line - 1].strip()
|
||||||
stderr.styledWriteLine(fgRed, "A fatal error occurred while parsing ", fgYellow, &"'{exc.file}'", fgRed, ", module ",
|
stderr.styledWriteLine(fgRed, "A fatal error occurred while parsing ", fgYellow, &"'{exc.file}'", fgRed, ", module ",
|
||||||
fgYellow, &"'{exc.file}'", fgRed, ", line ", fgYellow, $exc.line, fgRed, " at ", fgYellow, &"'{exc.lexeme}'",
|
fgYellow, &"'{exc.file}'", fgRed, ", line ", fgYellow, $exc.line, fgRed, " at ", fgYellow, &"'{exc.lexeme.escape()}'",
|
||||||
fgRed, ": ", fgGreen , getCurrentExceptionMsg())
|
fgRed, ": ", fgGreen , getCurrentExceptionMsg())
|
||||||
styledEcho fgBlue, "Source line: " , fgDefault, line
|
styledEcho fgBlue, "Source line: " , fgDefault, line
|
||||||
styledEcho fgCyan, " ".repeat(len("Source line: ")) & "^".repeat(relPos.stop - relPos.start)
|
styledEcho fgCyan, " ".repeat(len("Source line: ")) & "^".repeat(relPos.stop - relPos.start)
|
||||||
except ParseError:
|
except ParseError:
|
||||||
let exc = ParseError(getCurrentException())
|
let exc = ParseError(getCurrentException())
|
||||||
let lexeme = exc.token.lexeme
|
let lexeme = exc.token.lexeme.escape()
|
||||||
let lineNo = exc.token.line
|
let lineNo = exc.token.line
|
||||||
let relPos = tokenizer.getRelPos(lineNo)
|
let relPos = tokenizer.getRelPos(lineNo)
|
||||||
let fn = parser.getCurrentFunction()
|
let fn = parser.getCurrentFunction()
|
||||||
|
@ -290,7 +290,7 @@ proc runFile(f: string, interactive: bool = false, fromString: bool = false) =
|
||||||
styledEcho fgCyan, " ".repeat(len("Source line: ")) & "^".repeat(relPos.stop - relPos.start)
|
styledEcho fgCyan, " ".repeat(len("Source line: ")) & "^".repeat(relPos.stop - relPos.start)
|
||||||
except CompileError:
|
except CompileError:
|
||||||
let exc = CompileError(getCurrentException())
|
let exc = CompileError(getCurrentException())
|
||||||
let lexeme = exc.node.token.lexeme
|
let lexeme = exc.node.token.lexeme.escape()
|
||||||
let lineNo = exc.node.token.line
|
let lineNo = exc.node.token.line
|
||||||
let relPos = tokenizer.getRelPos(lineNo)
|
let relPos = tokenizer.getRelPos(lineNo)
|
||||||
let line = tokenizer.getSource().splitLines()[lineNo - 1].strip()
|
let line = tokenizer.getSource().splitLines()[lineNo - 1].strip()
|
||||||
|
@ -380,7 +380,8 @@ proc fillSymbolTable(tokenizer: Lexer) =
|
||||||
tokenizer.symbols.addSymbol("]", RightBracket)
|
tokenizer.symbols.addSymbol("]", RightBracket)
|
||||||
tokenizer.symbols.addSymbol(".", Dot)
|
tokenizer.symbols.addSymbol(".", Dot)
|
||||||
tokenizer.symbols.addSymbol(",", Comma)
|
tokenizer.symbols.addSymbol(",", Comma)
|
||||||
tokenizer.symbols.addSymbol(";", Semicolon)
|
# tokenizer.symbols.addSymbol(";", Semicolon)
|
||||||
|
tokenizer.symbols.addSymbol("\n", Semicolon)
|
||||||
# Keywords
|
# Keywords
|
||||||
tokenizer.symbols.addKeyword("type", TokenType.Type)
|
tokenizer.symbols.addKeyword("type", TokenType.Type)
|
||||||
tokenizer.symbols.addKeyword("enum", Enum)
|
tokenizer.symbols.addKeyword("enum", Enum)
|
||||||
|
|
Loading…
Reference in New Issue