mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-03 21:21:33 +00:00
idea: proper scoping support, completion now works
This commit is contained in:
@ -4,6 +4,11 @@ import gay.pizza.pork.ast.*
|
||||
|
||||
class Parser(source: TokenSource, attribution: NodeAttribution) :
|
||||
ParserBase(source, attribution) {
|
||||
override fun parseArgumentSpec(): ArgumentSpec = guarded(NodeType.ArgumentSpec) {
|
||||
val symbol = parseSymbol()
|
||||
ArgumentSpec(symbol, next(TokenType.DotDotDot))
|
||||
}
|
||||
|
||||
override fun parseBlock(): Block = guarded(NodeType.Block) {
|
||||
expect(TokenType.LeftCurly)
|
||||
val items = collect(TokenType.RightCurly) {
|
||||
@ -177,11 +182,15 @@ class Parser(source: TokenSource, attribution: NodeAttribution) :
|
||||
|
||||
override fun parseForIn(): ForIn = guarded(NodeType.ForIn) {
|
||||
expect(TokenType.For)
|
||||
val symbol = parseSymbol()
|
||||
val forInItem = parseForInItem()
|
||||
expect(TokenType.In)
|
||||
val value = parseExpression()
|
||||
val block = parseBlock()
|
||||
ForIn(symbol, value, block)
|
||||
ForIn(forInItem, value, block)
|
||||
}
|
||||
|
||||
override fun parseForInItem(): ForInItem = guarded(NodeType.ForInItem) {
|
||||
ForInItem(parseSymbol())
|
||||
}
|
||||
|
||||
override fun parseFunctionCall(): FunctionCall = guarded(NodeType.FunctionCall) {
|
||||
@ -200,12 +209,7 @@ class Parser(source: TokenSource, attribution: NodeAttribution) :
|
||||
val name = parseSymbol()
|
||||
expect(TokenType.LeftParentheses)
|
||||
val arguments = collect(TokenType.RightParentheses, TokenType.Comma) {
|
||||
val symbol = parseSymbol()
|
||||
var multiple = false
|
||||
if (next(TokenType.DotDotDot)) {
|
||||
multiple = true
|
||||
}
|
||||
ArgumentSpec(symbol, multiple)
|
||||
parseArgumentSpec()
|
||||
}
|
||||
expect(TokenType.RightParentheses)
|
||||
|
||||
|
@ -30,13 +30,17 @@ class Printer(buffer: StringBuilder) : NodeVisitor<Unit> {
|
||||
|
||||
override fun visitForIn(node: ForIn) {
|
||||
append("for ")
|
||||
visit(node.symbol)
|
||||
visit(node.item)
|
||||
append(" in ")
|
||||
visit(node.expression)
|
||||
append(" ")
|
||||
visit(node.block)
|
||||
}
|
||||
|
||||
override fun visitForInItem(node: ForInItem) {
|
||||
node.symbol.visit(this)
|
||||
}
|
||||
|
||||
override fun visitStringLiteral(node: StringLiteral) {
|
||||
append("\"")
|
||||
append(StringEscape.escape(node.text))
|
||||
@ -189,10 +193,7 @@ class Printer(buffer: StringBuilder) : NodeVisitor<Unit> {
|
||||
visit(node.symbol)
|
||||
append("(")
|
||||
for ((index, argument) in node.arguments.withIndex()) {
|
||||
visit(argument.symbol)
|
||||
if (argument.multiple) {
|
||||
append("...")
|
||||
}
|
||||
argument.visit(this)
|
||||
if (index + 1 != node.arguments.size) {
|
||||
append(", ")
|
||||
}
|
||||
@ -207,6 +208,13 @@ class Printer(buffer: StringBuilder) : NodeVisitor<Unit> {
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitArgumentSpec(node: ArgumentSpec) {
|
||||
node.symbol.visit(this)
|
||||
if (node.multiple) {
|
||||
append("...")
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitBlock(node: Block) {
|
||||
append("{")
|
||||
if (node.expressions.isNotEmpty()) {
|
||||
|
@ -23,8 +23,8 @@ enum class TokenType(vararg properties: TokenTypeProperty) {
|
||||
Minus(SingleChar('-'), OperatorFamily, Promotion('-', MinusMinus)),
|
||||
Multiply(SingleChar('*'), OperatorFamily),
|
||||
Divide(SingleChar('/'), OperatorFamily),
|
||||
And(ManyChars("and"), OperatorFamily),
|
||||
Or(ManyChars("or"), OperatorFamily),
|
||||
And(ManyChars("and"), KeywordFamily),
|
||||
Or(ManyChars("or"), KeywordFamily),
|
||||
Tilde(SingleChar('~'), OperatorFamily),
|
||||
Ampersand(SingleChar('&'), OperatorFamily),
|
||||
Pipe(SingleChar('|'), OperatorFamily),
|
||||
|
Reference in New Issue
Block a user