leo icon indicating copy to clipboard operation
leo copied to clipboard

[Bug] "parser" errors on parser test files

Open bendyarm opened this issue 3 years ago • 3 comments

🐛 Bug Report

Leo parser test files should be parseable using the "parser" example executable, but they get parse errors.

Steps to Reproduce

On the feature/staging-testnet2 branch of leo, build leo and parser with

cd leo
cargo build --release
cd parser
cargo install --path . --example parser

Then, here is an example of a file that does not parse:

$ cd ../leo/tests/parser/statement
$ parser iteration.leo
Error: ParserError(FormattedError(FormattedError { span: Span { line_start: 6, line_stop: 6, col_start: 1, col_stop: 4, path: "iteration.leo", content: Tendril<UTF8>(shared: "for x in 0..7 {}") }, backtrace: BacktracedError { message: "expected 'import', 'circuit', 'function', 'test', '@' -- got 'for'", help: None, exit_code: 5, code_identifier: 37, error_type: "PAR", backtrace:    0: leo_errors::parser::parser_errors::ParserError::unexpected
   1: leo_parser::parser::file::<impl leo_parser::parser::context::ParserContext>::unexpected_item
   2: leo_parser::parser::file::<impl leo_parser::parser::context::ParserContext>::parse_program
   3: leo_parser::parser::parse
   4: parser::main
   5: std::sys_common::backtrace::__rust_begin_short_backtrace
   6: std::rt::lang_start::{{closure}}
   7: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once
             at /rustc/09c42c45858d5f3aedfa670698275303a3d19afa/library/core/src/ops/function.rs:259:13
      std::panicking::try::do_call
             at /rustc/09c42c45858d5f3aedfa670698275303a3d19afa/library/std/src/panicking.rs:403:40
      std::panicking::try
             at /rustc/09c42c45858d5f3aedfa670698275303a3d19afa/library/std/src/panicking.rs:367:19
      std::panic::catch_unwind
             at /rustc/09c42c45858d5f3aedfa670698275303a3d19afa/library/std/src/panic.rs:129:14
      std::rt::lang_start_internal::{{closure}}
             at /rustc/09c42c45858d5f3aedfa670698275303a3d19afa/library/std/src/rt.rs:45:48
      std::panicking::try::do_call
             at /rustc/09c42c45858d5f3aedfa670698275303a3d19afa/library/std/src/panicking.rs:403:40
      std::panicking::try
             at /rustc/09c42c45858d5f3aedfa670698275303a3d19afa/library/std/src/panicking.rs:367:19
      std::panic::catch_unwind
             at /rustc/09c42c45858d5f3aedfa670698275303a3d19afa/library/std/src/panic.rs:129:14
      std::rt::lang_start_internal
             at /rustc/09c42c45858d5f3aedfa670698275303a3d19afa/library/std/src/rt.rs:45:20
   8: main
   9: __libc_start_main
             at /build/glibc-S9d2JN/glibc-2.27/csu/../csu/libc-start.c:310
  10: _start
 } }))

There are around 60 others like this.

Expected Behavior

Because the parse test files have a sequence of snippets, parser should parse the same sequence of snippets the same way they are parsed by the test framework. It should serialize the parsed snippets to JSON for output. The JSON could be an array of snippet ASTs.

Your Environment

  • leo version: 1.5.3, branch: feature/staging-testnet2; commit: 84d86af05
  • rustc 1.56.0
  • Linux Mint 19.3 built on Ubuntu 18.04 (Bionic Beaver)

bendyarm avatar Jan 04 '22 01:01 bendyarm

Pivot why don't we add a parse to the Leo CLI.

NOTE: Look at rustc has --emit metadata

gluax avatar Jan 04 '22 18:01 gluax

@gluax Yes, if we can get the AST output from a call to leo is fine with me, but having to create a directory structure with the TOML file and input directory is cumbersome. If the needed info is all on the command line, or fed to leo in a JSON structure on stdin, that would be easier to use.

bendyarm avatar Jan 11 '22 09:01 bendyarm

Edited the title and added an Expected Behavior section.

bendyarm avatar Feb 15 '22 18:02 bendyarm

Closing this since this is a feature request and not a bug. There has not been any interest in having the leo parser be used separate from the leo compiler.

collinc97 avatar Jan 05 '23 19:01 collinc97