unified: Generate corpus output

This commit is contained in:
Asger F
2026-07-30 10:06:52 +02:00
parent 91c2d7251f
commit 6e0d62c004
2 changed files with 429 additions and 0 deletions

View File

@@ -0,0 +1,222 @@
switch n {
case let x where x > 0:
print("positive")
case let y where y < 0, 0:
print("non-positive")
default:
print("other")
}
---
sourceFile
endOfFileToken: endOfFile
statements:
codeBlockItem
item:
expressionStmt
expression:
switchExpr
leftBrace: {
rightBrace: }
cases:
switchCase
label:
switchCaseLabel
colon: :
caseKeyword: case
caseItems:
switchCaseItem
pattern:
valueBindingPattern
pattern:
identifierPattern
identifier: identifier "x"
bindingSpecifier: let
whereClause:
whereClause
condition:
infixOperatorExpr
operator:
binaryOperatorExpr
operator: binaryOperator ">"
leftOperand:
declReferenceExpr
baseName: identifier "x"
rightOperand:
integerLiteralExpr
literal: integerLiteral "0"
whereKeyword: where
statements:
codeBlockItem
item:
functionCallExpr
leftParen: (
rightParen: )
arguments:
labeledExpr
expression:
stringLiteralExpr
closingQuote: "
openingQuote: "
segments:
stringSegment
content: stringSegment "positive"
additionalTrailingClosures:
calledExpression:
declReferenceExpr
baseName: identifier "print"
switchCase
label:
switchCaseLabel
colon: :
caseKeyword: case
caseItems:
switchCaseItem
trailingComma: ,
pattern:
valueBindingPattern
pattern:
identifierPattern
identifier: identifier "y"
bindingSpecifier: let
whereClause:
whereClause
condition:
infixOperatorExpr
operator:
binaryOperatorExpr
operator: binaryOperator "<"
leftOperand:
declReferenceExpr
baseName: identifier "y"
rightOperand:
integerLiteralExpr
literal: integerLiteral "0"
whereKeyword: where
switchCaseItem
pattern:
expressionPattern
expression:
integerLiteralExpr
literal: integerLiteral "0"
statements:
codeBlockItem
item:
functionCallExpr
leftParen: (
rightParen: )
arguments:
labeledExpr
expression:
stringLiteralExpr
closingQuote: "
openingQuote: "
segments:
stringSegment
content: stringSegment "non-positive"
additionalTrailingClosures:
calledExpression:
declReferenceExpr
baseName: identifier "print"
switchCase
label:
switchDefaultLabel
colon: :
defaultKeyword: default
statements:
codeBlockItem
item:
functionCallExpr
leftParen: (
rightParen: )
arguments:
labeledExpr
expression:
stringLiteralExpr
closingQuote: "
openingQuote: "
segments:
stringSegment
content: stringSegment "other"
additionalTrailingClosures:
calledExpression:
declReferenceExpr
baseName: identifier "print"
subject:
declReferenceExpr
baseName: identifier "n"
switchKeyword: switch
---
top_level
body:
block
stmt:
switch_expr
value:
name_expr
identifier: identifier "n"
case:
switch_case
pattern:
conditional_pattern
condition:
binary_expr
left:
name_expr
identifier: identifier "x"
operator: infix_operator ">"
right: int_literal "0"
pattern:
name_pattern
identifier: identifier "x"
body:
block
stmt:
call_expr
callee:
name_expr
identifier: identifier "print"
argument:
argument
value: string_literal "\"positive\""
switch_case
pattern:
or_pattern
pattern:
conditional_pattern
condition:
binary_expr
left:
name_expr
identifier: identifier "y"
operator: infix_operator "<"
right: int_literal "0"
pattern:
name_pattern
identifier: identifier "y"
expr_equality_pattern
expr: int_literal "0"
body:
block
stmt:
call_expr
callee:
name_expr
identifier: identifier "print"
argument:
argument
value: string_literal "\"non-positive\""
switch_case
body:
block
stmt:
call_expr
callee:
name_expr
identifier: identifier "print"
argument:
argument
value: string_literal "\"other\""

View File

@@ -0,0 +1,207 @@
do {
try foo()
} catch let e where isNetworkError(e), let f where isTimeout(f) {
print("retry")
} catch {
print("fallback")
}
---
sourceFile
endOfFileToken: endOfFile
statements:
codeBlockItem
item:
doStmt
body:
codeBlock
leftBrace: {
rightBrace: }
statements:
codeBlockItem
item:
tryExpr
expression:
functionCallExpr
leftParen: (
rightParen: )
arguments:
additionalTrailingClosures:
calledExpression:
declReferenceExpr
baseName: identifier "foo"
tryKeyword: try
catchClauses:
catchClause
body:
codeBlock
leftBrace: {
rightBrace: }
statements:
codeBlockItem
item:
functionCallExpr
leftParen: (
rightParen: )
arguments:
labeledExpr
expression:
stringLiteralExpr
closingQuote: "
openingQuote: "
segments:
stringSegment
content: stringSegment "retry"
additionalTrailingClosures:
calledExpression:
declReferenceExpr
baseName: identifier "print"
catchItems:
catchItem
trailingComma: ,
pattern:
valueBindingPattern
pattern:
identifierPattern
identifier: identifier "e"
bindingSpecifier: let
whereClause:
whereClause
condition:
functionCallExpr
leftParen: (
rightParen: )
arguments:
labeledExpr
expression:
declReferenceExpr
baseName: identifier "e"
additionalTrailingClosures:
calledExpression:
declReferenceExpr
baseName: identifier "isNetworkError"
whereKeyword: where
catchItem
pattern:
valueBindingPattern
pattern:
identifierPattern
identifier: identifier "f"
bindingSpecifier: let
whereClause:
whereClause
condition:
functionCallExpr
leftParen: (
rightParen: )
arguments:
labeledExpr
expression:
declReferenceExpr
baseName: identifier "f"
additionalTrailingClosures:
calledExpression:
declReferenceExpr
baseName: identifier "isTimeout"
whereKeyword: where
catchKeyword: catch
catchClause
body:
codeBlock
leftBrace: {
rightBrace: }
statements:
codeBlockItem
item:
functionCallExpr
leftParen: (
rightParen: )
arguments:
labeledExpr
expression:
stringLiteralExpr
closingQuote: "
openingQuote: "
segments:
stringSegment
content: stringSegment "fallback"
additionalTrailingClosures:
calledExpression:
declReferenceExpr
baseName: identifier "print"
catchItems:
catchKeyword: catch
doKeyword: do
---
top_level
body:
block
stmt:
try_expr
body:
block
stmt:
unary_expr
operand:
call_expr
callee:
name_expr
identifier: identifier "foo"
operator: prefix_operator "try"
catch_clause:
catch_clause
pattern:
or_pattern
pattern:
conditional_pattern
condition:
call_expr
callee:
name_expr
identifier: identifier "isNetworkError"
argument:
argument
value:
name_expr
identifier: identifier "e"
pattern:
name_pattern
identifier: identifier "e"
conditional_pattern
condition:
call_expr
callee:
name_expr
identifier: identifier "isTimeout"
argument:
argument
value:
name_expr
identifier: identifier "f"
pattern:
name_pattern
identifier: identifier "f"
body:
block
stmt:
call_expr
callee:
name_expr
identifier: identifier "print"
argument:
argument
value: string_literal "\"retry\""
catch_clause
body:
block
stmt:
call_expr
callee:
name_expr
identifier: identifier "print"
argument:
argument
value: string_literal "\"fallback\""