mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-03 13:11:32 +00:00
language: today, we killed lambdas
This commit is contained in:
@ -56,26 +56,6 @@ class Parser(source: PeekableSource<Token>, val attribution: NodeAttribution) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun readLambda(): Lambda = within {
|
||||
expect(TokenType.LeftCurly)
|
||||
val arguments = mutableListOf<Symbol>()
|
||||
while (!peek(TokenType.In)) {
|
||||
val symbol = readSymbolRaw()
|
||||
arguments.add(symbol)
|
||||
if (next(TokenType.Comma)) {
|
||||
continue
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
expect(TokenType.In)
|
||||
val items = collect(TokenType.RightCurly) {
|
||||
readExpression()
|
||||
}
|
||||
expect(TokenType.RightCurly)
|
||||
Lambda(arguments, items)
|
||||
}
|
||||
|
||||
private fun readParentheses(): Parentheses = within {
|
||||
expect(TokenType.LeftParentheses)
|
||||
val expression = readExpression()
|
||||
@ -128,10 +108,6 @@ class Parser(source: PeekableSource<Token>, val attribution: NodeAttribution) {
|
||||
readSymbolCases()
|
||||
}
|
||||
|
||||
TokenType.LeftCurly -> {
|
||||
readLambda()
|
||||
}
|
||||
|
||||
TokenType.LeftParentheses -> {
|
||||
readParentheses()
|
||||
}
|
||||
|
@ -82,34 +82,6 @@ class Printer(buffer: StringBuilder) : NodeVisitor<Unit> {
|
||||
visit(node.symbol)
|
||||
}
|
||||
|
||||
override fun visitLambda(node: Lambda) {
|
||||
append("{")
|
||||
if (node.arguments.isNotEmpty()) {
|
||||
append(" ")
|
||||
for ((index, argument) in node.arguments.withIndex()) {
|
||||
visit(argument)
|
||||
if (index + 1 != node.arguments.size) {
|
||||
append(",")
|
||||
}
|
||||
append(" ")
|
||||
}
|
||||
} else {
|
||||
append(" ")
|
||||
}
|
||||
append("in")
|
||||
out.increaseIndent()
|
||||
for (expression in node.expressions) {
|
||||
appendLine()
|
||||
visit(expression)
|
||||
}
|
||||
|
||||
if (node.expressions.isNotEmpty()) {
|
||||
appendLine()
|
||||
}
|
||||
out.decreaseIndent()
|
||||
append("}")
|
||||
}
|
||||
|
||||
override fun visitParentheses(node: Parentheses) {
|
||||
append("(")
|
||||
visit(node.expression)
|
||||
|
@ -24,7 +24,6 @@ enum class TokenType(vararg properties: TokenTypeProperty) {
|
||||
Comma(SingleChar(',')),
|
||||
False(Keyword("false"), KeywordFamily),
|
||||
True(Keyword("true"), KeywordFamily),
|
||||
In(Keyword("in"), KeywordFamily),
|
||||
If(Keyword("if"), KeywordFamily),
|
||||
Then(Keyword("then"), KeywordFamily),
|
||||
Else(Keyword("else"), KeywordFamily),
|
||||
|
Reference in New Issue
Block a user