mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-03 13:11:32 +00:00
Introduce the requirement of let for assignment.
This commit is contained in:
@ -31,6 +31,14 @@ class Parser(source: PeekableSource<Token>, val attribution: NodeAttribution) {
|
||||
ListLiteral(items)
|
||||
}
|
||||
|
||||
private fun readLetAssignment(): LetAssignment = within {
|
||||
expect(TokenType.Let)
|
||||
val symbol = readSymbolRaw()
|
||||
expect(TokenType.Equals)
|
||||
val value = readExpression()
|
||||
LetAssignment(symbol, value)
|
||||
}
|
||||
|
||||
private fun readSymbolRaw(): Symbol = within {
|
||||
expect(TokenType.Symbol) { Symbol(it.text) }
|
||||
}
|
||||
@ -43,8 +51,6 @@ class Parser(source: PeekableSource<Token>, val attribution: NodeAttribution) {
|
||||
}
|
||||
expect(TokenType.RightParentheses)
|
||||
FunctionCall(symbol, arguments)
|
||||
} else if (next(TokenType.Equals)) {
|
||||
Assignment(symbol, readExpression())
|
||||
} else {
|
||||
SymbolReference(symbol)
|
||||
}
|
||||
@ -114,6 +120,10 @@ class Parser(source: PeekableSource<Token>, val attribution: NodeAttribution) {
|
||||
readListLiteral()
|
||||
}
|
||||
|
||||
TokenType.Let -> {
|
||||
readLetAssignment()
|
||||
}
|
||||
|
||||
TokenType.Symbol -> {
|
||||
readSymbolCases()
|
||||
}
|
||||
|
@ -71,7 +71,8 @@ class Printer(buffer: StringBuilder) : NodeVisitor<Unit> {
|
||||
append(")")
|
||||
}
|
||||
|
||||
override fun visitDefine(node: Assignment) {
|
||||
override fun visitLetAssignment(node: LetAssignment) {
|
||||
append("let ")
|
||||
visit(node.symbol)
|
||||
append(" = ")
|
||||
visit(node.value)
|
||||
|
@ -31,6 +31,7 @@ enum class TokenType(vararg properties: TokenTypeProperty) {
|
||||
Import(Keyword("import"), KeywordFamily),
|
||||
Export(Keyword("export"), KeywordFamily),
|
||||
Func(Keyword("func"), KeywordFamily),
|
||||
Let(Keyword("let"), KeywordFamily),
|
||||
Whitespace(CharConsumer { it == ' ' || it == '\r' || it == '\n' || it == '\t' }),
|
||||
BlockComment(CommentFamily),
|
||||
LineComment(CommentFamily),
|
||||
|
Reference in New Issue
Block a user