diff --git a/examples/syntax.pork b/examples/syntax.pork index 7441cb5..54368fe 100644 --- a/examples/syntax.pork +++ b/examples/syntax.pork @@ -11,6 +11,8 @@ main = { in multiply = { a, b in a * b } + + // calculates the result calculateSimpleResult = calculateSimple() calculateComplexResult = calculateComplex() multiplyResult = multiply(50, 50) diff --git a/src/main/kotlin/gay/pizza/pork/parse/PorkParser.kt b/src/main/kotlin/gay/pizza/pork/parse/PorkParser.kt index f9c2ac0..cf2c2ab 100644 --- a/src/main/kotlin/gay/pizza/pork/parse/PorkParser.kt +++ b/src/main/kotlin/gay/pizza/pork/parse/PorkParser.kt @@ -197,6 +197,7 @@ class PorkParser(source: PeekableSource) { private fun ignoredByParser(type: TokenType): Boolean = when (type) { TokenType.BlockComment -> true + TokenType.LineComment -> true TokenType.Whitespace -> true else -> false } diff --git a/src/main/kotlin/gay/pizza/pork/parse/PorkTokenizer.kt b/src/main/kotlin/gay/pizza/pork/parse/PorkTokenizer.kt index d300f89..abc7dca 100644 --- a/src/main/kotlin/gay/pizza/pork/parse/PorkTokenizer.kt +++ b/src/main/kotlin/gay/pizza/pork/parse/PorkTokenizer.kt @@ -75,6 +75,20 @@ class PorkTokenizer(val source: CharSource) { return Token(TokenType.BlockComment, tokenStart, comment) } + private fun readLineComment(firstChar: Char): Token { + val comment = buildString { + append(firstChar) + while (true) { + val char = source.peek() + if (char == CharSource.NullChar || char == '\n') { + break + } + append(source.next()) + } + } + return Token(TokenType.LineComment, tokenStart, comment) + } + fun next(): Token { while (source.peek() != CharSource.NullChar) { tokenStart = source.currentIndex @@ -84,6 +98,10 @@ class PorkTokenizer(val source: CharSource) { return readBlockComment(char) } + if (char == '/' && source.peek() == '/') { + return readLineComment(char) + } + for (item in TokenType.SingleChars) { val itemChar = item.singleChar!!.char if (itemChar != char) { diff --git a/src/main/kotlin/gay/pizza/pork/parse/TokenType.kt b/src/main/kotlin/gay/pizza/pork/parse/TokenType.kt index 2b102f5..6e0ccd6 100644 --- a/src/main/kotlin/gay/pizza/pork/parse/TokenType.kt +++ b/src/main/kotlin/gay/pizza/pork/parse/TokenType.kt @@ -27,6 +27,7 @@ enum class TokenType(vararg properties: TokenTypeProperty) { Else(Keyword("else")), Whitespace, BlockComment, + LineComment, EndOfFile; val promotions: List = properties.filterIsInstance()