Files
carbon-lang/toolchain/parse/testdata/basics/fail_bracket_recovery.carbon
T
Geoff Romer 6429c1655c Make the tree structure more explicit in parse dumps (#7591)
It's hard to track 2-space indent levels across large vertical gaps, and
it can be hard to suppress the instinct to read the dump as if it were
preorder. This change introduces a new dump mode that addresses both
problems by using box-drawing characters to explicitly represent the
parent-child edges of the tree. This new mode is the default, but the
old behavior remains available with
`--parse-dump-format=yaml-postorder`.
2026-07-31 16:44:18 +00:00

96 lines
5.2 KiB
Plaintext

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// AUTOUPDATE
// TIP: To test this file alone, run:
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/parse/testdata/basics/fail_bracket_recovery.carbon
// TIP: To dump output, run:
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/parse/testdata/basics/fail_bracket_recovery.carbon
// This is a valid parse tree even though the lex errors.
fn F() {
var a: array(i32, 3) = (0, 1, 2);
// CHECK:STDERR: fail_bracket_recovery.carbon:[[@LINE+4]]:5: error: opening symbol without a corresponding closing symbol [UnmatchedOpening]
// CHECK:STDERR: (a[1) + 1;
// CHECK:STDERR: ^
// CHECK:STDERR:
(a[1) + 1;
// CHECK:STDERR: fail_bracket_recovery.carbon:[[@LINE+12]]:15: error: opening symbol without a corresponding closing symbol [UnmatchedOpening]
// CHECK:STDERR: var x: {.y: (} = {.y = ((};
// CHECK:STDERR: ^
// CHECK:STDERR:
// CHECK:STDERR: fail_bracket_recovery.carbon:[[@LINE+8]]:26: error: opening symbol without a corresponding closing symbol [UnmatchedOpening]
// CHECK:STDERR: var x: {.y: (} = {.y = ((};
// CHECK:STDERR: ^
// CHECK:STDERR:
// CHECK:STDERR: fail_bracket_recovery.carbon:[[@LINE+4]]:27: error: opening symbol without a corresponding closing symbol [UnmatchedOpening]
// CHECK:STDERR: var x: {.y: (} = {.y = ((};
// CHECK:STDERR: ^
// CHECK:STDERR:
var x: {.y: (} = {.y = ((};
}
// CHECK:STDOUT: - filename: fail_bracket_recovery.carbon
// CHECK:STDOUT: ╭─FileStart ''
// CHECK:STDOUT: │ ╭─FunctionIntroducer 'fn'
// CHECK:STDOUT: │ ├─IdentifierNameMaybeBeforeSignature 'F'
// CHECK:STDOUT: │ │ ╭─ExplicitParamListStart '('
// CHECK:STDOUT: │ ├─ExplicitParamList ')'
// CHECK:STDOUT: │ ╭─FunctionDefinitionStart '{'
// CHECK:STDOUT: │ │ ╭─VariableIntroducer 'var'
// CHECK:STDOUT: │ │ │ ╭─IdentifierNameNotBeforeSignature 'a'
// CHECK:STDOUT: │ │ │ ├─BindingPatternTypeStart ':'
// CHECK:STDOUT: │ │ │ │ ╭─ArrayExprKeyword 'array'
// CHECK:STDOUT: │ │ │ │ ├─ArrayExprOpenParen '('
// CHECK:STDOUT: │ │ │ │ ├─IntTypeLiteral 'i32'
// CHECK:STDOUT: │ │ │ │ ├─ArrayExprComma ','
// CHECK:STDOUT: │ │ │ │ ├─IntLiteral '3'
// CHECK:STDOUT: │ │ │ ├─ArrayExpr ')'
// CHECK:STDOUT: │ │ │ ╭─VarBindingPattern ':'
// CHECK:STDOUT: │ │ ├─VariablePattern 'var'
// CHECK:STDOUT: │ │ ├─VariableInitializer '='
// CHECK:STDOUT: │ │ │ ╭─TupleLiteralStart '('
// CHECK:STDOUT: │ │ │ ├─IntLiteral '0'
// CHECK:STDOUT: │ │ │ ├─TupleLiteralComma ','
// CHECK:STDOUT: │ │ │ ├─IntLiteral '1'
// CHECK:STDOUT: │ │ │ ├─TupleLiteralComma ','
// CHECK:STDOUT: │ │ │ ├─IntLiteral '2'
// CHECK:STDOUT: │ │ ├─TupleLiteral ')'
// CHECK:STDOUT: │ ├─VariableDecl ';'
// CHECK:STDOUT: │ │ ╭─ParenExprStart '('
// CHECK:STDOUT: │ │ │ ╭─IdentifierNameExpr 'a'
// CHECK:STDOUT: │ │ │ ╭─IndexExprStart '['
// CHECK:STDOUT: │ │ │ ├─IntLiteral '1'
// CHECK:STDOUT: │ │ ├─IndexExpr ']'
// CHECK:STDOUT: │ │ ╭─ParenExpr ')'
// CHECK:STDOUT: │ │ ├─IntLiteral '1'
// CHECK:STDOUT: │ │ ╭─InfixOperatorPlus '+'
// CHECK:STDOUT: │ ├─ExprStatement ';'
// CHECK:STDOUT: │ │ ╭─VariableIntroducer 'var'
// CHECK:STDOUT: │ │ │ ╭─IdentifierNameNotBeforeSignature 'x'
// CHECK:STDOUT: │ │ │ ├─BindingPatternTypeStart ':'
// CHECK:STDOUT: │ │ │ │ ╭─StructTypeLiteralStart '{'
// CHECK:STDOUT: │ │ │ │ │ ╭─IdentifierNameNotBeforeSignature 'y'
// CHECK:STDOUT: │ │ │ │ │ ╭─StructFieldDesignator '.'
// CHECK:STDOUT: │ │ │ │ │ │ ╭─TupleLiteralStart '('
// CHECK:STDOUT: │ │ │ │ │ ├─TupleLiteral ')'
// CHECK:STDOUT: │ │ │ │ ├─StructTypeLiteralField ':'
// CHECK:STDOUT: │ │ │ ├─StructTypeLiteral '}'
// CHECK:STDOUT: │ │ │ ╭─VarBindingPattern ':'
// CHECK:STDOUT: │ │ ├─VariablePattern 'var'
// CHECK:STDOUT: │ │ ├─VariableInitializer '='
// CHECK:STDOUT: │ │ │ ╭─StructLiteralStart '{'
// CHECK:STDOUT: │ │ │ │ ╭─IdentifierNameNotBeforeSignature 'y'
// CHECK:STDOUT: │ │ │ │ ╭─StructFieldDesignator '.'
// CHECK:STDOUT: │ │ │ │ │ ╭─ParenExprStart '('
// CHECK:STDOUT: │ │ │ │ │ │ ╭─TupleLiteralStart '('
// CHECK:STDOUT: │ │ │ │ │ ├─TupleLiteral ')'
// CHECK:STDOUT: │ │ │ │ ├─ParenExpr ')'
// CHECK:STDOUT: │ │ │ ├─StructLiteralField '='
// CHECK:STDOUT: │ │ ├─StructLiteral '}'
// CHECK:STDOUT: │ ├─VariableDecl ';'
// CHECK:STDOUT: ├─FunctionDefinition '}'
// CHECK:STDOUT: ├─FileEnd ''
// CHECK:STDOUT: (root)