mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 09:34:42 +01:00
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`.
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
// 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
|
||||
//
|
||||
// EXTRA-ARGS: --parse-dump-format=pretty
|
||||
// AUTOUPDATE
|
||||
// TIP: To test this file alone, run:
|
||||
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/parse/testdata/dump_format/pretty.carbon
|
||||
// TIP: To dump output, run:
|
||||
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/parse/testdata/dump_format/pretty.carbon
|
||||
|
||||
// --- fail_pretty.carbon
|
||||
|
||||
// CHECK:STDERR: fail_pretty.carbon:[[@LINE+4]]:9: error: expected `.field: field_type` or `.field = value` [ExpectedStructLiteralField]
|
||||
// CHECK:STDERR: var x: {,} = {};
|
||||
// CHECK:STDERR: ^
|
||||
// CHECK:STDERR:
|
||||
var x: {,} = {};
|
||||
|
||||
// CHECK:STDOUT: - filename: fail_pretty.carbon
|
||||
// CHECK:STDOUT: ╭─FileStart ''
|
||||
// CHECK:STDOUT: │ ╭─VariableIntroducer 'var'
|
||||
// CHECK:STDOUT: │ │ ╭─IdentifierNameNotBeforeSignature 'x'
|
||||
// CHECK:STDOUT: │ │ ├─BindingPatternTypeStart ':'
|
||||
// CHECK:STDOUT: │ │ │ ╭─StructLiteralStart '{'
|
||||
// CHECK:STDOUT: │ │ │ ├─InvalidParse ',' has_error
|
||||
// CHECK:STDOUT: │ │ │ ├─InvalidParse ',' has_error
|
||||
// CHECK:STDOUT: │ │ ├─StructLiteral '}' has_error
|
||||
// CHECK:STDOUT: │ │ ╭─VarBindingPattern ':'
|
||||
// CHECK:STDOUT: │ ├─VariablePattern 'var'
|
||||
// CHECK:STDOUT: │ ├─VariableInitializer '='
|
||||
// CHECK:STDOUT: │ │ ╭─StructLiteralStart '{'
|
||||
// CHECK:STDOUT: │ ├─StructLiteral '}'
|
||||
// CHECK:STDOUT: ├─VariableDecl ';'
|
||||
// CHECK:STDOUT: ├─FileEnd ''
|
||||
// CHECK:STDOUT: (root)
|
||||
@@ -0,0 +1,37 @@
|
||||
// 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
|
||||
//
|
||||
// EXTRA-ARGS: --parse-dump-format=yaml-postorder
|
||||
// AUTOUPDATE
|
||||
// TIP: To test this file alone, run:
|
||||
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/parse/testdata/dump_format/yaml_postorder.carbon
|
||||
// TIP: To dump output, run:
|
||||
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/parse/testdata/dump_format/yaml_postorder.carbon
|
||||
|
||||
// --- fail_yaml_postorder.carbon
|
||||
|
||||
// CHECK:STDERR: fail_yaml_postorder.carbon:[[@LINE+4]]:9: error: expected `.field: field_type` or `.field = value` [ExpectedStructLiteralField]
|
||||
// CHECK:STDERR: var x: {,} = {};
|
||||
// CHECK:STDERR: ^
|
||||
// CHECK:STDERR:
|
||||
var x: {,} = {};
|
||||
|
||||
// CHECK:STDOUT: - filename: fail_yaml_postorder.carbon
|
||||
// CHECK:STDOUT: parse_tree: [
|
||||
// CHECK:STDOUT: {kind: 'FileStart', text: ''},
|
||||
// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierNameNotBeforeSignature', text: 'x'},
|
||||
// CHECK:STDOUT: {kind: 'BindingPatternTypeStart', text: ':'},
|
||||
// CHECK:STDOUT: {kind: 'StructLiteralStart', text: '{'},
|
||||
// CHECK:STDOUT: {kind: 'InvalidParse', text: ',', has_error: yes},
|
||||
// CHECK:STDOUT: {kind: 'InvalidParse', text: ',', has_error: yes},
|
||||
// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', has_error: yes, subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'VarBindingPattern', text: ':', subtree_size: 7},
|
||||
// CHECK:STDOUT: {kind: 'VariablePattern', text: 'var', subtree_size: 8},
|
||||
// CHECK:STDOUT: {kind: 'VariableInitializer', text: '='},
|
||||
// CHECK:STDOUT: {kind: 'StructLiteralStart', text: '{'},
|
||||
// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'VariableDecl', text: ';', subtree_size: 13},
|
||||
// CHECK:STDOUT: {kind: 'FileEnd', text: ''},
|
||||
// CHECK:STDOUT: ]
|
||||
@@ -0,0 +1,37 @@
|
||||
// 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
|
||||
//
|
||||
// EXTRA-ARGS: --parse-dump-format=yaml-preorder
|
||||
// AUTOUPDATE
|
||||
// TIP: To test this file alone, run:
|
||||
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/parse/testdata/dump_format/yaml_preorder.carbon
|
||||
// TIP: To dump output, run:
|
||||
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/parse/testdata/dump_format/yaml_preorder.carbon
|
||||
|
||||
// --- fail_yaml_preorder.carbon
|
||||
|
||||
// CHECK:STDERR: fail_yaml_preorder.carbon:[[@LINE+4]]:9: error: expected `.field: field_type` or `.field = value` [ExpectedStructLiteralField]
|
||||
// CHECK:STDERR: var x: {,} = {};
|
||||
// CHECK:STDERR: ^
|
||||
// CHECK:STDERR:
|
||||
var x: {,} = {};
|
||||
|
||||
// CHECK:STDOUT: - filename: fail_yaml_preorder.carbon
|
||||
// CHECK:STDOUT: parse_tree: [
|
||||
// CHECK:STDOUT: {node_index: 0, kind: 'FileStart', text: ''},
|
||||
// CHECK:STDOUT: {node_index: 13, kind: 'VariableDecl', text: ';', subtree_size: 13, children: [
|
||||
// CHECK:STDOUT: {node_index: 1, kind: 'VariableIntroducer', text: 'var'},
|
||||
// CHECK:STDOUT: {node_index: 9, kind: 'VariablePattern', text: 'var', subtree_size: 8, children: [
|
||||
// CHECK:STDOUT: {node_index: 8, kind: 'VarBindingPattern', text: ':', subtree_size: 7, children: [
|
||||
// CHECK:STDOUT: {node_index: 2, kind: 'IdentifierNameNotBeforeSignature', text: 'x'},
|
||||
// CHECK:STDOUT: {node_index: 3, kind: 'BindingPatternTypeStart', text: ':'},
|
||||
// CHECK:STDOUT: {node_index: 7, kind: 'StructLiteral', text: '}', has_error: yes, subtree_size: 4, children: [
|
||||
// CHECK:STDOUT: {node_index: 4, kind: 'StructLiteralStart', text: '{'},
|
||||
// CHECK:STDOUT: {node_index: 5, kind: 'InvalidParse', text: ',', has_error: yes},
|
||||
// CHECK:STDOUT: {node_index: 6, kind: 'InvalidParse', text: ',', has_error: yes}]}]}]},
|
||||
// CHECK:STDOUT: {node_index: 10, kind: 'VariableInitializer', text: '='},
|
||||
// CHECK:STDOUT: {node_index: 12, kind: 'StructLiteral', text: '}', subtree_size: 2, children: [
|
||||
// CHECK:STDOUT: {node_index: 11, kind: 'StructLiteralStart', text: '{'}]}]},
|
||||
// CHECK:STDOUT: {node_index: 14, kind: 'FileEnd', text: ''},
|
||||
// CHECK:STDOUT: ]
|
||||
Reference in New Issue
Block a user