Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to parse fhirpath grammar #9

Open
AlexKovalevych opened this issue Aug 5, 2020 · 0 comments
Open

Unable to parse fhirpath grammar #9

AlexKovalevych opened this issue Aug 5, 2020 · 0 comments

Comments

@AlexKovalevych
Copy link

Grammar taken from here: https://github.com/HL7/fhirpath.js/blob/master/src/parser/FHIRPath.g4

Parsed like:

#![feature(try_blocks)]

#[macro_use]
extern crate lazy_static;

mod parser;

use antlr_rust::common_token_stream::CommonTokenStream;
use antlr_rust::input_stream::InputStream;
use antlr_rust::parser_rule_context::ParserRuleContext;
use antlr_rust::tree::{ErrorNode, ParseTreeListener, TerminalNode};

use parser::fhirpathlexer::FHIRPathLexer;
use parser::fhirpathlistener::FHIRPathListener;
use parser::fhirpathparser::*;

struct Listener;

impl ParseTreeListener for Listener {
    fn visit_terminal(&mut self, node: &TerminalNode) {}
    fn visit_error_node(&mut self, node: &ErrorNode) {}
    fn enter_every_rule(&mut self, ctx: &dyn ParserRuleContext) {}
    fn exit_every_rule(&mut self, ctx: &dyn ParserRuleContext) {}
}

impl FHIRPathListener for Listener {
...
}

fn main() {
    let input = String::from("Observation.value");
    let lexer = FHIRPathLexer::new(Box::new(InputStream::new(input)));
    let token_source = CommonTokenStream::new(lexer);
    let mut parser = FHIRPathParser::new(Box::new(token_source));
    parser.add_parse_listener(Box::new(Listener {}));
    let result = parser.expression();
    assert!(result.is_ok());
}

Getting error:

thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', /home/alex/.cargo/registry/src/github.com-1ecc6299db9ec823/antlr-rust-0.1.1/src/parser.rs:442:79
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:78
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:59
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1076
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1537
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:62
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:198
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:217
  10: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:526
  11: rust_begin_unwind
             at src/libstd/panicking.rs:437
  12: core::panicking::panic_fmt
             at src/libcore/panicking.rs:85
  13: core::panicking::panic
             at src/libcore/panicking.rs:50
  14: core::option::Option<T>::unwrap
             at /home/alex/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/macros/mod.rs:10
  15: antlr_rust::parser::BaseParser<Ext,T>::unroll_recursion_context
             at /home/alex/.cargo/registry/src/github.com-1ecc6299db9ec823/antlr-rust-0.1.1/src/parser.rs:442
  16: fhir_server_fhirpath::parser::fhirpathparser::FHIRPathParser::expression_rec
             at src/parser/fhirpathparser.rs:1493
  17: fhir_server_fhirpath::parser::fhirpathparser::FHIRPathParser::expression
             at src/parser/fhirpathparser.rs:1097
  18: fhir_server_fhirpath::main
             at src/main.rs:534
  19: std::rt::lang_start::{{closure}}
             at /home/alex/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/rt.rs:67
  20: std::rt::lang_start_internal::{{closure}}
             at src/libstd/rt.rs:52
  21: std::panicking::try::do_call
             at src/libstd/panicking.rs:348
  22: std::panicking::try
             at src/libstd/panicking.rs:325
  23: std::panic::catch_unwind
             at src/libstd/panic.rs:394
  24: std::rt::lang_start_internal
             at src/libstd/rt.rs:51
  25: std::rt::lang_start
             at /home/alex/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/rt.rs:67
  26: main
  27: __libc_start_main
  28: _start

rust version: 1.46.0-nightly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant