DMNTK | Decision Model and Notation Toolkit

dmntk-feel-grammar

FEEL grammar and parsing tables generator:

Crates.io MIT licensed Apache 2.0 licensed Code coverage

Overview

Excerpt from Decision Model and Notation™ specification, ver. 1.3, pp. 105-179:

"DMN 1.3 defines the friendly enough expression language (FEEL) for the purpose of giving standard executable semantics to many kinds of expressions in decision model. [...] FEEL syntax is defined as a grammar here [...]".

dmntk-feel-grammar crate defines the Bison version of the full FEEL grammar as defined in clause 10.3 of cited above Decision Model and Notation™ specification.

In addition, dmntk-feel-grammar crate provides functionality for generating LALR parsing tables and reduce actions, ready to be used by LALR parser written in Rust. Such parser that uses the output from dmntk-feel-grammar crate is implemented in dmntk-feel-parser.

How it works

Inputs and outputs of dmntk-feel-grammar crate are depicted in the following diagram:

Component

dmntk-feel-grammar takes Yacc/Bison compatible grammar file as an input. Grammar file for FEEL language is defined as a source file named feel.y and compiled with this crate.

The output from dmntk-feel-grammar create is a file named lalr.rs. This file is a Rust source code that contains definitions of parsing tables and reduce actions.

dmntk-feel-grammar crate uses Bison parser generator to process the input grammar file and to generate the parser source for C language. Command that generates the parser for C language using Bison may look like this: shell $ LANG=C bison -l -r states -L C feel.y Bison generates C source file that contains the generated parsing tables. dmntk-feel-grammar extracts those tables, adds reduce action definitions and saves the result code in lalr.rs file as Rust source code.

Requirements

dmntk-feel-grammar requires: - installed the newest Rust nightly version, - installed the newest Bison version.

Usage

dmntk-feel-grammar may be used as a library.

Add dmntk-feel-grammar to your Cargo.toml:

toml [dependencies] dmntk-feel-grammar = "0.0.20"

To generate LALR parsing tables, call lalr_rust_tables function:

```rust use dmntkfeelgrammar::lalrrusttables;

fn main() { lalrrusttables("./src/lalr.rs"); } ```

Implemented grammar rules

The following grammar rules are taken from Decision Model and Notation™ ver. 1.3

  1. expression =

  2. textual_expression =

  3. textualexpressions = textual expression , { , , textualexpression } ;

  4. arithmetic_expression =

  5. simpleexpression = arithmeticexpression | simple_value ;

  6. simpleexpressions = simpleexpression , { , , simple_expression } ;

  7. simplepositiveunary_test =

  8. interval = ( openintervalstart | closedintervalstart ) , endpoint , .. , endpoint , ( openintervalend | closedintervalend ) ;

  9. openintervalstart = ( | ] ;

  10. closedintervalstart = [ ;

  11. openintervalend = ) | [ ;

  12. closedintervalend = ] ;

  13. positiveunarytest = expression ;

  14. positiveunarytests = positiveunarytest , { , , positiveunarytest } ;

  15. unary_tests =

  16. endpoint = simple_value ;

  17. simplevalue = qualifiedname | simple_literal ;

  18. qualified_name = name , { . , name } ;

  19. addition = expression , + , expression ;

  20. subtraction = expression , - , expression ;

  21. multiplication = expression , * , expression ;

  22. division = expression , / , expression ;

  23. exponentiation = expression, **, expression ;

  24. arithmetic_negation = - , expression ;

  25. name = namestart , { namepart | additionalnamesymbols } ;

  26. namestart = namestartchar, { namepart_char } ;

  27. namepart = namepartchar , { namepart_char } ;

  28. namestartchar = ? | [A-Z] | _ | [a-z] | [\uC0-\uD6] | [\uD8-\uF6] | [\uF8-\u2FF] | [\u370-\u37D] | [\u37F-\u1FFF] | [\u200C-\u200D] | [\u2070-\u218F] | [\u2C00-\u2FEF] | [\u3001-\uD7FF] | [\uF900-\uFDCF] | [\uFDF0-\uFFFD] | [\u10000-\uEFFFF] ;

  29. namepartchar = namestartchar | digit | \uB7 | [\u0300-\u036F] | [\u203F-\u2040] ;

  30. additionalnamesymbols = . | / | - | | + | * ;

  31. literal = simple_literal | null ;

  32. simpleliteral = numericliteral | stringliteral | booleanliteral | datetimeliteral ;

  33. stringliteral = ", { character – (" | verticalspace) | stringescapesequence}, " ;

  34. boolean_literal = true | false ;

  35. numeric_literal = [ - ] , ( digits , [ ., digits ] | . , digits ) ;

  36. digit = [0-9] ;

  37. digits = digit , { digit } ;

  38. function_invocation = expression , parameters ;

  39. parameters = ( , ( namedparameters | positionalparameters ) , ) ;

  40. namedparameters = parametername , : , expression , { , , parameter name , : , expression } ;

  41. parameter_name = name ;

  42. positional_parameters = [ expression , { , , expression } ] ;

  43. path_expression = expression , . , name ;

  44. for_expression = for , name , in , iteration context { , , name , in , iteration context } , return , expression ;

  45. if_expression = if , expression , then , expression , else expression ;

  46. quantified_expression = (some | every) , name , in , expression , { , , name , in , expression } , satisfies , expression ;

  47. disjunction = expression , or , expression ;

  48. conjunction = expression , and , expression ;

  49. comparison =

  50. filter_expression = expression , [ , expression , ] ;

  51. instance_of = expression , instance , of , type ;

  52. type =

  53. boxedexpression = list | functiondefinition | context ;

  54. list = [ , [ expression , { , , expression } ] , ] ;

  55. functiondefinition = function , ( , [ formalparameter { , , formal parameter } ] , ) , [ external ] , expression ;

  56. formalparameter = parametername [: type ] ;

  57. context = { , [contextentry , { , , contextentry } ] , } ;

  58. context_entry = key , : , expression ;

  59. key = name | string_literal ;

  60. datetimeliteral = atliteral | functioninvocation ;

  61. whitespace = verticalspace | \u0009 | \u0020 | \u0085 | \u00A0 | \u1680 | \u180E | [\u2000-\u200B] | \u2028 | \u2029 | \u202F | \u205F | \u3000 | \uFEFF ;

  62. vertical_space = [\u000A-\u000D] ;

  63. iteration_context = expression, [ .., expression ] ;

  64. stringescapesequence = \' | \" | \\ | \n | \r | \t | code_point;

  65. atliteral = @, stringliteral

License

dmntk-feel-grammar is distributed under the terms of both the MIT license and the Apache License (Version 2.0). See LICENSE-MIT and LICENSE-APACHE for details.