basic_syntax.carbon 2.7 KB

1234567891011121314151617181920212223242526272829303132
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // Dump all tokens so that we include the file start and end.
  6. // EXTRA-ARGS: --no-omit-file-boundary-tokens
  7. //
  8. // AUTOUPDATE
  9. // TIP: To test this file alone, run:
  10. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/lex/testdata/basic_syntax.carbon
  11. // TIP: To dump output, run:
  12. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lex/testdata/basic_syntax.carbon
  13. // CHECK:STDOUT: - filename: basic_syntax.carbon
  14. // CHECK:STDOUT: tokens:
  15. // CHECK:STDOUT: - { index: 0, kind: 'FileStart', line: {{ *\d+}}, column: 1, indent: 1, spelling: '' }
  16. fn run(String program) {
  17. // CHECK:STDOUT: - { index: 1, kind: 'Fn', line: {{ *}}[[@LINE-1]], column: 1, indent: 1, spelling: 'fn', has_leading_space: true }
  18. // CHECK:STDOUT: - { index: 2, kind: 'Identifier', line: {{ *}}[[@LINE-2]], column: 4, indent: 1, spelling: 'run', identifier: 0, has_leading_space: true }
  19. // CHECK:STDOUT: - { index: 3, kind: 'OpenParen', line: {{ *}}[[@LINE-3]], column: 7, indent: 1, spelling: '(', closing_token: 6 }
  20. // CHECK:STDOUT: - { index: 4, kind: 'StringTypeLiteral', line: {{ *}}[[@LINE-4]], column: 8, indent: 1, spelling: 'String' }
  21. // CHECK:STDOUT: - { index: 5, kind: 'Identifier', line: {{ *}}[[@LINE-5]], column: 15, indent: 1, spelling: 'program', identifier: 1, has_leading_space: true }
  22. // CHECK:STDOUT: - { index: 6, kind: 'CloseParen', line: {{ *}}[[@LINE-6]], column: 22, indent: 1, spelling: ')', opening_token: 3 }
  23. // CHECK:STDOUT: - { index: 7, kind: 'OpenCurlyBrace', line: {{ *}}[[@LINE-7]], column: 24, indent: 1, spelling: '{', closing_token: 11, has_leading_space: true }
  24. return True;
  25. // CHECK:STDOUT: - { index: 8, kind: 'Return', line: {{ *}}[[@LINE-1]], column: 3, indent: 3, spelling: 'return', has_leading_space: true }
  26. // CHECK:STDOUT: - { index: 9, kind: 'Identifier', line: {{ *}}[[@LINE-2]], column: 10, indent: 3, spelling: 'True', identifier: 2, has_leading_space: true }
  27. // CHECK:STDOUT: - { index: 10, kind: 'Semi', line: {{ *}}[[@LINE-3]], column: 14, indent: 3, spelling: ';' }
  28. }
  29. // CHECK:STDOUT: - { index: 11, kind: 'CloseCurlyBrace', line: {{ *}}[[@LINE-1]], column: 1, indent: 1, spelling: '}', opening_token: 7, has_leading_space: true }
  30. // CHECK:STDOUT: - { index: 12, kind: 'FileEnd', line: {{ *}}[[@LINE+0]], column: {{ *\d+}}, indent: 1, spelling: '', has_leading_space: true }