dsntk_feel_parser/
lib.rs

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