mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-03 21:21:33 +00:00
language: implement for in
This commit is contained in:
@ -106,6 +106,15 @@ class Parser(source: PeekableSource<Token>, val attribution: NodeAttribution) {
|
||||
While(condition, block)
|
||||
}
|
||||
|
||||
private fun readForIn(): ForIn = within {
|
||||
expect(TokenType.For)
|
||||
val symbol = readSymbolRaw()
|
||||
expect(TokenType.In)
|
||||
val value = readExpression()
|
||||
val block = readBlock()
|
||||
ForIn(symbol, value, block)
|
||||
}
|
||||
|
||||
private fun readNative(): Native = within {
|
||||
expect(TokenType.Native)
|
||||
val form = readSymbolRaw()
|
||||
@ -160,6 +169,10 @@ class Parser(source: PeekableSource<Token>, val attribution: NodeAttribution) {
|
||||
readWhile()
|
||||
}
|
||||
|
||||
TokenType.For -> {
|
||||
readForIn()
|
||||
}
|
||||
|
||||
TokenType.Break -> {
|
||||
expect(TokenType.Break)
|
||||
Break()
|
||||
|
@ -28,6 +28,15 @@ class Printer(buffer: StringBuilder) : NodeVisitor<Unit> {
|
||||
append(node.value.toString())
|
||||
}
|
||||
|
||||
override fun visitForIn(node: ForIn) {
|
||||
append("for ")
|
||||
visit(node.symbol)
|
||||
append(" in ")
|
||||
visit(node.expression)
|
||||
append(" ")
|
||||
visit(node.block)
|
||||
}
|
||||
|
||||
override fun visitStringLiteral(node: StringLiteral) {
|
||||
append("\"")
|
||||
append(StringEscape.escape(node.text))
|
||||
|
@ -47,6 +47,8 @@ enum class TokenType(vararg properties: TokenTypeProperty) {
|
||||
If(ManyChars("if"), KeywordFamily),
|
||||
Else(ManyChars("else"), KeywordFamily),
|
||||
While(ManyChars("while"), KeywordFamily),
|
||||
For(ManyChars("for"), KeywordFamily),
|
||||
In(ManyChars("in"), KeywordFamily),
|
||||
Continue(ManyChars("continue"), KeywordFamily),
|
||||
Break(ManyChars("break"), KeywordFamily),
|
||||
Import(ManyChars("import"), KeywordFamily),
|
||||
|
Reference in New Issue
Block a user