Skip to main content

dsntk_feel_parser/
lib.rs

1#![doc = include_str!("../docs/README.md")]
2#![deny(rustdoc::broken_intra_doc_links)]
3
4#[macro_use]
5extern crate dsntk_macros;
6
7mod ast;
8mod closure;
9mod context;
10mod errors;
11mod lalr;
12mod lexer;
13mod parser;
14mod scope;
15
16#[cfg(test)]
17mod tests;
18
19pub use ast::AstNode;
20pub use closure::ClosureBuilder;
21pub use scope::ParsingScope;
22
23use crate::errors::*;
24use crate::lalr::TokenType;
25use crate::parser::Parser;
26use dsntk_common::Result;
27use dsntk_feel::{FeelScope, Name};
28
29/// Parses an `expression` as defined in grammar rule `1`.
30pub fn parse_expression(scope: &FeelScope, input: &str, trace: bool) -> Result<AstNode> {
31  Parser::new(&scope.into(), TokenType::StartExpression, input, trace).parse()
32}
33
34/// Parses a `textual expression` as defined in grammar rule `2`.
35pub fn parse_textual_expression(scope: &FeelScope, input: &str, trace: bool) -> Result<AstNode> {
36  Parser::new(&scope.into(), TokenType::StartTextualExpression, input, trace).parse()
37}
38
39/// Parses `textual expressions` as defined in grammar rule `3`.
40pub fn parse_textual_expressions(scope: &FeelScope, input: &str, trace: bool) -> Result<AstNode> {
41  Parser::new(&scope.into(), TokenType::StartTextualExpressions, input, trace).parse()
42}
43
44/// Parses a `simple expression` as defined in grammar rule `5`.
45pub fn parse_simple_expression(scope: &FeelScope, input: &str, trace: bool) -> Result<AstNode> {
46  Parser::new(&scope.into(), TokenType::StartSimpleExpression, input, trace).parse()
47}
48
49/// Parses `simple expressions` as defined in grammar rule `6`.
50pub fn parse_simple_expressions(scope: &FeelScope, input: &str, trace: bool) -> Result<AstNode> {
51  Parser::new(&scope.into(), TokenType::StartSimpleExpressions, input, trace).parse()
52}
53
54/// Parses `unary tests` as defined in grammar rule `15`.
55pub fn parse_unary_tests(scope: &FeelScope, input: &str, trace: bool) -> Result<AstNode> {
56  Parser::new(&scope.into(), TokenType::StartUnaryTests, input, trace).parse()
57}
58
59/// Parses a `simple value` as defined in grammar rule `17`.
60pub fn parse_simple_value(scope: &FeelScope, input: &str, trace: bool) -> Result<AstNode> {
61  Parser::new(&scope.into(), TokenType::StartSimpleValue, input, trace).parse()
62}
63
64/// Parses a `name` as defined grammar rule `25`.
65pub fn parse_name(scope: &FeelScope, input: &str, trace: bool) -> Result<Name> {
66  if let AstNode::Name(name) = Parser::new(&scope.into(), TokenType::StartTextualExpression, input, trace).parse()? {
67    Ok(name)
68  } else {
69    Err(err_not_a_feel_name(input))
70  }
71}
72
73/// Parses the longest valid `name` as defined in grammar rule `25`.
74pub fn parse_longest_name(input: &str) -> Result<Name> {
75  parse_name(&Default::default(), input, false)
76}
77
78/// Parses a `boxed expression` as defined in grammar rule `53`.
79pub fn parse_boxed_expression(scope: &FeelScope, input: &str, trace: bool) -> Result<AstNode> {
80  Parser::new(&scope.into(), TokenType::StartBoxedExpression, input, trace).parse()
81}
82
83/// Parses a `context` as defined in grammar rule `59`.
84pub fn parse_context(scope: &FeelScope, input: &str, trace: bool) -> Result<AstNode> {
85  Parser::new(&scope.into(), TokenType::StartBoxedExpression, input, trace).parse()
86}
87
88/// Parses a `range literal` as defined in grammar rule `66`.
89pub fn parse_range_literal(scope: &FeelScope, input: &str, trace: bool) -> Result<AstNode> {
90  Parser::new(&scope.into(), TokenType::StartRangeLiteral, input, trace).parse()
91}