diff options
| author | Sébastien Dailly <sebastien@dailly.me> | 2026-03-27 08:48:05 +0100 |
|---|---|---|
| committer | Sébastien Dailly <sebastien@dailly.me> | 2026-03-27 08:48:05 +0100 |
| commit | 830e7c5d27d161b91402414e6ecd49f1ed818bfb (patch) | |
| tree | 448864635d29b1ea66424cbb9e0816fbcf1e1907 | |
Initial commit
60 files changed, 4749 insertions, 0 deletions
diff --git a/lib/configuration/all_errors b/lib/configuration/all_errors new file mode 100644 index 0000000..737023d --- /dev/null +++ b/lib/configuration/all_errors @@ -0,0 +1,911 @@ +path_expr: R_PAREN +## +## Ends in an error in state: 0. +## +## path_expr' -> . path_expr [ # ] +## +## The known suffix of the stack is as follows: +## +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: L_PAREN R_PAREN +## +## Ends in an error in state: 1. +## +## expr_(path_,EOF) -> L_PAREN . expr_(path_,R_PAREN) R_PAREN [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## L_PAREN +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: L_PAREN L_PAREN R_PAREN +## +## Ends in an error in state: 2. +## +## expr_(path_,R_PAREN) -> L_PAREN . expr_(path_,R_PAREN) R_PAREN [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## L_PAREN +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: L_PAREN IDENT R_PAREN +## +## Ends in an error in state: 5. +## +## expr_(path_,R_PAREN) -> IDENT . arguments(path_) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,R_PAREN) -> IDENT . L_PAREN option(opt_arg(path_,COMA)) group(path_) COMA group(path_) R_PAREN [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## IDENT +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: L_PAREN IDENT L_PAREN R_BRACKET +## +## Ends in an error in state: 6. +## +## arguments(path_) -> L_PAREN . loption(separated_nonempty_list(COMA,expr_(path_,COMA))) R_PAREN [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,R_PAREN) -> IDENT L_PAREN . option(opt_arg(path_,COMA)) group(path_) COMA group(path_) R_PAREN [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## IDENT L_PAREN +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: INTEGER BOOL_OPERATOR L_PAREN R_PAREN +## +## Ends in an error in state: 7. +## +## expr_(path_,COMA) -> L_PAREN . expr_(path_,R_PAREN) R_PAREN [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## L_PAREN +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: COLUMN R_PAREN +## +## Ends in an error in state: 8. +## +## path_ -> COLUMN . separated_nonempty_list(DOT,IDENT) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## COLUMN +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: COLUMN IDENT L_PAREN +## +## Ends in an error in state: 9. +## +## separated_nonempty_list(DOT,IDENT) -> IDENT . [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## separated_nonempty_list(DOT,IDENT) -> IDENT . DOT separated_nonempty_list(DOT,IDENT) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## IDENT +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: COLUMN IDENT DOT R_PAREN +## +## Ends in an error in state: 10. +## +## separated_nonempty_list(DOT,IDENT) -> IDENT DOT . separated_nonempty_list(DOT,IDENT) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## IDENT DOT +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: INTEGER BOOL_OPERATOR L_PAREN INTEGER R_BRACKET +## +## Ends in an error in state: 15. +## +## expr_(path_,COMA) -> L_PAREN expr_(path_,R_PAREN) . R_PAREN [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,R_PAREN) -> expr_(path_,R_PAREN) . CONCAT_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,R_PAREN) -> expr_(path_,R_PAREN) . BINARY_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,R_PAREN) -> expr_(path_,R_PAREN) . INEQUALITY_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,R_PAREN) -> expr_(path_,R_PAREN) . EQUALITY_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,R_PAREN) -> expr_(path_,R_PAREN) . BOOL_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,R_PAREN) -> expr_(path_,R_PAREN) . EQUALITY_OPERATOR group(path_) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## L_PAREN expr_(path_,R_PAREN) +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: L_PAREN INTEGER INEQUALITY_OPERATOR R_PAREN +## +## Ends in an error in state: 17. +## +## expr_(path_,R_PAREN) -> expr_(path_,R_PAREN) INEQUALITY_OPERATOR . expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## expr_(path_,R_PAREN) INEQUALITY_OPERATOR +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: INTEGER BOOL_OPERATOR IDENT R_PAREN +## +## Ends in an error in state: 18. +## +## expr_(path_,COMA) -> IDENT . arguments(path_) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> IDENT . L_PAREN option(opt_arg(path_,COMA)) group(path_) COMA group(path_) R_PAREN [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## IDENT +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: INTEGER BOOL_OPERATOR IDENT L_PAREN R_BRACKET +## +## Ends in an error in state: 19. +## +## arguments(path_) -> L_PAREN . loption(separated_nonempty_list(COMA,expr_(path_,COMA))) R_PAREN [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> IDENT L_PAREN . option(opt_arg(path_,COMA)) group(path_) COMA group(path_) R_PAREN [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## IDENT L_PAREN +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: INTEGER EQUALITY_OPERATOR L_BRACKET R_PAREN +## +## Ends in an error in state: 23. +## +## group(path_) -> L_BRACKET . loption(separated_nonempty_list(COMA,expr_(path_,COMA))) R_BRACKET [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## L_BRACKET +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: INTEGER EQUALITY_OPERATOR L_BRACKET INTEGER R_PAREN +## +## Ends in an error in state: 24. +## +## group(path_) -> L_BRACKET loption(separated_nonempty_list(COMA,expr_(path_,COMA))) . R_BRACKET [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## L_BRACKET loption(separated_nonempty_list(COMA,expr_(path_,COMA))) +## +## WARNING: This example involves spurious reductions. +## This implies that, although the LR(1) items shown above provide an +## accurate view of the past (what has been recognized so far), they +## may provide an INCOMPLETE view of the future (what was expected next). +## In state 27, spurious reduction of production separated_nonempty_list(COMA,expr_(path_,COMA)) -> expr_(path_,COMA) +## In state 20, spurious reduction of production loption(separated_nonempty_list(COMA,expr_(path_,COMA))) -> separated_nonempty_list(COMA,expr_(path_,COMA)) +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: INTEGER EQUALITY_OPERATOR L_BRACKET INTEGER EOF +## +## Ends in an error in state: 27. +## +## expr_(path_,COMA) -> expr_(path_,COMA) . CONCAT_OPERATOR expr_(path_,COMA) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . BINARY_OPERATOR expr_(path_,COMA) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . INEQUALITY_OPERATOR expr_(path_,COMA) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . EQUALITY_OPERATOR expr_(path_,COMA) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . BOOL_OPERATOR expr_(path_,COMA) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . EQUALITY_OPERATOR group(path_) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## separated_nonempty_list(COMA,expr_(path_,COMA)) -> expr_(path_,COMA) . [ R_PAREN R_BRACKET ] +## separated_nonempty_list(COMA,expr_(path_,COMA)) -> expr_(path_,COMA) . COMA separated_nonempty_list(COMA,expr_(path_,COMA)) [ R_PAREN R_BRACKET ] +## +## The known suffix of the stack is as follows: +## expr_(path_,COMA) +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: INTEGER BOOL_OPERATOR INTEGER INEQUALITY_OPERATOR R_PAREN +## +## Ends in an error in state: 28. +## +## expr_(path_,COMA) -> expr_(path_,COMA) INEQUALITY_OPERATOR . expr_(path_,COMA) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## expr_(path_,COMA) INEQUALITY_OPERATOR +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: INTEGER BOOL_OPERATOR INTEGER INEQUALITY_OPERATOR INTEGER L_PAREN +## +## Ends in an error in state: 29. +## +## expr_(path_,COMA) -> expr_(path_,COMA) . CONCAT_OPERATOR expr_(path_,COMA) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . BINARY_OPERATOR expr_(path_,COMA) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . INEQUALITY_OPERATOR expr_(path_,COMA) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) INEQUALITY_OPERATOR expr_(path_,COMA) . [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . EQUALITY_OPERATOR expr_(path_,COMA) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . BOOL_OPERATOR expr_(path_,COMA) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . EQUALITY_OPERATOR group(path_) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## expr_(path_,COMA) INEQUALITY_OPERATOR expr_(path_,COMA) +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: INTEGER BOOL_OPERATOR INTEGER EQUALITY_OPERATOR R_PAREN +## +## Ends in an error in state: 30. +## +## expr_(path_,COMA) -> expr_(path_,COMA) EQUALITY_OPERATOR . expr_(path_,COMA) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) EQUALITY_OPERATOR . group(path_) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## expr_(path_,COMA) EQUALITY_OPERATOR +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: INTEGER BOOL_OPERATOR INTEGER EQUALITY_OPERATOR INTEGER L_PAREN +## +## Ends in an error in state: 32. +## +## expr_(path_,COMA) -> expr_(path_,COMA) . CONCAT_OPERATOR expr_(path_,COMA) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . BINARY_OPERATOR expr_(path_,COMA) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . INEQUALITY_OPERATOR expr_(path_,COMA) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . EQUALITY_OPERATOR expr_(path_,COMA) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) EQUALITY_OPERATOR expr_(path_,COMA) . [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . BOOL_OPERATOR expr_(path_,COMA) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . EQUALITY_OPERATOR group(path_) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## expr_(path_,COMA) EQUALITY_OPERATOR expr_(path_,COMA) +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: INTEGER BOOL_OPERATOR INTEGER CONCAT_OPERATOR R_PAREN +## +## Ends in an error in state: 33. +## +## expr_(path_,COMA) -> expr_(path_,COMA) CONCAT_OPERATOR . expr_(path_,COMA) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## expr_(path_,COMA) CONCAT_OPERATOR +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: INTEGER BOOL_OPERATOR INTEGER CONCAT_OPERATOR INTEGER L_PAREN +## +## Ends in an error in state: 34. +## +## expr_(path_,COMA) -> expr_(path_,COMA) . CONCAT_OPERATOR expr_(path_,COMA) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) CONCAT_OPERATOR expr_(path_,COMA) . [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . BINARY_OPERATOR expr_(path_,COMA) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . INEQUALITY_OPERATOR expr_(path_,COMA) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . EQUALITY_OPERATOR expr_(path_,COMA) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . BOOL_OPERATOR expr_(path_,COMA) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . EQUALITY_OPERATOR group(path_) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## expr_(path_,COMA) CONCAT_OPERATOR expr_(path_,COMA) +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: INTEGER BOOL_OPERATOR INTEGER BINARY_OPERATOR R_PAREN +## +## Ends in an error in state: 35. +## +## expr_(path_,COMA) -> expr_(path_,COMA) BINARY_OPERATOR . expr_(path_,COMA) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## expr_(path_,COMA) BINARY_OPERATOR +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: INTEGER BOOL_OPERATOR INTEGER BINARY_OPERATOR INTEGER L_PAREN +## +## Ends in an error in state: 36. +## +## expr_(path_,COMA) -> expr_(path_,COMA) . CONCAT_OPERATOR expr_(path_,COMA) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . BINARY_OPERATOR expr_(path_,COMA) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) BINARY_OPERATOR expr_(path_,COMA) . [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . INEQUALITY_OPERATOR expr_(path_,COMA) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . EQUALITY_OPERATOR expr_(path_,COMA) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . BOOL_OPERATOR expr_(path_,COMA) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . EQUALITY_OPERATOR group(path_) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## expr_(path_,COMA) BINARY_OPERATOR expr_(path_,COMA) +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: INTEGER EQUALITY_OPERATOR L_BRACKET INTEGER COMA R_PAREN +## +## Ends in an error in state: 37. +## +## separated_nonempty_list(COMA,expr_(path_,COMA)) -> expr_(path_,COMA) COMA . separated_nonempty_list(COMA,expr_(path_,COMA)) [ R_PAREN R_BRACKET ] +## +## The known suffix of the stack is as follows: +## expr_(path_,COMA) COMA +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: INTEGER BOOL_OPERATOR INTEGER BOOL_OPERATOR R_PAREN +## +## Ends in an error in state: 39. +## +## expr_(path_,COMA) -> expr_(path_,COMA) BOOL_OPERATOR . expr_(path_,COMA) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## expr_(path_,COMA) BOOL_OPERATOR +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: INTEGER BOOL_OPERATOR INTEGER BOOL_OPERATOR INTEGER L_PAREN +## +## Ends in an error in state: 40. +## +## expr_(path_,COMA) -> expr_(path_,COMA) . CONCAT_OPERATOR expr_(path_,COMA) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . BINARY_OPERATOR expr_(path_,COMA) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . INEQUALITY_OPERATOR expr_(path_,COMA) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . EQUALITY_OPERATOR expr_(path_,COMA) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . BOOL_OPERATOR expr_(path_,COMA) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) BOOL_OPERATOR expr_(path_,COMA) . [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . EQUALITY_OPERATOR group(path_) [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## expr_(path_,COMA) BOOL_OPERATOR expr_(path_,COMA) +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: INTEGER BOOL_OPERATOR IDENT L_PAREN L_BRACKET R_BRACKET R_PAREN +## +## Ends in an error in state: 41. +## +## expr_(path_,COMA) -> IDENT L_PAREN option(opt_arg(path_,COMA)) group(path_) . COMA group(path_) R_PAREN [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## IDENT L_PAREN option(opt_arg(path_,COMA)) group(path_) +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: INTEGER BOOL_OPERATOR IDENT L_PAREN L_BRACKET R_BRACKET COMA R_PAREN +## +## Ends in an error in state: 42. +## +## expr_(path_,COMA) -> IDENT L_PAREN option(opt_arg(path_,COMA)) group(path_) COMA . group(path_) R_PAREN [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## IDENT L_PAREN option(opt_arg(path_,COMA)) group(path_) COMA +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: INTEGER BOOL_OPERATOR IDENT L_PAREN L_BRACKET R_BRACKET COMA L_BRACKET R_BRACKET R_BRACKET +## +## Ends in an error in state: 43. +## +## expr_(path_,COMA) -> IDENT L_PAREN option(opt_arg(path_,COMA)) group(path_) COMA group(path_) . R_PAREN [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## IDENT L_PAREN option(opt_arg(path_,COMA)) group(path_) COMA group(path_) +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: IDENT L_PAREN INTEGER COMA INTEGER R_BRACKET +## +## Ends in an error in state: 46. +## +## arguments(path_) -> L_PAREN loption(separated_nonempty_list(COMA,expr_(path_,COMA))) . R_PAREN [ R_PAREN R_BRACKET INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## L_PAREN loption(separated_nonempty_list(COMA,expr_(path_,COMA))) +## +## WARNING: This example involves spurious reductions. +## This implies that, although the LR(1) items shown above provide an +## accurate view of the past (what has been recognized so far), they +## may provide an INCOMPLETE view of the future (what was expected next). +## In state 27, spurious reduction of production separated_nonempty_list(COMA,expr_(path_,COMA)) -> expr_(path_,COMA) +## In state 38, spurious reduction of production separated_nonempty_list(COMA,expr_(path_,COMA)) -> expr_(path_,COMA) COMA separated_nonempty_list(COMA,expr_(path_,COMA)) +## In state 20, spurious reduction of production loption(separated_nonempty_list(COMA,expr_(path_,COMA))) -> separated_nonempty_list(COMA,expr_(path_,COMA)) +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: IDENT L_PAREN INTEGER R_BRACKET +## +## Ends in an error in state: 48. +## +## expr_(path_,COMA) -> expr_(path_,COMA) . CONCAT_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . BINARY_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . INEQUALITY_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . EQUALITY_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . BOOL_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . EQUALITY_OPERATOR group(path_) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR COMA BOOL_OPERATOR BINARY_OPERATOR ] +## opt_arg(path_,COMA) -> expr_(path_,COMA) . COMA [ L_BRACKET ] +## separated_nonempty_list(COMA,expr_(path_,COMA)) -> expr_(path_,COMA) . [ R_PAREN ] +## separated_nonempty_list(COMA,expr_(path_,COMA)) -> expr_(path_,COMA) . COMA separated_nonempty_list(COMA,expr_(path_,COMA)) [ R_PAREN ] +## +## The known suffix of the stack is as follows: +## expr_(path_,COMA) +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: IDENT L_PAREN INTEGER COMA R_PAREN +## +## Ends in an error in state: 49. +## +## opt_arg(path_,COMA) -> expr_(path_,COMA) COMA . [ L_BRACKET ] +## separated_nonempty_list(COMA,expr_(path_,COMA)) -> expr_(path_,COMA) COMA . separated_nonempty_list(COMA,expr_(path_,COMA)) [ R_PAREN ] +## +## The known suffix of the stack is as follows: +## expr_(path_,COMA) COMA +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: L_PAREN INTEGER INEQUALITY_OPERATOR INTEGER R_BRACKET +## +## Ends in an error in state: 51. +## +## expr_(path_,COMA) -> expr_(path_,COMA) . CONCAT_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . BINARY_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . INEQUALITY_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . EQUALITY_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . BOOL_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . EQUALITY_OPERATOR group(path_) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,R_PAREN) -> expr_(path_,R_PAREN) INEQUALITY_OPERATOR expr_(path_,COMA) . [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## expr_(path_,R_PAREN) INEQUALITY_OPERATOR expr_(path_,COMA) +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: L_PAREN INTEGER EQUALITY_OPERATOR R_PAREN +## +## Ends in an error in state: 52. +## +## expr_(path_,R_PAREN) -> expr_(path_,R_PAREN) EQUALITY_OPERATOR . expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,R_PAREN) -> expr_(path_,R_PAREN) EQUALITY_OPERATOR . group(path_) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## expr_(path_,R_PAREN) EQUALITY_OPERATOR +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: L_PAREN INTEGER EQUALITY_OPERATOR INTEGER R_BRACKET +## +## Ends in an error in state: 54. +## +## expr_(path_,COMA) -> expr_(path_,COMA) . CONCAT_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . BINARY_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . INEQUALITY_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . EQUALITY_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . BOOL_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . EQUALITY_OPERATOR group(path_) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,R_PAREN) -> expr_(path_,R_PAREN) EQUALITY_OPERATOR expr_(path_,COMA) . [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## expr_(path_,R_PAREN) EQUALITY_OPERATOR expr_(path_,COMA) +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: L_PAREN INTEGER CONCAT_OPERATOR R_PAREN +## +## Ends in an error in state: 55. +## +## expr_(path_,R_PAREN) -> expr_(path_,R_PAREN) CONCAT_OPERATOR . expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## expr_(path_,R_PAREN) CONCAT_OPERATOR +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: L_PAREN INTEGER CONCAT_OPERATOR INTEGER R_BRACKET +## +## Ends in an error in state: 56. +## +## expr_(path_,COMA) -> expr_(path_,COMA) . CONCAT_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . BINARY_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . INEQUALITY_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . EQUALITY_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . BOOL_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . EQUALITY_OPERATOR group(path_) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,R_PAREN) -> expr_(path_,R_PAREN) CONCAT_OPERATOR expr_(path_,COMA) . [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## expr_(path_,R_PAREN) CONCAT_OPERATOR expr_(path_,COMA) +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: L_PAREN INTEGER BOOL_OPERATOR R_PAREN +## +## Ends in an error in state: 57. +## +## expr_(path_,R_PAREN) -> expr_(path_,R_PAREN) BOOL_OPERATOR . expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## expr_(path_,R_PAREN) BOOL_OPERATOR +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: L_PAREN INTEGER BOOL_OPERATOR INTEGER R_BRACKET +## +## Ends in an error in state: 58. +## +## expr_(path_,COMA) -> expr_(path_,COMA) . CONCAT_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . BINARY_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . INEQUALITY_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . EQUALITY_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . BOOL_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . EQUALITY_OPERATOR group(path_) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,R_PAREN) -> expr_(path_,R_PAREN) BOOL_OPERATOR expr_(path_,COMA) . [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## expr_(path_,R_PAREN) BOOL_OPERATOR expr_(path_,COMA) +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: L_PAREN INTEGER BINARY_OPERATOR R_PAREN +## +## Ends in an error in state: 59. +## +## expr_(path_,R_PAREN) -> expr_(path_,R_PAREN) BINARY_OPERATOR . expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## expr_(path_,R_PAREN) BINARY_OPERATOR +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: L_PAREN INTEGER BINARY_OPERATOR INTEGER R_BRACKET +## +## Ends in an error in state: 60. +## +## expr_(path_,COMA) -> expr_(path_,COMA) . CONCAT_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . BINARY_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . INEQUALITY_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . EQUALITY_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . BOOL_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . EQUALITY_OPERATOR group(path_) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,R_PAREN) -> expr_(path_,R_PAREN) BINARY_OPERATOR expr_(path_,COMA) . [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## expr_(path_,R_PAREN) BINARY_OPERATOR expr_(path_,COMA) +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: L_PAREN IDENT L_PAREN L_BRACKET R_BRACKET R_PAREN +## +## Ends in an error in state: 62. +## +## expr_(path_,R_PAREN) -> IDENT L_PAREN option(opt_arg(path_,COMA)) group(path_) . COMA group(path_) R_PAREN [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## IDENT L_PAREN option(opt_arg(path_,COMA)) group(path_) +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: L_PAREN IDENT L_PAREN L_BRACKET R_BRACKET COMA R_PAREN +## +## Ends in an error in state: 63. +## +## expr_(path_,R_PAREN) -> IDENT L_PAREN option(opt_arg(path_,COMA)) group(path_) COMA . group(path_) R_PAREN [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## IDENT L_PAREN option(opt_arg(path_,COMA)) group(path_) COMA +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: L_PAREN IDENT L_PAREN L_BRACKET R_BRACKET COMA L_BRACKET R_BRACKET R_BRACKET +## +## Ends in an error in state: 64. +## +## expr_(path_,R_PAREN) -> IDENT L_PAREN option(opt_arg(path_,COMA)) group(path_) COMA group(path_) . R_PAREN [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## IDENT L_PAREN option(opt_arg(path_,COMA)) group(path_) COMA group(path_) +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: L_PAREN L_PAREN INTEGER R_BRACKET +## +## Ends in an error in state: 67. +## +## expr_(path_,R_PAREN) -> L_PAREN expr_(path_,R_PAREN) . R_PAREN [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,R_PAREN) -> expr_(path_,R_PAREN) . CONCAT_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,R_PAREN) -> expr_(path_,R_PAREN) . BINARY_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,R_PAREN) -> expr_(path_,R_PAREN) . INEQUALITY_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,R_PAREN) -> expr_(path_,R_PAREN) . EQUALITY_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,R_PAREN) -> expr_(path_,R_PAREN) . BOOL_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,R_PAREN) -> expr_(path_,R_PAREN) . EQUALITY_OPERATOR group(path_) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## L_PAREN expr_(path_,R_PAREN) +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: L_PAREN INTEGER R_BRACKET +## +## Ends in an error in state: 69. +## +## expr_(path_,EOF) -> L_PAREN expr_(path_,R_PAREN) . R_PAREN [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,R_PAREN) -> expr_(path_,R_PAREN) . CONCAT_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,R_PAREN) -> expr_(path_,R_PAREN) . BINARY_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,R_PAREN) -> expr_(path_,R_PAREN) . INEQUALITY_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,R_PAREN) -> expr_(path_,R_PAREN) . EQUALITY_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,R_PAREN) -> expr_(path_,R_PAREN) . BOOL_OPERATOR expr_(path_,COMA) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,R_PAREN) -> expr_(path_,R_PAREN) . EQUALITY_OPERATOR group(path_) [ R_PAREN INEQUALITY_OPERATOR EQUALITY_OPERATOR CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## L_PAREN expr_(path_,R_PAREN) +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: IDENT R_PAREN +## +## Ends in an error in state: 71. +## +## expr_(path_,EOF) -> IDENT . arguments(path_) [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,EOF) -> IDENT . L_PAREN option(opt_arg(path_,COMA)) group(path_) COMA group(path_) R_PAREN [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## IDENT +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: IDENT L_PAREN R_BRACKET +## +## Ends in an error in state: 72. +## +## arguments(path_) -> L_PAREN . loption(separated_nonempty_list(COMA,expr_(path_,COMA))) R_PAREN [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,EOF) -> IDENT L_PAREN . option(opt_arg(path_,COMA)) group(path_) COMA group(path_) R_PAREN [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## IDENT L_PAREN +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: IDENT L_PAREN L_BRACKET R_BRACKET R_PAREN +## +## Ends in an error in state: 74. +## +## expr_(path_,EOF) -> IDENT L_PAREN option(opt_arg(path_,COMA)) group(path_) . COMA group(path_) R_PAREN [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## IDENT L_PAREN option(opt_arg(path_,COMA)) group(path_) +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: IDENT L_PAREN L_BRACKET R_BRACKET COMA R_PAREN +## +## Ends in an error in state: 75. +## +## expr_(path_,EOF) -> IDENT L_PAREN option(opt_arg(path_,COMA)) group(path_) COMA . group(path_) R_PAREN [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## IDENT L_PAREN option(opt_arg(path_,COMA)) group(path_) COMA +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: IDENT L_PAREN L_BRACKET R_BRACKET COMA L_BRACKET R_BRACKET R_BRACKET +## +## Ends in an error in state: 76. +## +## expr_(path_,EOF) -> IDENT L_PAREN option(opt_arg(path_,COMA)) group(path_) COMA group(path_) . R_PAREN [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## IDENT L_PAREN option(opt_arg(path_,COMA)) group(path_) COMA group(path_) +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: INTEGER R_PAREN +## +## Ends in an error in state: 83. +## +## expr_(path_,EOF) -> expr_(path_,EOF) . CONCAT_OPERATOR expr_(path_,COMA) [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,EOF) -> expr_(path_,EOF) . BINARY_OPERATOR expr_(path_,COMA) [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,EOF) -> expr_(path_,EOF) . INEQUALITY_OPERATOR expr_(path_,COMA) [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,EOF) -> expr_(path_,EOF) . EQUALITY_OPERATOR expr_(path_,COMA) [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,EOF) -> expr_(path_,EOF) . BOOL_OPERATOR expr_(path_,COMA) [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,EOF) -> expr_(path_,EOF) . EQUALITY_OPERATOR group(path_) [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## path_expr -> expr_(path_,EOF) . EOF [ # ] +## +## The known suffix of the stack is as follows: +## expr_(path_,EOF) +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: INTEGER INEQUALITY_OPERATOR R_PAREN +## +## Ends in an error in state: 84. +## +## expr_(path_,EOF) -> expr_(path_,EOF) INEQUALITY_OPERATOR . expr_(path_,COMA) [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## expr_(path_,EOF) INEQUALITY_OPERATOR +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: INTEGER INEQUALITY_OPERATOR INTEGER R_PAREN +## +## Ends in an error in state: 85. +## +## expr_(path_,COMA) -> expr_(path_,COMA) . CONCAT_OPERATOR expr_(path_,COMA) [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . BINARY_OPERATOR expr_(path_,COMA) [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . INEQUALITY_OPERATOR expr_(path_,COMA) [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . EQUALITY_OPERATOR expr_(path_,COMA) [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . BOOL_OPERATOR expr_(path_,COMA) [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . EQUALITY_OPERATOR group(path_) [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,EOF) -> expr_(path_,EOF) INEQUALITY_OPERATOR expr_(path_,COMA) . [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## expr_(path_,EOF) INEQUALITY_OPERATOR expr_(path_,COMA) +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: INTEGER EQUALITY_OPERATOR R_PAREN +## +## Ends in an error in state: 86. +## +## expr_(path_,EOF) -> expr_(path_,EOF) EQUALITY_OPERATOR . expr_(path_,COMA) [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,EOF) -> expr_(path_,EOF) EQUALITY_OPERATOR . group(path_) [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## expr_(path_,EOF) EQUALITY_OPERATOR +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: INTEGER EQUALITY_OPERATOR INTEGER R_PAREN +## +## Ends in an error in state: 88. +## +## expr_(path_,COMA) -> expr_(path_,COMA) . CONCAT_OPERATOR expr_(path_,COMA) [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . BINARY_OPERATOR expr_(path_,COMA) [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . INEQUALITY_OPERATOR expr_(path_,COMA) [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . EQUALITY_OPERATOR expr_(path_,COMA) [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . BOOL_OPERATOR expr_(path_,COMA) [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . EQUALITY_OPERATOR group(path_) [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,EOF) -> expr_(path_,EOF) EQUALITY_OPERATOR expr_(path_,COMA) . [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## expr_(path_,EOF) EQUALITY_OPERATOR expr_(path_,COMA) +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: INTEGER CONCAT_OPERATOR R_PAREN +## +## Ends in an error in state: 90. +## +## expr_(path_,EOF) -> expr_(path_,EOF) CONCAT_OPERATOR . expr_(path_,COMA) [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## expr_(path_,EOF) CONCAT_OPERATOR +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: INTEGER CONCAT_OPERATOR INTEGER R_PAREN +## +## Ends in an error in state: 91. +## +## expr_(path_,COMA) -> expr_(path_,COMA) . CONCAT_OPERATOR expr_(path_,COMA) [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . BINARY_OPERATOR expr_(path_,COMA) [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . INEQUALITY_OPERATOR expr_(path_,COMA) [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . EQUALITY_OPERATOR expr_(path_,COMA) [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . BOOL_OPERATOR expr_(path_,COMA) [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . EQUALITY_OPERATOR group(path_) [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,EOF) -> expr_(path_,EOF) CONCAT_OPERATOR expr_(path_,COMA) . [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## expr_(path_,EOF) CONCAT_OPERATOR expr_(path_,COMA) +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: INTEGER BOOL_OPERATOR R_PAREN +## +## Ends in an error in state: 92. +## +## expr_(path_,EOF) -> expr_(path_,EOF) BOOL_OPERATOR . expr_(path_,COMA) [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## expr_(path_,EOF) BOOL_OPERATOR +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: INTEGER BOOL_OPERATOR INTEGER R_PAREN +## +## Ends in an error in state: 93. +## +## expr_(path_,COMA) -> expr_(path_,COMA) . CONCAT_OPERATOR expr_(path_,COMA) [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . BINARY_OPERATOR expr_(path_,COMA) [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . INEQUALITY_OPERATOR expr_(path_,COMA) [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . EQUALITY_OPERATOR expr_(path_,COMA) [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . BOOL_OPERATOR expr_(path_,COMA) [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . EQUALITY_OPERATOR group(path_) [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,EOF) -> expr_(path_,EOF) BOOL_OPERATOR expr_(path_,COMA) . [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## expr_(path_,EOF) BOOL_OPERATOR expr_(path_,COMA) +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: INTEGER BINARY_OPERATOR R_PAREN +## +## Ends in an error in state: 94. +## +## expr_(path_,EOF) -> expr_(path_,EOF) BINARY_OPERATOR . expr_(path_,COMA) [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## expr_(path_,EOF) BINARY_OPERATOR +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + +path_expr: INTEGER BINARY_OPERATOR INTEGER R_PAREN +## +## Ends in an error in state: 95. +## +## expr_(path_,COMA) -> expr_(path_,COMA) . CONCAT_OPERATOR expr_(path_,COMA) [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . BINARY_OPERATOR expr_(path_,COMA) [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . INEQUALITY_OPERATOR expr_(path_,COMA) [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . EQUALITY_OPERATOR expr_(path_,COMA) [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . BOOL_OPERATOR expr_(path_,COMA) [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,COMA) -> expr_(path_,COMA) . EQUALITY_OPERATOR group(path_) [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## expr_(path_,EOF) -> expr_(path_,EOF) BINARY_OPERATOR expr_(path_,COMA) . [ INEQUALITY_OPERATOR EQUALITY_OPERATOR EOF CONCAT_OPERATOR BOOL_OPERATOR BINARY_OPERATOR ] +## +## The known suffix of the stack is as follows: +## expr_(path_,EOF) BINARY_OPERATOR expr_(path_,COMA) +## + +<YOUR SYNTAX ERROR MESSAGE HERE> + diff --git a/lib/configuration/ast.ml b/lib/configuration/ast.ml new file mode 100644 index 0000000..5857902 --- /dev/null +++ b/lib/configuration/ast.ml @@ -0,0 +1,154 @@ +open StdLabels + +module Splay = Splay.Make (struct + include String + + let pp = Format.pp_print_string +end) + +let escaped = String.escaped + +type list' = { id : string; source : string } + +type setting = { + mutable contents : Model.Reference.t Model.Content.t Splay.t; + lists : list' list; +} + +let init : unit -> setting = fun () -> { contents = Splay.empty (); lists = [] } + +(** Get the content from the setting. *) +let get_content : setting -> string -> Model.Reference.t Model.Content.t option + = + fun settings name -> Splay.find name settings.contents + +exception BrokenLink : ('a Type.Id.t * 'a * string) -> exn + +(** Convert the content having fields referencing element by name into content + having fields referencing other contents *) +let rec convert : + 'a Type.Id.t -> + setting -> + ('a * string) Model.Content.t -> + Model.Reference.t Model.Content.t = + fun ty setting content -> + let subcontents = + List.map (Model.Content.subcontents content) ~f:(convert ty setting) + in + let sections = + List.map + ~f:(fun section -> + let section' : Model.Reference.t Model.Section.t = + { + section with + fields = + List.map section.Model.Section.fields ~f:(fun field -> + Model.Field.map + (fun (value, name) -> + (* Raise a local exception here, which will be checked + later once the configuration will be completely + loaded *) + Model.Reference.v (fun () -> + match get_content setting name with + | Some v -> v + | None -> raise (BrokenLink (ty, value, name)))) + field); + } + in + section') + (Model.Content.sections content) + in + Model.Content.v (Model.Content.id content) sections subcontents + +(** Register a content and all the associated subcontent in the top level, + giving the possibility to fetch any content or subcontent by is’s name + without traversing the whole tree each time. *) +let register_content : + 'a Type.Id.t -> setting -> ('a * string) Model.Content.t -> unit = + fun ty setting content -> + let rec traverse content = + let () = + setting.contents <- + Splay.add (Model.Content.id content) content setting.contents + in + List.iter ~f:traverse (Model.Content.subcontents content) + in + traverse (convert ty setting content) + +let register_list : setting -> list' -> setting = + fun t l -> { t with lists = l :: t.lists } + +(** Force the evaluation of the field target and ensure it points to an existing + content in the application. + + Return the content targeted *) +let get_reference_target : + Model.Reference.t Model.Field.t -> Model.Reference.t Model.Content.t option + = + fun field -> + let (T ty) = Model.Field.type_ field in + match ty with + | Text -> None + | Integer -> None + | MonoReference r | MultiReference r -> ( + try Some (Model.Reference.get r.Model.Typ.t) + with BrokenLink _ as e -> raise_notrace e) + +(** Extract the other contents pointed by a given content, and the field used + for it. *) +let targeted_contents : + Model.Reference.t Model.Content.t -> + (Model.Reference.t Model.Field.t * Model.Reference.t Model.Content.t) Seq.t + = + fun t -> + Seq.filter_map + (fun field -> + match get_reference_target field with + | None -> None + | Some ref -> Some (field, ref)) + (Model.Content.fields t) + +let tree : ?required:bool -> setting -> Graph_tree.t = + fun ?(required = false) setting -> + let tree = Graph_tree.create () in + let () = + Splay.fold + (fun () (_, src) -> + let targets = targeted_contents src in + let root = Model.Content.root src in + Graph_tree.add_content tree root; + Seq.iter + (fun (field, dst) -> + (* We build the dependencies tree with the root contents only. + This does not change the logic, and this makes things easer + too *) + let add_edge = (not required) || Model.Field.required field in + match add_edge with + | false -> () + | true -> + Graph_tree.add_edge tree root field (Model.Content.root dst)) + targets) + () setting.contents + in + tree + +(** Return all the contents declared in the settings. + + The list provide the root contents in the topological order *) +let root_contents : setting -> Model.Reference.t Model.Content.t list = + fun setting -> Graph_tree.fold (fun a acc -> a :: acc) (tree setting) [] + +let check : setting -> (unit, exn) result = + fun setting -> + (* Ensure each content referenced exists. + + We accept mutually recursive dependancy and need to load all the content + first before checking the settings *) + try + let _ = tree setting in + + (* Check cycle dependencies *) + let required_tree = tree ~required:true setting in + Graph_tree.check_cycle required_tree; + Ok () + with e -> Error e diff --git a/lib/configuration/ast.mli b/lib/configuration/ast.mli new file mode 100644 index 0000000..5eda6f6 --- /dev/null +++ b/lib/configuration/ast.mli @@ -0,0 +1,30 @@ +type setting +type list' = { id : string; source : string } + +val init : unit -> setting + +val get_content : setting -> string -> Model.Reference.t Model.Content.t option +(** Get the content from the setting. *) + +val root_contents : setting -> Model.Reference.t Model.Content.t list +(** Extract all the content in the topological order. + + Only the root content are repored in the list *) + +val register_content : + 'a Type.Id.t -> setting -> ('a * string) Model.Content.t -> unit +(** Register a content and all the associated subcontent in the top level, + giving the possibility to fetch any content or subcontent by is’s name + without traversing the whole tree each time. *) + +exception BrokenLink : ('a Type.Id.t * 'a * string) -> exn +(** Exception raised when a reference in the configuration targets a + non-existing content *) + +val register_list : setting -> list' -> setting + +val check : setting -> (unit, exn) result +(** Check the setting and return the the error as an exception *) + +val tree : ?required:bool -> setting -> Graph_tree.t +val escaped : string -> string diff --git a/lib/configuration/dune b/lib/configuration/dune new file mode 100755 index 0000000..134a7dc --- /dev/null +++ b/lib/configuration/dune @@ -0,0 +1,19 @@ +(library + (name configuration) + (libraries menhirLib decoders yojson yojson-five ocamlgraph splay model) + (preprocess + (pps ppx_deriving.ord ppx_deriving.show ppx_deriving.eq))) + +(rule + (targets expression_parser_messages.ml) + (deps expression_parser.messages expression_parser.mly) + (action + (with-stdout-to + %{targets} + (run menhir --compile-errors %{deps})))) + +(menhir + (modules expression_parser) + (flags --table)) + +(ocamllex expression_lexer) diff --git a/lib/configuration/expression_lexer.mll b/lib/configuration/expression_lexer.mll new file mode 100644 index 0000000..1b4602a --- /dev/null +++ b/lib/configuration/expression_lexer.mll @@ -0,0 +1,93 @@ +{ + open Expression_parser + + exception UnclosedQuote of { content: string ; line : int} +} + + +let spaces = [ ' ' '\t' ] +let letters = [^ '$' '"' '\'' '(' ')' '[' ']' ':' '.' ',' '^' ' ' '\t' '\n' '\r' ] +let digit = [ '0'-'9' ] +let eol = [ '\r' '\n' ] + +let escaped = [ '\'' '\\'] + +rule token = parse +| eol { Lexing.new_line lexbuf; token lexbuf } +| spaces { token lexbuf } +| '\'' { + try read_quoted_string (Buffer.create 17) lexbuf + with Failure _ -> + let line = lexbuf.Lexing.lex_curr_p.pos_lnum + and content = Bytes.to_string lexbuf.Lexing.lex_buffer in + raise (UnclosedQuote {line; content}) +} +| '"' { read_dquoted_string (Buffer.create 17) lexbuf } +| '#' { skip_comment lexbuf } +| '(' { L_PAREN } +| ')' { R_PAREN } +| '[' { L_BRACKET } +| ']' { R_BRACKET } +| ':' { COLUMN } +| '$' { DOLLAR } +| '.' { DOT } +| ',' { COMA } +| '^' { CONCAT_OPERATOR } +| '+' { BINARY_OPERATOR (Model.Dsl.Add) } +| '-' { BINARY_OPERATOR (Model.Dsl.Minus) } +| '/' { BINARY_OPERATOR (Model.Dsl.Division) } +| "and" { BOOL_OPERATOR (Model.Dsl.And) } +| "or" { BOOL_OPERATOR (Model.Dsl.Or) } +| '<' { INEQUALITY_OPERATOR (Model.Dsl.LT) } +| "<=" { INEQUALITY_OPERATOR (Model.Dsl.LTE) } +| '>' { INEQUALITY_OPERATOR (Model.Dsl.GT) } +| ">=" { INEQUALITY_OPERATOR (Model.Dsl.GTE) } +| "<>" { EQUALITY_OPERATOR (Model.Dsl.Different) } +| '=' { EQUALITY_OPERATOR (Model.Dsl.Equal) } +| digit+ as l { INTEGER l} +| '-' digit+ as l { INTEGER l} +| letters+ as l { IDENT l} +| eof { EOF } + +and skip_comment = parse + | [^ '\r' '\n' ] + { skip_comment lexbuf } + | eol + { token lexbuf } + +(* Read the content until we got another one quote *) +and read_quoted_string buf = parse + | [^ '\'' '\\' ]+ + { Buffer.add_string buf (Lexing.lexeme lexbuf); + read_quoted_string buf lexbuf + } + | "\\\'" + { Buffer.add_char buf '\''; + read_quoted_string buf lexbuf + } + | '\\' + { Buffer.add_char buf '\\'; + read_quoted_string buf lexbuf + } + | '\'' + { LITERAL (Buffer.contents buf) + } + +(* Read the content until we got another one quote *) +and read_dquoted_string buf = parse + | [^ '"' '\\' ]+ + { Buffer.add_string buf (Lexing.lexeme lexbuf); + read_dquoted_string buf lexbuf + } + | "\\\"" + { Buffer.add_char buf '"'; + read_dquoted_string buf lexbuf + } + | '\\' + { Buffer.add_char buf '\\'; + read_dquoted_string buf lexbuf + } + | '"' + { + LITERAL (Buffer.contents buf) + } diff --git a/lib/configuration/expression_parser.messages b/lib/configuration/expression_parser.messages new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/lib/configuration/expression_parser.messages diff --git a/lib/configuration/expression_parser.mly b/lib/configuration/expression_parser.mly new file mode 100644 index 0000000..8341362 --- /dev/null +++ b/lib/configuration/expression_parser.mly @@ -0,0 +1,108 @@ +%token <string>IDENT +%token L_PAREN +%token R_PAREN +%token L_BRACKET R_BRACKET +%token COLUMN DOLLAR +%token DOT +%token <string>LITERAL +%token <string>INTEGER +%token COMA +%token EOF +%token CONCAT_OPERATOR + +%token <Model.Dsl.binary_operator>BINARY_OPERATOR +%token <Model.Dsl.binary_operator>INEQUALITY_OPERATOR +%token <Model.Dsl.binary_operator>EQUALITY_OPERATOR +%token <Model.Dsl.binary_operator>BOOL_OPERATOR + +%start <string list Model.Dsl.t> path_expr + +%right BOOL_OPERATOR +%right INEQUALITY_OPERATOR EQUALITY_OPERATOR +%right CONCAT_OPERATOR BINARY_OPERATOR + +%% + +path_expr: + | expr_(path_, EOF) EOF { $1 } + | EOF { Model.Dsl.Empty } + +path_: + | COLUMN + path = separated_list(DOT, IDENT) + { Model.Dsl.ValuePath path } + | DOLLAR + path = separated_list(DOT, IDENT) + { Model.Dsl.ContentPath path } + +arguments(PATH): + | L_PAREN + expr = separated_list(COMA, expr_(PATH, COMA)) + R_PAREN + { expr } + +group(PATH): + | L_BRACKET + expr = separated_list(COMA, expr_(PATH, COMA)) + R_BRACKET + { expr } + +fixed(PATH): + | d = INTEGER + { Model.Dsl.Integer d } + | l = LITERAL + { + if String.equal String.empty l then + Model.Dsl.Empty + else + Model.Dsl.Literal l + } + +%inline boperator: + | e = BINARY_OPERATOR { e } + | e = INEQUALITY_OPERATOR { e } + | e = EQUALITY_OPERATOR { e } + | e = BOOL_OPERATOR { e } + +(* The expression evaluation receveive in parameters : + 1. the way to build a path, as we have two distinct ways to build them in + the case of externals (the external_key does not allow a table name) + 2. a phantom type telling wich kind of element will end the expression. + This can be EOF for the root expression, or COMA when inside a function. + This prevent merlin to optimize thoses two path, and allow more precise + error messages. *) +expr_(PATH, ENDING_PHANTOM): + | L_PAREN + e = expr_(PATH, R_PAREN) + R_PAREN + { Model.Dsl.Expr e + } + | + p1 = expr_(PATH, ENDING_PHANTOM) + CONCAT_OPERATOR + p2 = expr_(PATH, COMA) + { match p2 with + | Model.Dsl.Function(Concat, args) -> Model.Dsl.Function(Concat, (p1::args)) + | _ -> Model.Dsl.Function(Concat, (p1::p2::[])) + } + | p1 = expr_(PATH, ENDING_PHANTOM) + op = boperator + p2 = expr_(PATH, COMA) + { Model.Dsl.BOperator (op, p1, p2) } + + | p1 = expr_(PATH, ENDING_PHANTOM) + op = EQUALITY_OPERATOR + p2 = group(PATH) + { Model.Dsl.GEquality(op, p1, p2) } + | p = PATH + { p } + | f = fixed(PATH) + { f } + | s = IDENT + args = arguments(PATH) + { Model.Dsl.function_of_name args s } + +opt_arg(PATH, SEP): + | expr = expr_(PATH, COMA) + SEP + { expr } diff --git a/lib/configuration/generate_errors.sh b/lib/configuration/generate_errors.sh new file mode 100755 index 0000000..4c7233d --- /dev/null +++ b/lib/configuration/generate_errors.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +# Generate the error file with the helper messages. This script is required +# when the syntax is modified because menhir will change the state number and +# we need to make it match with the comment in the messages. + +menhir --list-errors *.mly --base expression_parser.mly > all_errors +menhir --merge-errors expression_parser.messages --merge-errors all_errors *.mly --base parser.mly > expression_parser.messages_new diff --git a/lib/configuration/graph_tree.ml b/lib/configuration/graph_tree.ml new file mode 100644 index 0000000..25c9366 --- /dev/null +++ b/lib/configuration/graph_tree.ml @@ -0,0 +1,71 @@ +(** Content graph + + Each content is associated with a vertex, and the links between each content + (through the references fields) are the graph vertexes. + + This module provide function for the topological order traversing, or the + cycle analysis. *) + +module Vertex = struct + type t = Model.Reference.t Model.Content.t + + let compare t1 t2 = String.compare (Model.Content.id t1) (Model.Content.id t2) + let equal t1 t2 = String.equal (Model.Content.id t1) (Model.Content.id t2) + let hash t = Hashtbl.hash (Model.Content.id t) +end + +module Edge = struct + type t = Default | Field of Model.Reference.t Model.Field.t + + let compare e1 e2 = + match (e1, e2) with + | Field f1, Field f2 -> + String.compare (Model.Field.name f1) (Model.Field.name f2) + | Default, Default -> 0 + | _, _ -> Stdlib.compare e1 e2 + + let default = Default +end + +module G = Graph.Imperative.Digraph.ConcreteLabeled (Vertex) (Edge) + +module GV_Printer = Graph.Graphviz.Dot (struct + include G + + let graph_attributes _ = [] + let vertex_name v = Model.Content.id v + let vertex_attributes _ = [] + let default_vertex_attributes _ = [] + let edge_attributes _ = [] + let default_edge_attributes _ = [] + let get_subgraph _ = None +end) + +module Topological = Graph.Topological.Make (G) +module Cycle = Graph.Cycles.Johnson (G) + +type t = G.t + +let create : unit -> t = G.create + +let add_edge : + t -> + Model.Reference.t Model.Content.t -> + Model.Reference.t Model.Field.t -> + Model.Reference.t Model.Content.t -> + unit = + fun t src field dst -> G.add_edge_e t (src, Edge.Field field, dst) + +let add_content : t -> Model.Reference.t Model.Content.t -> unit = G.add_vertex +let pp : Format.formatter -> t -> unit = GV_Printer.fprint_graph + +let fold : (Model.Reference.t Model.Content.t -> 'a -> 'a) -> t -> 'a -> 'a = + Topological.fold + +let iter : (Model.Reference.t Model.Content.t -> unit) -> t -> unit = + Topological.iter + +exception Cycle of Model.Reference.t Model.Content.t list + +let check_cycle : t -> unit = + fun t -> Cycle.iter_cycles (fun vertexes -> raise_notrace (Cycle vertexes)) t diff --git a/lib/configuration/graph_tree.mli b/lib/configuration/graph_tree.mli new file mode 100644 index 0000000..31a8f79 --- /dev/null +++ b/lib/configuration/graph_tree.mli @@ -0,0 +1,25 @@ +type t + +val create : unit -> t + +val add_content : t -> Model.Reference.t Model.Content.t -> unit +(** Add a new content in the tree *) + +val add_edge : + t -> + Model.Reference.t Model.Content.t -> + Model.Reference.t Model.Field.t -> + Model.Reference.t Model.Content.t -> + unit +(** Add a relation between two contents. + + The function does not check if the two contents are actually linked together +*) + +val pp : Format.formatter -> t -> unit +val fold : (Model.Reference.t Model.Content.t -> 'a -> 'a) -> t -> 'a -> 'a +val iter : (Model.Reference.t Model.Content.t -> unit) -> t -> unit + +exception Cycle of Model.Reference.t Model.Content.t list + +val check_cycle : t -> unit diff --git a/lib/configuration/json5.ml b/lib/configuration/json5.ml new file mode 100644 index 0000000..f6e182c --- /dev/null +++ b/lib/configuration/json5.ml @@ -0,0 +1,54 @@ +module Json_decodeable : + Decoders.Decode.Decodeable with type value = Yojson_five.Basic.t = struct + type value = Yojson_five.Basic.t + + let pp fmt json = Yojson.Basic.pretty_print fmt json + + let of_string : string -> (value, string) result = + fun string -> Yojson_five.Basic.from_string string + + let of_file file = Yojson_five.Basic.from_file file + let get_string = function `String value -> Some value | _ -> None + let get_int = function `Int value -> Some value | _ -> None + + let get_float = function + | `Float value -> Some value + | `Int value -> Some (float_of_int value) + | _ -> None + + let get_bool = function `Bool value -> Some value | _ -> None + let get_null = function `Null -> Some () | _ -> None + + let get_list : value -> value list option = function + | `List l -> Some l + | _ -> None + + let get_key_value_pairs : value -> (value * value) list option = function + | `Assoc assoc -> + Some (List.map (fun (key, value) -> (`String key, value)) assoc) + | _ -> None + + let to_list values = `List values +end + +module Decode = Decoders.Decode.Make (Json_decodeable) + +module Json_encodeable = struct + type value = Yojson_five.Basic.t + + let to_string json = Yojson_five.Basic.to_string json + let of_string x = `String x + let of_int x = `Int x + let of_float x = `Float x + let of_bool x = `Bool x + let null = `Null + let of_list xs = `List xs + + let of_key_value_pairs xs = + `Assoc + (xs + |> Decoders.Util.My_list.filter_map (fun (k, v) -> + match k with `String k -> Some (k, v) | _ -> None)) +end + +module Encode = Decoders.Encode.Make (Json_encodeable) diff --git a/lib/configuration/parser.ml b/lib/configuration/parser.ml new file mode 100644 index 0000000..bf962d9 --- /dev/null +++ b/lib/configuration/parser.ml @@ -0,0 +1,118 @@ +open StdLabels + +module ExpressionParser : sig + val of_string : string -> (string list Model.Dsl.t, string) result +end = struct + module MI = Expression_parser.MenhirInterpreter + module E = MenhirLib.ErrorReports + module L = MenhirLib.LexerUtil + + type error = { + message : string; + start_line : int; + start_pos : int; + end_pos : int; + } + + let range_message start_pos end_pos message = + let start_c = start_pos.Lexing.pos_cnum - start_pos.Lexing.pos_bol + and end_c = end_pos.Lexing.pos_cnum - end_pos.Lexing.pos_bol in + { + message; + start_line = start_pos.Lexing.pos_bol; + start_pos = start_c; + end_pos = end_c; + } + + (** Extract the line in error from the whole expression, and print some + characters just under the faulty part *) + let get_line_error : error -> string -> string = + fun error content -> + let sub_text = + try + let end_pos = String.index_from content error.start_line '\n' in + + String.sub content ~pos:error.start_line + ~len:(end_pos - error.start_line) + with Not_found -> + (* There is no new line, extract the ending part *) + let len = String.length content - error.start_line in + String.sub content ~pos:error.start_line ~len + in + (* I’m not sure how to produce it, but the error may be over two lines. + This line is here to prevent the underline to overflow. *) + let stop_pos = min error.end_pos (String.length sub_text) in + let error_length = stop_pos - error.start_pos in + String.concat ~sep:"" + [ + sub_text; + "\n"; + String.make error.start_pos ' '; + String.make error_length '^'; + ] + + let get_parse_error default_position env : error = + match MI.stack env with + | (lazy Nil) -> + range_message default_position.Lexing.lex_start_p + default_position.Lexing.lex_curr_p "Invalid syntax\n" + | (lazy (Cons (MI.Element (state, _, start_pos, end_pos), _))) -> + let message = + try Expression_parser_messages.message (MI.number state) + with Not_found -> + "Invalid syntax (no specific message for this eror)\n" + in + range_message start_pos end_pos message + + let rec _parse lexbuf (checkpoint : 'a Model.Dsl.t MI.checkpoint) = + match checkpoint with + | MI.InputNeeded _env -> + let token = Expression_lexer.token lexbuf in + let startp = lexbuf.lex_start_p and endp = lexbuf.lex_curr_p in + let checkpoint = MI.offer checkpoint (token, startp, endp) in + _parse lexbuf checkpoint + | MI.Shifting _ | MI.AboutToReduce _ -> + let checkpoint = MI.resume checkpoint in + _parse lexbuf checkpoint + | MI.HandlingError _env -> + let err = get_parse_error lexbuf _env in + Error err + | MI.Accepted v -> Ok v + | MI.Rejected -> + let err = + range_message lexbuf.lex_start_p lexbuf.lex_curr_p + "invalid syntax (parser rejected the input)" + in + Error err + + let of_string : string -> ('a Model.Dsl.t, string) result = + fun str_expression -> + let f = Expression_parser.Incremental.path_expr in + try + let lexbuf = Lexing.from_string str_expression in + let init = f lexbuf.lex_curr_p in + match _parse lexbuf init with + | Ok res -> Ok res + | Error e -> + let message = + String.concat ~sep:"\n" + [ e.message; get_line_error e str_expression ] + in + Error message + with + | Expression_lexer.UnclosedQuote { line; content } -> + let message = + Printf.sprintf "Unclosed quote at line %d : \"%s\"" line content + in + Error message + | Model.Dsl.UnknowFunction name -> + let message = + Printf.sprintf + "Unknown function or wrong number of arguments for '%s'" name + in + + Error message + | e -> + let message = Printexc.to_string e in + Error message +end diff --git a/lib/configuration/read_conf.ml b/lib/configuration/read_conf.ml new file mode 100644 index 0000000..f079e4e --- /dev/null +++ b/lib/configuration/read_conf.ml @@ -0,0 +1,158 @@ +open StdLabels + +module Make (S : Decoders.Decode.S) = struct + let ( let* ) = S.( let* ) + let ( and* ) = S.( and* ) + + (** Recursive type declaring a content and the subcontents *) + type declared_content = + | C of + string * (S.value * string) Model.Section.t list * declared_content list + + let rec content_builder : + declared_content -> (S.value * string) Model.Content.t = + fun c -> + let (C (content_id, sections, declared_subcontents)) = c in + let children = List.map declared_subcontents ~f:content_builder in + Model.Content.v content_id sections children + + (** [keep decoder] transform a decoder and keep the initial value with the + decoded value. + + This helps to build custom error message, if we want to report an error + from a different place. *) + let keep : 'a S.decoder -> (S.value * 'a) S.decoder = + fun decoder value -> S.map (fun v -> (value, v)) decoder value + + let textI18n : Model.Field.textI18n S.decoder = S.key_value_pairs S.string + + let dsl : string list Model.Dsl.t S.decoder = + let* content = S.string in + let dsl = Parser.ExpressionParser.of_string content in + Result.map_error Decoders.Error.make dsl |> S.from_result + + let field_type : (S.value * string) Model.Field.field_ex S.decoder = + let text_type : (S.value * string) Model.Field.field_ex S.decoder = + S.and_then + (fun value -> + match String.lowercase_ascii value with + | "text" -> S.succeed (Model.Field.T Text) + | "integer" -> S.succeed (Model.Field.T Integer) + | other -> S.fail other) + S.string + and content : (S.value * string) Model.Field.field_ex S.decoder = + let* content_t = keep @@ S.field "content" S.string + and* multivaluated = S.field_opt_or ~default:false "multivaluated" S.bool + and* constraints = S.field_opt "constraints" dsl in + + let reference = content_t in + + match multivaluated with + | true -> + S.succeed + (Model.Field.T (MultiReference { t = reference; constraints })) + | false -> + S.succeed + (Model.Field.T (MonoReference { t = reference; constraints })) + in + + S.one_of [ ("text", text_type); ("content", content) ] + + let validation : Model.Field.validation S.decoder = + let* rule = S.field "rule" dsl and* message = S.field "message" textI18n in + S.succeed Model.Field.{ rule; message } + + let field : (S.value * string) Model.Field.t S.decoder = + let* name = S.field "name" S.string + and* label = S.field "label" textI18n + and* type' = S.field "type" field_type + and* required = S.field_opt_or ~default:false "required" S.bool + and* placeholder = S.field_opt "placeholder" textI18n + and* validation = + S.field_opt_or ~default:[] "validation" (S.list validation) + and* criteria = S.field_opt "criteria" dsl in + let icon = None in + S.succeed + (Model.Field.create type' label ~required ?placeholder ~validation + ?criteria ?icon name) + + let section : (S.value * string) Model.Section.t S.decoder = + let* label = S.field_opt_or ~default:[] "label" textI18n + and* criteria = S.field_opt "criteria" dsl + and* fields = S.field "field" (S.list field) in + let icon = None in + S.succeed Model.Section.{ label; criteria; fields; icon } + + let identifier : string S.decoder = + let* id = S.string in + if String.equal String.empty id then + S.fail "Expected a non empty identifier" + else if String.contains id '.' then + S.fail "Expected an identifier with only the accepted characters" + else S.succeed id + + let content : (S.value * string) Model.Content.t S.decoder = + (* Build a temporary type without the parent information *) + let* c = + S.fix (fun content_decoder -> + let* id = S.field "id" identifier + and* sections = S.field_opt_or ~default:[] "section" (S.list section) + and* subcontents = + S.field_opt_or ~default:[] "subcontent" (S.list content_decoder) + in + let content = C (id, sections, subcontents) in + S.succeed content) + in + S.succeed (content_builder c) + + let list' : Ast.list' S.decoder = + let* id = S.field "id" S.string and* source = S.field "source" S.string in + S.succeed Ast.{ id; source } + + let t : Ast.setting S.decoder = + (* Register the data type to fetch it later *) + let ty : S.value Type.Id.t = Type.Id.make () in + + let settings = Ast.init () in + + let* contents = S.field "content" (S.list content) + (* Register the lists *) + and* lists = S.field_opt_or ~default:[] "list" (S.list list') in + let settings = List.fold_left lists ~init:settings ~f:Ast.register_list in + + let () = List.iter contents ~f:(Ast.register_content ty settings) in + + (* Ensure the settings are valid in the configuration *) + match Ast.check settings with + | Ok () -> S.succeed settings + | Error (Ast.BrokenLink (ty', context, name) as e) -> ( + match Type.Id.provably_equal ty ty' with + | None -> raise e + | Some Type.Equal -> + let message = + "Undefined target \"" ^ name + ^ "\". Expected existing list or content" + in + S.fail_with (Decoders.Error.make ~context message)) + | Error (Graph_tree.Cycle contents) -> + let content_name = List.map contents ~f:(fun c -> Model.Content.id c) in + let message = + String.concat ~sep:" " + ("Dependency circle found between:" :: content_name) + in + S.fail_with (Decoders.Error.make message) + | Error other -> raise other +end + +module ConfFormat = Json5.Decode +include Make (ConfFormat) + +type error = ConfFormat.error + +let read_conf : string -> (Ast.setting, error) result = + fun file -> ConfFormat.decode_file t file + +let pp_error = ConfFormat.pp_error + +let read_string_conf : string -> (Ast.setting, error) result = + fun file -> ConfFormat.decode_string t file diff --git a/lib/configuration/read_conf.mli b/lib/configuration/read_conf.mli new file mode 100644 index 0000000..3f2dde5 --- /dev/null +++ b/lib/configuration/read_conf.mli @@ -0,0 +1,9 @@ +type error = Json5.Decode.error + +val read_conf : string -> (Ast.setting, error) result +(** Read the configuration from a file *) + +val read_string_conf : string -> (Ast.setting, error) result +(** Read the configuration from a string *) + +val pp_error : Format.formatter -> error -> unit diff --git a/lib/configuration/tests/configuration.t b/lib/configuration/tests/configuration.t new file mode 100644 index 0000000..a732db6 --- /dev/null +++ b/lib/configuration/tests/configuration.t @@ -0,0 +1,77 @@ +The configuration is written in JSON5 format. + +Minimal configuration file with nothing: + + $ tests -configuration <<EOF + > { "content" : [] } + > + > EOF + + +Trailing coma are accepted: + + $ tests -configuration <<EOF + > { "content" : + > [ + > { + > "id": "entity", + > }, + > ] + > } + > + > EOF + +Comments are accepted: + + $ tests -configuration <<EOF + > { "content" : + > [ + > { + > // This is a comment in the file + > "id": "entity", + > } + > ] + > } + > + > EOF + +Cycles between elements are accepted when they are not mandatory to each other + + $ tests -configuration <<EOF + > { + > "content": [ + > { + > "id": "entity", + > "section": [ + > { + > "field": [ + > { + > "name": "user_type", + > "label": {}, + > "type": { + > "content": "user", + > "multivaluated": true + > } + > } + > ] + > } + > ] + > }, + > { + > "id": "user", + > "section": [ + > { + > "field": [ + > { + > "name": "entity", + > "label": {}, + > "type": { "content": "entity", } + > } + > ] + > } + > ] + > } + > ] + > } + + diff --git a/lib/configuration/tests/dune b/lib/configuration/tests/dune new file mode 100644 index 0000000..c5913da --- /dev/null +++ b/lib/configuration/tests/dune @@ -0,0 +1,11 @@ +; Add the test library in the path + +(env + (_ + (binaries %{project_root}/test/tests.exe))) + +; And depend of it. The binary will be available in the +; cram tests under the name "tests" + +(cram + (deps %{bin:tests})) diff --git a/lib/configuration/tests/errors.t b/lib/configuration/tests/errors.t new file mode 100644 index 0000000..6b5584e --- /dev/null +++ b/lib/configuration/tests/errors.t @@ -0,0 +1,119 @@ +Differents invalid configuration. All of them shall report the error properly + +Every content shall have an identifier + + $ tests -configuration <<EOF + > { + > "content": [ + > { + > "key": "", + > } + > ] + > } + > EOF + in field "content": + while decoding a list: + element 0: + Expected an object with an attribute "id", but got { "key": "" } + +The content ID cannot be empty: + + $ tests -configuration <<EOF + > { + > "content": [ + > { + > "id": "", + > } + > ] + > } + > EOF + in field "content": + while decoding a list: + element 0: in field "id": Expected a non empty identifier, but got "" + +The content ID cannot be contains "." (this charater is used internaly): + + $ tests -configuration <<EOF + > { + > "content": [ + > { + > "id": "foo.bar", + > } + > ] + > } + > EOF + in field "content": + while decoding a list: + element 0: + in field "id": + Expected an identifier with only the accepted characters, but got + "foo.bar" + +A reference shall point to an existing content: + + $ tests -configuration <<EOF + > { + > "content": [ + > { + > "id": "content", + > "section": [ + > { + > "field": [ + > { + > "name": "name", + > "label": {}, + > "type": { + > "content": "yes_no" + > } + > } + > ] + > } + > ] + > } + > ] + > } + > EOF + Undefined target "yes_no". Expected existing list or content, but got + { "content": "yes_no" } + +Cycles between required content are not accepted + + $ tests -configuration <<EOF + > { + > "content": [ + > { + > "id": "entity", + > "section": [ + > { + > "field": [ + > { + > "name": "user_type", + > "label": {}, + > "required": true, + > "type": { + > "content": "user", + > "multivaluated": true, + > } + > } + > ] + > } + > ] + > }, + > { + > "id": "user", + > "section": [ + > { + > "field": [ + > { + > "name": "entity", + > "label": {}, + > "required": true, + > "type": { "content": "entity", } + > } + > ] + > } + > ] + > } + > ] + > } + Dependency circle found between: entity user diff --git a/lib/configuration/tests/tree.t b/lib/configuration/tests/tree.t new file mode 100644 index 0000000..b69c830 --- /dev/null +++ b/lib/configuration/tests/tree.t @@ -0,0 +1,161 @@ +This test display the dependency tree between root contents after loading the +configuration. + +Each reference field introduce a dependency between the content having the field +and the content targeted by the field. + + $ tests -configuration -tree <<EOF + > { + > "content": [ + > { + > "id": "entity", + > "section": [ + > { + > "field": [ + > { + > "name": "user_type", + > "label": {}, + > "type": { + > "content": "user_type_list", + > "multivaluated": true + > } + > } + > ] + > } + > ] + > }, + > { + > "id": "user_type_list" + > } + > ] + > } + > EOF + digraph G { + entity; + user_type_list; + + + entity -> user_type_list; + + } + +The tree only contains root elements. Links between subcontent are reported as +link between their respective root content. + + $ tests -configuration -tree <<EOF + > { + > "content": [ + > { + > "id": "entity", + > "subcontent": [ + > { + > "id": "details", + > "section": [ + > { + > "field": [ + > { + > "name": "user_type", + > "label": {}, + > "type": { + > "content": "user_type_list", + > } + > } + > ] + > } + > ] + > } + > ] + > }, + > { + > "id": "user_type_list" + > } + > ] + > } + > EOF + digraph G { + entity; + user_type_list; + + + entity -> user_type_list; + + } + + $ tests -configuration -tree <<EOF + > { + > "content": [ + > { + > "id": "entity", + > "subcontent": [ + > { + > "id": "details", + > "section": [ + > { + > "field": [ + > { + > "name": "reference", + > "label": {}, + > "type": { "content": "user-details", } + > } + > ] + > } + > ] + > } + > ] + > }, + > { + > "id": "user_type_list", + > "subcontent": [ + > { + > "id": "user-details", + > } + > ] + > } + > ] + > } + > EOF + digraph G { + entity; + user_type_list; + + + entity -> user_type_list; + + } + +A content is allowed to loop to itself, directly or indirectly: + + $ tests -configuration -tree <<EOF + > { + > "content": [ + > { + > "id": "entity", + > "subcontent": [ + > { + > "id": "details", + > "section": [ + > { + > "field": [ + > { + > "name": "entities", + > "label": {}, + > "type": { "content": "entity", } + > } + > ] + > } + > ] + > } + > ] + > } + > ] + > } + > EOF + digraph G { + entity; + + + entity -> entity; + + } + + diff --git a/lib/configuration/toml.ml_ b/lib/configuration/toml.ml_ new file mode 100644 index 0000000..3648f2b --- /dev/null +++ b/lib/configuration/toml.ml_ @@ -0,0 +1,133 @@ +open StdLabels + +let rec pp : + ?topLevel:bool -> ?path:string list -> Format.formatter -> Otoml.t -> unit = + fun ?(topLevel = true) ?(path = []) format -> function + | Otoml.TomlString v -> begin + match String.contains v '\n' with + | false -> + Format.pp_print_string format "\""; + Format.pp_print_string format v; + Format.pp_print_string format "\"" + | true -> + Format.pp_print_string format {|"""|}; + Format.pp_print_text format v; + Format.pp_print_string format {|"""|} + end + | Otoml.TomlInteger i -> Format.pp_print_int format i + | Otoml.TomlFloat f -> Format.pp_print_float format f + | Otoml.TomlBoolean b -> Format.pp_print_bool format b + | Otoml.TomlArray l -> begin + match (topLevel, l) with + | _, [] -> Format.pp_print_string format "[]" + | false, _ -> Format.pp_print_string format "..." + | true, l -> + Format.pp_print_string format "["; + Format.pp_print_break format 0 4; + Format.pp_open_vbox format 0; + Format.pp_print_list + ~pp_sep:(fun f () -> + Format.pp_print_string f ","; + Format.pp_print_cut f ()) + pp format l; + Format.pp_close_box format (); + Format.pp_print_cut format (); + Format.pp_print_string format "]" + end + | Otoml.TomlTable elements | Otoml.TomlInlineTable elements -> + pp_table ~path format elements + | Otoml.TomlTableArray t -> Format.pp_print_list pp format t + | Otoml.TomlOffsetDateTime _ | Otoml.TomlLocalDate _ + | Otoml.TomlLocalDateTime _ | Otoml.TomlLocalTime _ -> + () + +and pp_key_values : Format.formatter -> string * Otoml.t -> unit = + fun format (name, value) -> + Format.fprintf format "%s = %a" name (pp ~topLevel:false ~path:[]) value + +and pp_table : + ?path:string list -> Format.formatter -> (string * Otoml.t) list -> unit = + fun ?(path = []) format elements -> + (* Create two lists, one for the subtables, and one for the values. + + As a table is valid until the next table, we then start to print the + preoperties before printintg the subtables inside the element. + *) + let subtables, properties = + List.partition elements ~f:(fun (_, v) -> + match v with Otoml.TomlTable _ -> true | _ -> false) + in + + let () = + match properties with + | [] -> () + | _ -> + let isTopLevel = match path with [] -> true | _ -> false in + if not isTopLevel then begin + let path = List.rev path in + Format.pp_print_cut format (); + Format.fprintf format "[%a]" + (Format.pp_print_list + ~pp_sep:(fun f () -> Format.pp_print_string f ".") + Format.pp_print_string) + path; + Format.pp_print_break format 0 4; + Format.pp_open_vbox format 0 + end; + if isTopLevel then begin + Format.pp_print_list ~pp_sep:Format.pp_print_cut + (fun format v -> + match v with + | key, Otoml.TomlTable elements -> + pp_table ~path:(key :: path) format elements + | other -> pp_key_values format other) + format properties + end + else begin + Format.pp_print_string format "..." + end; + + if not isTopLevel then begin + Format.pp_close_box format () + end; + Format.pp_print_cut format () + in + (* Then go deeper inside each subtable *) + List.iter subtables ~f:(function + | name, Otoml.TomlTable v -> pp_table ~path:(name :: path) format v + | _ -> (* Because of the partition, this should not happen *) ()) + +module Decode = struct + module S = struct + type value = Otoml.t + + let pp : Format.formatter -> value -> unit = + fun formatter v -> + Format.pp_open_vbox formatter 0; + pp formatter v; + Format.pp_close_box formatter () + + let of_string : string -> (value, string) result = + Otoml.Parser.from_string_result + + let of_file : string -> (value, string) result = + Otoml.Parser.from_file_result + + let get_string : value -> string option = Otoml.get_opt Otoml.get_string + let get_int : value -> int option = Otoml.get_opt Otoml.get_integer + let get_float : value -> float option = Otoml.get_opt Otoml.get_float + let get_bool : value -> bool option = Otoml.get_opt Otoml.get_boolean + let get_null : value -> unit option = fun _ -> None + + let get_list : value -> value list option = + Otoml.get_opt @@ Otoml.get_array Fun.id + + let get_key_value_pairs : value -> (value * value) list option = + Otoml.get_opt (fun key -> + Otoml.get_table key |> List.map ~f:(fun (k, v) -> (Otoml.string k, v))) + + let to_list : value list -> value = Otoml.array + end + + include Decoders.Decode.Make (S) +end diff --git a/lib/configuration/toml.mli_ b/lib/configuration/toml.mli_ new file mode 100644 index 0000000..08d30b8 --- /dev/null +++ b/lib/configuration/toml.mli_ @@ -0,0 +1 @@ +module Decode : Decoders.Decode.S with type value = Otoml.t diff --git a/lib/model/content.ml b/lib/model/content.ml new file mode 100644 index 0000000..2760715 --- /dev/null +++ b/lib/model/content.ml @@ -0,0 +1,30 @@ +open StdLabels + +type 'a t = { + id : string; + sections : 'a Section.t list; + subcontents : 'a t list; + parent : 'a t Weak.t; +} + +let v : string -> 'a Section.t list -> 'a t list -> 'a t = + fun id sections subcontents -> + let parent = Weak.create 1 in + let content = { id; sections; subcontents; parent } in + (* Fill the parent for all existing subcontent declared in the type + There is no need to repeat the same for the subcontents as they all are + already created in the same way. + *) + List.iter content.subcontents ~f:(fun v -> Weak.set v.parent 0 (Some content)); + content + +let id t = t.id +let sections t = t.sections +let subcontents t = t.subcontents +let parent t = Weak.get t.parent 0 +let rec root t = match parent t with None -> t | Some t -> root t + +let fields : 'a t -> 'a Field.t Seq.t = + fun t -> + List.to_seq t.sections + |> Seq.flat_map (fun section -> List.to_seq section.Section.fields) diff --git a/lib/model/content.mli b/lib/model/content.mli new file mode 100644 index 0000000..ab8d838 --- /dev/null +++ b/lib/model/content.mli @@ -0,0 +1,18 @@ +type 'a t + +val v : string -> 'a Section.t list -> 'a t list -> 'a t +val id : _ t -> string + +val subcontents : 'a t -> 'a t list +(** Return the direct subcontent *) + +val sections : 'a t -> 'a Section.t list + +val parent : 'a t -> 'a t option +(** Get the parent type for an element, if such exists *) + +val root : 'a t -> 'a t +(** Return the root element, which is the content without any parent *) + +val fields : 'a t -> 'a Field.t Seq.t +(** Iterate over the fields in the content *) diff --git a/lib/model/dsl.ml b/lib/model/dsl.ml new file mode 100644 index 0000000..0f873f3 --- /dev/null +++ b/lib/model/dsl.ml @@ -0,0 +1,135 @@ +open StdLabels + +exception UnknowFunction of string + +type 'a t = + | Empty + | Expr of 'a t + | Literal of string + | Integer of string + | ValuePath of 'a + | ContentPath of 'a + | Nvl of 'a t list + | Join of string * 'a t list + | BOperator of binary_operator * 'a t * 'a t + | GEquality of binary_operator * 'a t * 'a t list + | Function of funct * 'a t list +[@@deriving show, eq, ord] + +and binary_operator = + | Equal + | Different + | Add + | Minus + | Division + | LT + | GT + | LTE + | GTE + | And + | Or +[@@deriving ord] + +and funct = + | Cmp + | Trim + | Ucase + | If + | Concat + | Matches + | Substring + | Length + | Uniq + +let name_of_function : funct -> string = function + | Ucase -> "ucase" + | Trim -> "trim" + | Cmp -> "cmp" + | If -> "if" + | Concat -> "concat" + | Matches -> "matches" + | Substring -> "substring" + | Length -> "length" + | Uniq -> "uniq" + +let function_of_name : 'a t list -> string -> 'a t = + fun param f -> + match (String.lowercase_ascii f, param) with + | "nvl", _ -> Nvl param + | "join", Literal sep :: tl -> Join (sep, tl) + | "join", Empty :: tl -> Join ("", tl) + (* Branch function *) + | "if", [ _; _; _ ] -> Function (If, param) + (* String functions *) + | "matches", _ -> Function (Matches, param) + | "substring", _ -> Function (Substring, param) + | "length", [ _ ] -> Function (Length, param) + | "ucase", [ _ ] -> Function (Ucase, param) + | "trim", [ _ ] -> Function (Trim, param) + | "concat", _ -> Function (Concat, param) + | "uniq", [ _ ] -> Function (Uniq, param) + | _ -> + (*Function (other, param)*) + raise (UnknowFunction f) + +let name_of_operator = function + | Equal -> "=" + | Different -> "<>" + | Add -> "+" + | Minus -> "-" + | Division -> "/" + | LT -> "<" + | GT -> ">" + | LTE -> "<=" + | GTE -> ">=" + | And -> " and " + | Or -> " or " + +let rec cmp : ('a -> 'a -> int) -> 'a t -> 'a t -> int = + fun f e1 e2 -> + match (e1, e2) with + | Empty, Empty -> 0 + | Literal l1, Literal l2 -> String.compare l1 l2 + | Integer l1, Integer l2 -> String.compare l1 l2 + | ValuePath p1, ValuePath p2 -> f p1 p2 + | ContentPath p1, ContentPath p2 -> f p1 p2 + | BOperator (n1, arg11, arg12), BOperator (n2, arg21, arg22) -> ( + match compare_binary_operator n1 n2 with + | 0 -> ( + match cmp f arg11 arg21 with 0 -> cmp f arg12 arg22 | other -> other) + | other -> other) + (* Any other case *) + | other1, other2 -> Stdlib.compare other1 other2 + +let fold_values : f:('b -> 'a -> 'b) -> init:'b -> 'a t -> 'b = + fun ~f ~init expression -> + let rec _f acc = function + | Empty | Literal _ | Integer _ -> acc + | Expr e -> _f acc e + | ValuePath p -> f acc p + | ContentPath p -> f acc p + | Function (_, pp) | Nvl pp | Join (_, pp) -> + List.fold_left ~f:(fun acc a -> _f acc a) ~init:acc pp + | BOperator (_, arg1, arg2) -> _f (_f acc arg1) arg2 + | GEquality (_, arg1, arg2) -> + let eval1 = List.fold_left ~f:(fun acc a -> _f acc a) ~init:acc arg2 in + _f eval1 arg1 + in + _f init expression + +let map : type a b. f:(a -> b) -> a t -> b t = + fun ~f expression -> + let rec map = function + | Expr e -> Expr (map e) + | Empty -> Empty + | Literal s -> Literal s + | Integer i -> Integer i + | ValuePath p -> ValuePath (f p) + | ContentPath p -> ContentPath (f p) + | Function (name, pp) -> Function (name, List.map ~f:map pp) + | Nvl pp -> Nvl (List.map ~f:map pp) + | Join (sep, pp) -> Join (sep, List.map ~f:map pp) + | BOperator (n, arg1, arg2) -> BOperator (n, map arg1, map arg2) + | GEquality (n, arg1, args) -> GEquality (n, map arg1, List.map ~f:map args) + in + map expression diff --git a/lib/model/dune b/lib/model/dune new file mode 100644 index 0000000..12dfa56 --- /dev/null +++ b/lib/model/dune @@ -0,0 +1,5 @@ +(library + (name model) + (libraries) + (preprocess + (pps ppx_deriving.ord ppx_deriving.show ppx_deriving.eq))) diff --git a/lib/model/field.ml b/lib/model/field.ml new file mode 100644 index 0000000..8ea38fd --- /dev/null +++ b/lib/model/field.ml @@ -0,0 +1,55 @@ +type textI18n = (string * string) list +(** A label is just an association list*) + +type validation = { rule : string list Dsl.t; message : textI18n } +type 't field_ex = T : ('a, 't) Typ.t -> 't field_ex + +type 't t = { + name : string; (** The internal name *) + label : textI18n; + placeholder : textI18n option; + icon : unit option; + type' : 't field_ex; + required : bool; + validation : validation list; + criteria : string list Dsl.t option; + (** Display the field when the criteria is valid *) +} + +let name : 'ref t -> string = fun t -> t.name +let label : 'ref t -> textI18n = fun t -> t.label +let placeholder : 'ref t -> textI18n option = fun t -> t.placeholder +let icon : 'ref t -> unit option = fun t -> t.icon +let type_ : 'ref t -> 'ref field_ex = fun t -> t.type' +let required : 'ref t -> bool = fun t -> t.required +let validation : 'ref t -> validation list = fun t -> t.validation +let criteria : 'ref t -> string list Dsl.t option = fun t -> t.criteria + +let create : + 't field_ex -> + textI18n -> + ?placeholder:textI18n -> + ?icon:unit -> + ?required:bool -> + ?validation:validation list -> + ?criteria:string list Dsl.t -> + string -> + 't t = + fun type_ label ?placeholder ?icon ?(required = false) ?(validation = []) + ?criteria name -> + { + name; + label; + placeholder; + icon; + type' = type_; + required; + validation; + criteria; + } + +let map : ('a -> 'b) -> 'a t -> 'b t = + fun f t -> + let (T field_type) = t.type' in + let new_type = T (Typ.map f field_type) in + { t with type' = new_type } diff --git a/lib/model/field.mli b/lib/model/field.mli new file mode 100644 index 0000000..a121871 --- /dev/null +++ b/lib/model/field.mli @@ -0,0 +1,35 @@ +type textI18n = (string * string) list +(** A label is just an association list*) + +type validation = { rule : string list Dsl.t; message : textI18n } +type 't field_ex = T : ('a, 't) Typ.t -> 't field_ex + +type 'ref t +(** Description of a field *) + +val create : + 'ref field_ex -> + textI18n -> + ?placeholder:textI18n -> + ?icon:unit -> + ?required:bool -> + ?validation:validation list -> + ?criteria:string list Dsl.t -> + string -> + 'ref t + +val name : _ t -> string +(** Name (identifier) for the field*) + +val label : _ t -> textI18n +val placeholder : _ t -> textI18n option +val icon : _ t -> unit option +val type_ : 'ref t -> 'ref field_ex +val required : _ t -> bool +val validation : _ t -> validation list +val criteria : _ t -> string list Dsl.t option + +val map : ('a -> 'b) -> 'a t -> 'b t +(** Change the type of reference in the field. Used when loading the + configuration to switch between fields referencing string (the name given in + the configuration) and actual contents *) diff --git a/lib/model/reference.ml b/lib/model/reference.ml new file mode 100644 index 0000000..496eb9d --- /dev/null +++ b/lib/model/reference.ml @@ -0,0 +1,4 @@ +type t = T : t Content.t Lazy.t -> t [@@unboxed] + +let v : (unit -> t Content.t) -> t = fun f -> T (lazy (f ())) +let get : t -> t Content.t = fun (T target) -> Lazy.force target diff --git a/lib/model/reference.mli b/lib/model/reference.mli new file mode 100644 index 0000000..7a9d135 --- /dev/null +++ b/lib/model/reference.mli @@ -0,0 +1,4 @@ +type t + +val v : (unit -> t Content.t) -> t +val get : t -> t Content.t diff --git a/lib/model/section.ml b/lib/model/section.ml new file mode 100644 index 0000000..9e871e3 --- /dev/null +++ b/lib/model/section.ml @@ -0,0 +1,7 @@ +type 'a t = { + label : Field.textI18n; + icon : unit option; + criteria : string list Dsl.t option; + (** Display the section when the criteria is valid*) + fields : 'a Field.t list; +} diff --git a/lib/model/tests/dune b/lib/model/tests/dune new file mode 100644 index 0000000..c5913da --- /dev/null +++ b/lib/model/tests/dune @@ -0,0 +1,11 @@ +; Add the test library in the path + +(env + (_ + (binaries %{project_root}/test/tests.exe))) + +; And depend of it. The binary will be available in the +; cram tests under the name "tests" + +(cram + (deps %{bin:tests})) diff --git a/lib/model/tests/parent.t b/lib/model/tests/parent.t new file mode 100644 index 0000000..8e77578 --- /dev/null +++ b/lib/model/tests/parent.t @@ -0,0 +1,91 @@ + +A root content does not have any parent + + $ tests -parent "entity" <<EOF + > { + > "content": [ + > { + > "id": "entity" + > } + > ] + > } + > EOF + [No parent] + +A root content is the root of itself + + $ tests -parent -root "entity" <<EOF + > { + > "content": [ + > { + > "id": "entity" + > } + > ] + > } + > EOF + "entity" + +The parent of a subcontent shall never been None, and will target the container + + $ tests -parent "details" <<EOF + > { + > "content": [ + > { + > "id": "entity", + > "subcontent": [ + > { + > "id": "details" + > } + > ] + > } + > ] + > } + > EOF + "entity" + +The parent element can be a subcontent itself + + $ tests -parent "level2" <<EOF + > { + > "content": [ + > { + > "id": "entity", + > "subcontent": [ + > { + > "id": "level1", + > "subcontent": [ + > { + > "id": "level2" + > } + > ] + > } + > ] + > } + > ] + > } + > EOF + "level1" + +The root element is the top content + + $ tests -parent -root "level2" <<EOF + > { + > "content": [ + > { + > "id": "entity", + > "subcontent": [ + > { + > "id": "level1", + > "subcontent": [ + > { + > "id": "level2" + > } + > ] + > } + > ] + > } + > ] + > } + > EOF + "entity" + diff --git a/lib/model/typ.ml b/lib/model/typ.ml new file mode 100644 index 0000000..2770885 --- /dev/null +++ b/lib/model/typ.ml @@ -0,0 +1,62 @@ +type 'a reference = { + t : 'a; (** The content targeted by this field. *) + constraints : string list Dsl.t option; + (** Retrict only the values to thoses ones *) +} + +(** Each of the field types available in the application. + + - The first type parameter match the DB data for the content. + - The second is the type of the target in references fields *) +type ('db, 't) t = + | Text : (string option, 't) t + | Integer : (int64 option, 't) t + | MonoReference : 't reference -> (int64 option, 't) t + | MultiReference : 't reference -> (int64 option, 't) t + (** Multireferences properties allows only one kind of content. + + They are not encoded in the content table but in another table *) + +let map : type a. ('ref1 -> 'ref2) -> (a, 'ref1) t -> (a, 'ref2) t = + fun f -> function + | Text -> Text + | Integer -> Integer + | MonoReference v -> MonoReference { v with t = f v.t } + | MultiReference v -> MultiReference { v with t = f v.t } + +(** Get the value to insert in the database when the field is empty *) +let default_value : type a. (a, _) t -> a = function + | Integer -> None + | Text -> None + | MultiReference _ -> None + | MonoReference _ -> None + +let eq : type a b c. (a, c) t -> (b, c) t -> (a, b) Type.eq option = + fun t1 t2 -> + match (t1, t2) with + | MultiReference _, MultiReference _ -> Some Type.Equal + | MonoReference _, MonoReference _ -> Some Type.Equal + | Integer, Integer -> Some Type.Equal + | Text, Text -> Some Type.Equal + | _ -> None + +(** Represent the value in the database for a given field. + +Example for inserting data +[ + (* Function providing a value for each field to insert in the database *) + + let f : string -> Model.Reference.t Model.Field.value = function + | "siret" -> V (Model.Field.Text, Some "siret") + | "name" -> V (Model.Field.Text, Some "name") + | _ -> None + + let* id = Query.insert db entity_content f in +] + +*) +type 't value = + | V : ('a option, 't) t * 'a -> 't value + (** V is the value for the field. The field type is also reported in order + to give the compiler the nature of the data *) + | None (** None tell the field is empty in the database *) diff --git a/lib/query/common.ml b/lib/query/common.ml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/lib/query/common.ml diff --git a/lib/query/create.ml b/lib/query/create.ml new file mode 100644 index 0000000..ec1fb21 --- /dev/null +++ b/lib/query/create.ml @@ -0,0 +1,251 @@ +open StdLabels +module Ast = Configuration.Ast + +let ( |>::? ) : 'a list -> 'a option -> 'a list = + fun lst opt -> match opt with None -> lst | Some v -> v :: lst + +let ( let* ) = Lwt.bind + +let get_field_query : _ Model.Field.t -> string option = + fun field -> + let ty = + match Model.Field.type_ field with + | T (MultiReference _) -> None + | T Integer -> Some "INTEGER" + | T (MonoReference _) -> Some "INTEGER" + | T Text -> Some "VARCHAR" + in + Option.map + (fun t -> + String.concat ~sep:" " [ "\"" ^ Model.Field.name field ^ "\""; t ]) + ty + +type foreign = { + src_table : string; + src_column : string; + dst_table : string; + dst_column : string; +} +(** Foreign key between a column referencing a content and the referenced value +*) + +(* +ALTER TABLE question +ADD FOREIGN KEY (best_a_id) +REFERENCES answer(a_id); +*) + +let get_foreign_statement : string -> _ Model.Content.t -> string = + fun property content -> + "FOREIGN KEY(\"" ^ property ^ "\") REFERENCES " ^ Model.Content.id content + ^ "(\"id\")" + +(** Create the dedicated table required for multivaluated fields *) +let create_external_reference_table : + Caqti_lwt.connection -> + Model.Reference.t Model.Content.t -> + foreign list -> + Model.Reference.t Model.Field.t -> + foreign list Lwt.t = + fun db content acc field -> + match Model.Field.type_ field with + | Model.Field.(T Integer) + | Model.Field.(T Text) + | Model.Field.(T (MonoReference _)) -> + Lwt.return acc + | Model.Field.(T (MultiReference reference)) -> + let buff = Buffer.create 16 in + let format = Format.formatter_of_buffer buff in + let target = Model.Reference.get reference.Model.Typ.t in + let fields = + [ + "\"id\" INTEGER PRIMARY KEY"; + "\"parent\" INTEGER NOT NULL"; + "\"target\" INTEGER NOT NULL"; + get_foreign_statement "parent" content; + get_foreign_statement "target" target; + ] + in + let () = + Format.fprintf format "CREATE TABLE \"%s.%s\"@; @[@[<v>( %a@] )@]" + (Model.Content.id content) (Model.Field.name field) + (Format.pp_print_list + ~pp_sep:(fun f () -> + Format.pp_print_break f 0 0; + Format.pp_print_string f ", ") + Format.pp_print_string) + fields + in + Format.pp_print_flush format (); + let request_str = Buffer.contents buff in + let request = + Caqti_request.Infix.( + (Caqti_type.unit ->. Caqti_type.unit) ~oneshot:true) + request_str + in + let module Db = (val db) in + let* result = Db.exec request () in + let* () = Caqti_lwt.or_fail result in + Lwt.return acc + +(** Generate the create table for a content *) +let rec create_table : + Caqti_lwt.connection -> + foreign list * Model.Reference.t Model.Content.t list -> + _ Model.Content.t -> + (foreign list * Model.Reference.t Model.Content.t list) Lwt.t = + fun db (alter_queries, created) content -> + (* The foreign keys are added at the end of the query, and need to be + defined first *) + let alter_queries = + match Model.Content.parent content with + | None -> alter_queries + | Some p -> + { + src_table = Model.Content.id content; + src_column = "parent"; + dst_table = Model.Content.id p; + dst_column = "id"; + } + :: alter_queries + in + + let content_fields = List.of_seq (Model.Content.fields content) in + + (* Collect all the target contents already created in the database, and add + the foreign key constraint *) + let init_foreign = + match Model.Content.parent content with + | Some parent -> [ get_foreign_statement "parent" parent ] + | None -> [] + in + let foreign, alter_queries = + List.fold_left content_fields ~init:(init_foreign, alter_queries) + ~f:(fun (foreign, alter_queries) field -> + match Model.Field.type_ field with + | T (MonoReference reference) -> ( + let dst = Model.Reference.get reference.Model.Typ.t in + let column = Model.Field.name field in + match List.mem ~set:created dst with + | true -> + let foreign = get_foreign_statement column dst :: foreign in + (foreign, alter_queries) + | false -> + (* If the table does not exists yet, add the constraint in the + ALTER TABLE list. + + This list will be processed later, once all the table are + created *) + let alter_queries = + { + src_table = Model.Content.id content; + src_column = column; + dst_table = Model.Content.id dst; + dst_column = "id"; + } + :: alter_queries + in + (foreign, alter_queries)) + | _ -> (foreign, alter_queries)) + in + + let fields = + "\"id\" INTEGER PRIMARY KEY" + (* Identify each field in each of the sections *) + :: List.fold_left content_fields ~init:foreign ~f:(fun acc field -> + match get_field_query field with None -> acc | Some q -> q :: acc) + |>::? Option.map + (* We don’t care about the parent, we just want to + know there is one in order to add the column *) + (fun _ -> "\"parent\" INTEGER NOT NULL") + (Model.Content.parent content) + in + let buff = Buffer.create 128 in + let format = Format.formatter_of_buffer buff in + let () = + Format.fprintf format "CREATE TABLE \"%s\"@; @[@[<v>( %a@] )@]" + (Model.Content.id content) + (Format.pp_print_list + ~pp_sep:(fun f () -> + Format.pp_print_break f 0 0; + Format.pp_print_string f ", ") + Format.pp_print_string) + fields + in + Format.pp_print_flush format (); + let request_str = Buffer.contents buff in + let request = + Caqti_request.Infix.((Caqti_type.unit ->. Caqti_type.unit) ~oneshot:true) + request_str + in + let module Db = (val db) in + let* result = Db.exec request () in + let* () = Caqti_lwt.or_fail result in + (* Create the externals tables holding the multivaluated fields *) + let* acc = + Lwt_list.fold_left_s + (create_external_reference_table db content) + alter_queries content_fields + in + let created = content :: created in + (* Create the subcontent *) + let* acc = + Lwt_list.fold_left_s (create_table db) (acc, created) + (Model.Content.subcontents content) + in + Lwt.return acc + +(** Modify the table and add the foreign key in case of cyclic references *) +let add_foreign_statement : Caqti_lwt.connection -> foreign list -> unit Lwt.t = + fun db foreigns -> + let request_str = + "ALTER TABLE ? ADD CONSTRAINT FOREIGN KEY(?) REFERENCES ?(?)" + in + let request = + Caqti_request.Infix.( + (Caqti_type.(t4 string string string string) ->. Caqti_type.unit) + ~oneshot:true) + request_str + in + let module Db = (val db) in + let* () = + Lwt_list.iter_s + (fun foreign -> + let* result = + Db.exec request + ( foreign.src_table, + foreign.src_column, + foreign.dst_table, + foreign.dst_column ) + in + Caqti_lwt.or_fail result) + foreigns + in + Lwt.return_unit + +let create : Caqti_lwt.connection -> Configuration.Ast.setting -> unit Lwt.t = + fun db conf -> + let module Db = (val db) in + let contents = Configuration.Ast.root_contents conf in + let* foreign, _ = + Lwt_list.fold_left_s + (fun acc content -> + match Model.Content.parent content with + | Some _ -> + (* Ignore the subcontents, they will be created just after the + parent *) + Lwt.return acc + | None -> create_table db acc content) + ([], []) contents + in + match Caqti_driver_info.dialect_tag Db.driver_info with + | `Sqlite -> + (* There is no way to add a foreign key to an existing table in sqlite, + so we just stop the table creation here. + + https://www.sqlite.org/foreignkeys.html#fk_schemacommands + https://www.sqlite.org/omitted.html + *) + ignore foreign; + Lwt.return_unit + | `Pgsql | `Mysql | _ -> add_foreign_statement db foreign diff --git a/lib/query/dune b/lib/query/dune new file mode 100644 index 0000000..b9a862a --- /dev/null +++ b/lib/query/dune @@ -0,0 +1,11 @@ +(library + (name query) + (libraries + caqti + caqti-lwt + caqti-lwt.unix + lwt.unix + lwt + uri + model + configuration)) diff --git a/lib/query/encoder.ml b/lib/query/encoder.ml new file mode 100644 index 0000000..624931a --- /dev/null +++ b/lib/query/encoder.ml @@ -0,0 +1,268 @@ +(** Encode the values in order to build a request All of the modules are used to + build query, either when generating placeholders in the query, giving values + to the request, or column name. *) + +open StdLabels +open Intf + +module Map (T : Encoder) = struct + let rec f : type a. a tuple -> a T.t = + fun t -> + match t with + | T0 -> T.unit + | T1 t1 -> T.f t1 + | T2 (t1, t2) -> T.t2 (T.f t1) (T.f t2) + | T3 (t1, t2, t3) -> T.t3 (T.f t1) (T.f t2) (T.f t3) + | T4 (t1, t2, t3, t4) -> T.t4 (T.f t1) (T.f t2) (T.f t3) (T.f t4) + | T5 (t1, t2, t3, t4, t5) -> + T.t5 (T.f t1) (T.f t2) (T.f t3) (T.f t4) (T.f t5) + | T6 (t1, t2, t3, t4, t5, t6) -> + T.t6 (T.f t1) (T.f t2) (T.f t3) (T.f t4) (T.f t5) (T.f t6) + | T7 (t1, t2, t3, t4, t5, t6, t7) -> + T.t7 (T.f t1) (T.f t2) (T.f t3) (T.f t4) (T.f t5) (T.f t6) (T.f t7) + | T8 (t1, t2, t3, t4, t5, t6, t7, t8) -> + T.t8 (T.f t1) (T.f t2) (T.f t3) (T.f t4) (T.f t5) (T.f t6) (T.f t7) + (T.f t8) + | T9 (t1, t2, t3, t4, t5, t6, t7, t8, t9) -> + T.t9 (T.f t1) (T.f t2) (T.f t3) (T.f t4) (T.f t5) (T.f t6) (T.f t7) + (T.f t8) (T.f t9) + | T10 (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10) -> + T.t10 (T.f t1) (T.f t2) (T.f t3) (T.f t4) (T.f t5) (T.f t6) (T.f t7) + (T.f t8) (T.f t9) (T.f t10) + | T_N (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t_n) -> + let tl = f t_n in + T.t_n (T.f t1) (T.f t2) (T.f t3) (T.f t4) (T.f t5) (T.f t6) (T.f t7) + (T.f t8) (T.f t9) (T.f t10) tl +end + +module Fold (T : sig + type 'a t + + val f : 'a t -> 'any data -> 'a t +end) = +struct + let rec f : type a. 'acc -> a tuple -> 'acc = + fun init t -> + match t with + | T0 -> init + | T1 t1 -> T.f init t1 + | T2 (t1, t2) -> T.f (T.f init t1) t2 + | T3 (t1, t2, t3) -> T.f (T.f (T.f init t1) t2) t3 + | T4 (t1, t2, t3, t4) -> T.f (T.f (T.f (T.f init t1) t2) t3) t4 + | T5 (t1, t2, t3, t4, t5) -> T.f (T.f (T.f (T.f (T.f init t1) t2) t3) t4) t5 + | T6 (t1, t2, t3, t4, t5, t6) -> + T.f (T.f (T.f (T.f (T.f (T.f init t1) t2) t3) t4) t5) t6 + | T7 (t1, t2, t3, t4, t5, t6, t7) -> + T.f (T.f (T.f (T.f (T.f (T.f (T.f init t1) t2) t3) t4) t5) t6) t7 + | T8 (t1, t2, t3, t4, t5, t6, t7, t8) -> + T.f + (T.f (T.f (T.f (T.f (T.f (T.f (T.f init t1) t2) t3) t4) t5) t6) t7) + t8 + | T9 (t1, t2, t3, t4, t5, t6, t7, t8, t9) -> + T.f + (T.f + (T.f (T.f (T.f (T.f (T.f (T.f (T.f init t1) t2) t3) t4) t5) t6) t7) + t8) + t9 + | T10 (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10) -> + T.f + (T.f + (T.f + (T.f + (T.f (T.f (T.f (T.f (T.f (T.f init t1) t2) t3) t4) t5) t6) + t7) + t8) + t9) + t10 + | T_N (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, tl) -> + let init' = + T.f + (T.f + (T.f + (T.f + (T.f (T.f (T.f (T.f (T.f (T.f init t1) t2) t3) t4) t5) t6) + t7) + t8) + t9) + t10 + in + f init' tl +end + +let rec list_to_tup : f:('a -> t_type) -> 'a list -> t = + fun ~f lst -> + match lst with + | [] -> T T0 + | elem_0 :: [] -> + let (TT v0) = f elem_0 in + T (T1 v0) + | [ elem_0; elem_1 ] -> + let (TT v0) = f elem_0 in + let (TT v1) = f elem_1 in + T (T2 (v0, v1)) + | [ elem_0; elem_1; elem_2 ] -> + let (TT v0) = f elem_0 in + let (TT v1) = f elem_1 in + let (TT v2) = f elem_2 in + T (T3 (v0, v1, v2)) + | [ elem_0; elem_1; elem_2; elem_3 ] -> + let (TT v0) = f elem_0 in + let (TT v1) = f elem_1 in + let (TT v2) = f elem_2 in + let (TT v3) = f elem_3 in + T (T4 (v0, v1, v2, v3)) + | [ elem_0; elem_1; elem_2; elem_3; elem_4 ] -> + let (TT v0) = f elem_0 in + let (TT v1) = f elem_1 in + let (TT v2) = f elem_2 in + let (TT v3) = f elem_3 in + let (TT v4) = f elem_4 in + T (T5 (v0, v1, v2, v3, v4)) + | [ elem_0; elem_1; elem_2; elem_3; elem_4; elem_5 ] -> + let (TT v0) = f elem_0 in + let (TT v1) = f elem_1 in + let (TT v2) = f elem_2 in + let (TT v3) = f elem_3 in + let (TT v4) = f elem_4 in + let (TT v5) = f elem_5 in + T (T6 (v0, v1, v2, v3, v4, v5)) + | [ elem_0; elem_1; elem_2; elem_3; elem_4; elem_5; elem_6 ] -> + let (TT v0) = f elem_0 in + let (TT v1) = f elem_1 in + let (TT v2) = f elem_2 in + let (TT v3) = f elem_3 in + let (TT v4) = f elem_4 in + let (TT v5) = f elem_5 in + let (TT v6) = f elem_6 in + T (T7 (v0, v1, v2, v3, v4, v5, v6)) + | [ elem_0; elem_1; elem_2; elem_3; elem_4; elem_5; elem_6; elem_7 ] -> + let (TT v0) = f elem_0 in + let (TT v1) = f elem_1 in + let (TT v2) = f elem_2 in + let (TT v3) = f elem_3 in + let (TT v4) = f elem_4 in + let (TT v5) = f elem_5 in + let (TT v6) = f elem_6 in + let (TT v7) = f elem_7 in + T (T8 (v0, v1, v2, v3, v4, v5, v6, v7)) + | [ elem_0; elem_1; elem_2; elem_3; elem_4; elem_5; elem_6; elem_7; elem_8 ] + -> + let (TT v0) = f elem_0 in + let (TT v1) = f elem_1 in + let (TT v2) = f elem_2 in + let (TT v3) = f elem_3 in + let (TT v4) = f elem_4 in + let (TT v5) = f elem_5 in + let (TT v6) = f elem_6 in + let (TT v7) = f elem_7 in + let (TT v8) = f elem_8 in + T (T9 (v0, v1, v2, v3, v4, v5, v6, v7, v8)) + | [ + elem_0; + elem_1; + elem_2; + elem_3; + elem_4; + elem_5; + elem_6; + elem_7; + elem_8; + elem_9; + ] -> + let (TT v0) = f elem_0 in + let (TT v1) = f elem_1 in + let (TT v2) = f elem_2 in + let (TT v3) = f elem_3 in + let (TT v4) = f elem_4 in + let (TT v5) = f elem_5 in + let (TT v6) = f elem_6 in + let (TT v7) = f elem_7 in + let (TT v8) = f elem_8 in + let (TT v9) = f elem_9 in + T (T10 (v0, v1, v2, v3, v4, v5, v6, v7, v8, v9)) + | elem_0 :: elem_1 :: elem_2 :: elem_3 :: elem_4 :: elem_5 :: elem_6 :: elem_7 + :: elem_8 :: elem_9 :: tl -> + (* In this pattern, we are sure tl is not empty, otherwise we would have + matched the previous case *) + let (TT v0) = f elem_0 in + let (TT v1) = f elem_1 in + let (TT v2) = f elem_2 in + let (TT v3) = f elem_3 in + let (TT v4) = f elem_4 in + let (TT v5) = f elem_5 in + let (TT v6) = f elem_6 in + let (TT v7) = f elem_7 in + let (TT v8) = f elem_8 in + let (TT v9) = f elem_9 in + let (T tl) = list_to_tup ~f tl in + T (T_N (v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, tl)) + +module CaqtiRequest = Map (struct + include Caqti_type + + let t_n = Caqti_type.t11 + + let f : type a. a data -> a Caqti_type.t = function + | { content = Text; _ } -> Caqti_type.option @@ Caqti_type.string + | { content = Integer; _ } -> Caqti_type.option @@ Caqti_type.int64 + | { content = MultiReference _; _ } -> Caqti_type.option @@ Caqti_type.int64 + | { content = MonoReference _; _ } -> Caqti_type.option @@ Caqti_type.int64 +end) + +module DefaultEncoder = struct + let unit = () + let t2 a b = (a, b) + let t3 a b c = (a, b, c) + let t4 a b c d = (a, b, c, d) + let t5 a b c d e = (a, b, c, d, e) + let t6 a b c d e f = (a, b, c, d, e, f) + let t7 a b c d e f g = (a, b, c, d, e, f, g) + let t8 a b c d e f g h = (a, b, c, d, e, f, g, h) + let t9 a b c d e f g h i = (a, b, c, d, e, f, g, h, i) + let t10 a b c d e f g h i j = (a, b, c, d, e, f, g, h, i, j) + let t_n a b c d e f g h i j k = (a, b, c, d, e, f, g, h, i, j, k) +end + +module ConcatParam = struct + let sep = "," + let unit = "" + let t2 a b = String.concat ~sep [ a; b ] + let t3 a b c = String.concat ~sep [ a; b; c ] + let t4 a b c d = String.concat ~sep [ a; b; c; d ] + let t5 a b c d e = String.concat ~sep [ a; b; c; d; e ] + let t6 a b c d e f = String.concat ~sep [ a; b; c; d; e; f ] + let t7 a b c d e f g = String.concat ~sep [ a; b; c; d; e; f; g ] + let t8 a b c d e f g h = String.concat ~sep [ a; b; c; d; e; f; g; h ] + let t9 a b c d e f g h i = String.concat ~sep [ a; b; c; d; e; f; g; h; i ] + + let t10 a b c d e f g h i j = + String.concat ~sep [ a; b; c; d; e; f; g; h; i; j ] + + let t_n a b c d e f g h i j k = + String.concat ~sep [ a; b; c; d; e; f; g; h; i; j; k ] +end + +module EncodeInsert = Map (struct + type 'a t = string + + let f : type a. a data -> a t = function + | { content = Text; _ } -> "?" + | { content = Integer; _ } -> "?" + | { content = MonoReference _; _ } -> "?" + | { content = MultiReference _; _ } -> + failwith "Cannot encode multireference field" + + include ConcatParam +end) + +module InsertTableName = Map (struct + type 'a t = string + + let f : type a. a data -> a t = function + | { name = column; content = Text; _ } -> column + | { name = column; content = Integer; _ } -> column + | { name = column; content = MultiReference _; _ } -> column + | { name = column; content = MonoReference _; _ } -> column + + include ConcatParam +end) diff --git a/lib/query/insert.ml b/lib/query/insert.ml new file mode 100644 index 0000000..39c32d0 --- /dev/null +++ b/lib/query/insert.ml @@ -0,0 +1,146 @@ +(** Generate the insert queries for the different database *) + +exception TypeMismatch +(** Exception raised when the given type does not match the value *) + +(** Transform the list of fields from the model into a tuple with the type of + each field associated with *) +let collect_fields : + ?init_fields:Model.Reference.t Model.Field.t list -> + ?filter:('a Model.Field.t -> bool) -> + 'a Model.Content.t -> + Intf.t = + fun ?(init_fields = []) ?filter content -> + let field_seq = + match filter with + | None -> Model.Content.fields content + | Some f -> Model.Content.fields content |> Seq.filter f + in + + let fields = init_fields @ List.of_seq field_seq in + + Encoder.list_to_tup fields ~f:(fun field -> + let name = Model.Field.name field in + let (Model.Field.T content) = Model.Field.type_ field in + TT { name; content }) + +(** Insert a row. This syntax use RETURNING ID to get the value we just inserted +*) +let insert_returning : + Caqti_lwt.connection -> + Model.Reference.t Model.Content.t -> + (string -> Model.Reference.t Model.Typ.value) -> + int64 Lwt.t = + fun db content provider -> + let module Db = (val db) in + let module CaqtiValues = Encoder.Map (struct + include Encoder.DefaultEncoder + + type 'a t = 'a + + let f : type a. a Intf.data -> a t = + fun Intf.{ name; content } -> + let result = provider name in + (* Check the value given by the provider and ensure it’s match + the expected type *) + match (content, result) with + | _, None -> + (* The provider does not have any value for this property, use the + default value*) + Model.Typ.default_value content + | _, V (field_type', value) -> ( + match Model.Typ.eq content field_type' with + | Some Equal -> Some value + | None -> raise TypeMismatch) + end) in + let init_fields = + match Model.Content.parent content with + | None -> [] + | Some _ -> Model.Field.[ create (T Integer) [] ~required:true "parent" ] + in + + (* Remove the mulivaluated content fields from the request because they are + not inserted in the table directly *) + let (T t) = + collect_fields content + ~filter:(fun field -> + let (T ty) = Model.Field.type_ field in + match ty with Model.Typ.MultiReference _ -> false | _ -> true) + ~init_fields + in + let insert_template = + match t with Intf.T0 -> "" | _ -> "(" ^ Encoder.EncodeInsert.f t ^ ")" + and columns = + match t with + | Intf.T0 -> "DEFAULT" + | _ -> "(" ^ Encoder.InsertTableName.f t ^ ")" + in + + let buff = Buffer.create 16 in + let format = Format.formatter_of_buffer buff in + let () = + Format.fprintf format "INSERT INTO \"%s\" %s VALUES %s RETURNING ID" + (Model.Content.id content) columns insert_template + in + Format.pp_print_flush format (); + let types_param = Encoder.CaqtiRequest.f t in + let request = + Caqti_request.Infix.((types_param ->! Caqti_type.int64) ~oneshot:true) + (Buffer.contents buff) + in + let ( let* ) = Lwt.bind in + let values = CaqtiValues.f t in + + (* The insert request is returning the ID. That’s why we call it with the + fuction [find] even if it is not a real find in the database. *) + let* id_result = Db.find request values in + let* id = Caqti_lwt.or_fail id_result in + + (* The value is created in the db, reuse the ID in order to insert the + multi-values fields in their own tables *) + let (T multi_valuated_fields) = + collect_fields content ~filter:(fun field -> + let (T ty) = Model.Field.type_ field in + match ty with Model.Typ.MultiReference _ -> true | _ -> false) + in + + let module Fold = Encoder.Fold (struct + type 'a t = 'a Lwt.t + + (** The function is called for each feature declared as multi reference. *) + let f : 'a Lwt.t -> 'b Intf.data -> 'a Lwt.t = + fun acc Intf.{ name; content } -> + ignore content; + let values = provider name in + ignore values; + let* acc = acc in + Lwt.return acc + end) in + let* () = Fold.f Lwt.return_unit multi_valuated_fields in + Lwt.return id + +(** Insert an entry for a specific content *) +let insert : + Caqti_lwt.connection -> + Model.Reference.t Model.Content.t -> + ?parent:int64 -> + (string -> Model.Reference.t Model.Typ.value) -> + int64 Lwt.t = + fun db content ?parent provider -> + let provider = + match (parent, Model.Content.parent content) with + | _, None -> provider + | None, Some _ -> + (* Raise an error right now if the parent of the subcontent is not + given *) + raise TypeMismatch + | Some v, Some _ -> ( + (* Otherwise update the provider to give a value for the parent *) + function + | "parent" -> Model.Typ.(V (Integer, v)) + | other -> provider other) + in + let module Db = (val db) in + match Caqti_driver_info.dialect_tag Db.driver_info with + | `Sqlite | `Pgsql -> insert_returning db content provider + | _ -> raise Not_found diff --git a/lib/query/insert.mli b/lib/query/insert.mli new file mode 100644 index 0000000..63e16a6 --- /dev/null +++ b/lib/query/insert.mli @@ -0,0 +1,12 @@ +(** Low level insertion in the database *) + +exception TypeMismatch +(** Exception raised when the given type does not match the value *) + +val insert : + Caqti_lwt.connection -> + Model.Reference.t Model.Content.t -> + ?parent:int64 -> + (string -> Model.Reference.t Model.Typ.value) -> + int64 Lwt.t +(** See [Query.insert] *) diff --git a/lib/query/intf.ml b/lib/query/intf.ml new file mode 100644 index 0000000..49c51db --- /dev/null +++ b/lib/query/intf.ml @@ -0,0 +1,151 @@ +type 'a data = { name : string; content : ('a, Model.Reference.t) Model.Typ.t } +(** The data is the name of the field and the type associated with *) + +type t_type = TT : 'a data -> t_type [@@unboxed] + +(** Keep a track of the number in the fields in the content. Each property in + the content is mapped as an optionnal field in the DB, as each value can be + empty. *) +type _ tuple = + | T0 : unit tuple + | T1 : 'a data -> 'a tuple + | T2 : 'a data * 'b data -> ('a * 'b) tuple + | T3 : 'a data * 'b data * 'c data -> ('a * 'b * 'c) tuple + | T4 : 'a data * 'b data * 'c data * 'd data -> ('a * 'b * 'c * 'd) tuple + | T5 : + 'a data * 'b data * 'c data * 'd data * 'e data + -> ('a * 'b * 'c * 'd * 'e) tuple + | T6 : + 'a data * 'b data * 'c data * 'd data * 'e data * 'f data + -> ('a * 'b * 'c * 'd * 'e * 'f) tuple + | T7 : + 'a data * 'b data * 'c data * 'd data * 'e data * 'f data * 'g data + -> ('a * 'b * 'c * 'd * 'e * 'f * 'g) tuple + | T8 : + 'a data + * 'b data + * 'c data + * 'd data + * 'e data + * 'f data + * 'g data + * 'h data + -> ('a * 'b * 'c * 'd * 'e * 'f * 'g * 'h) tuple + | T9 : + 'a data + * 'b data + * 'c data + * 'd data + * 'e data + * 'f data + * 'g data + * 'h data + * 'i data + -> ('a * 'b * 'c * 'd * 'e * 'f * 'g * 'h * 'i) tuple + | T10 : + 'a data + * 'b data + * 'c data + * 'd data + * 'e data + * 'f data + * 'g data + * 'h data + * 'i data + * 'j data + -> ('a * 'b * 'c * 'd * 'e * 'f * 'g * 'h * 'i * 'j) tuple + | T_N : + 'a data + * 'b data + * 'c data + * 'd data + * 'e data + * 'f data + * 'g data + * 'h data + * 'i data + * 'j data + * 'tl tuple + -> ('a * 'b * 'c * 'd * 'e * 'f * 'g * 'h * 'i * 'j * 'tl) tuple + +type t = T : _ tuple -> t [@@unboxed] + +module type Encoder = sig + type 'a t + + val f : 'a data -> 'a t + val unit : unit t + val t2 : 'a t -> 'b t -> ('a * 'b) t + val t3 : 'a t -> 'b t -> 'c t -> ('a * 'b * 'c) t + val t4 : 'a t -> 'b t -> 'c t -> 'd t -> ('a * 'b * 'c * 'd) t + val t5 : 'a t -> 'b t -> 'c t -> 'd t -> 'e t -> ('a * 'b * 'c * 'd * 'e) t + + val t6 : + 'a t -> + 'b t -> + 'c t -> + 'd t -> + 'e t -> + 'f t -> + ('a * 'b * 'c * 'd * 'e * 'f) t + + val t7 : + 'a t -> + 'b t -> + 'c t -> + 'd t -> + 'e t -> + 'f t -> + 'g t -> + ('a * 'b * 'c * 'd * 'e * 'f * 'g) t + + val t8 : + 'a t -> + 'b t -> + 'c t -> + 'd t -> + 'e t -> + 'f t -> + 'g t -> + 'h t -> + ('a * 'b * 'c * 'd * 'e * 'f * 'g * 'h) t + + val t9 : + 'a t -> + 'b t -> + 'c t -> + 'd t -> + 'e t -> + 'f t -> + 'g t -> + 'h t -> + 'i t -> + ('a * 'b * 'c * 'd * 'e * 'f * 'g * 'h * 'i) t + + val t10 : + 'a t -> + 'b t -> + 'c t -> + 'd t -> + 'e t -> + 'f t -> + 'g t -> + 'h t -> + 'i t -> + 'j t -> + ('a * 'b * 'c * 'd * 'e * 'f * 'g * 'h * 'i * 'j) t + + val t_n : + 'a t -> + 'b t -> + 'c t -> + 'd t -> + 'e t -> + 'f t -> + 'g t -> + 'h t -> + 'i t -> + 'j t -> + 'k t -> + ('a * 'b * 'c * 'd * 'e * 'f * 'g * 'h * 'i * 'j * 'k) t +end diff --git a/lib/query/query.ml b/lib/query/query.ml new file mode 100644 index 0000000..4aaf467 --- /dev/null +++ b/lib/query/query.ml @@ -0,0 +1,9 @@ +(** This module provide functions used to generate SQL requests for creating or + updating contents. + + The model is not known at the compilation time, but we have all the required + informations in the configuration. Here, we create Caqti request template + matching the types given in the configuration. *) + +let insert = Insert.insert +let create = Create.create diff --git a/lib/query/query.mli b/lib/query/query.mli new file mode 100644 index 0000000..1a26383 --- /dev/null +++ b/lib/query/query.mli @@ -0,0 +1,21 @@ +val insert : + Caqti_lwt.connection -> + Model.Reference.t Model.Content.t -> + ?parent:int64 -> + (string -> Model.Reference.t Model.Typ.value) -> + int64 Lwt.t +(** Insert a new element and return the ID. + + [insert content ~parent provider] will create the content in the database. + + The parent is required if the content is a subcontent. Not providing the + parameter is a structural error in the database. + + For each field in the content, the function [provider] will be called with + the name for this property. The value returned shall match the expected type + for this property, the execption [TypeMismatch] is raised otherwise. + + This is a low-level function: there is no representation for the content + itself, and no functionnals controls are realized. *) + +val create : Caqti_lwt.connection -> Configuration.Ast.setting -> unit Lwt.t diff --git a/lib/query/tests/create.t b/lib/query/tests/create.t new file mode 100644 index 0000000..565235a --- /dev/null +++ b/lib/query/tests/create.t @@ -0,0 +1,150 @@ +Test the schema generated in the database. The tests create the database +in memory according the configuration given, then display the schema for a +specfic table. (The schema is extracted from the table, and requires the table +to be succesfully created). + +Test a single content with no field: + + $ tests -schema "entity" <<EOF + > { + > "content": [ + > { + > "id": "entity", + > } + > ] + > } + > EOF + CREATE TABLE "entity" + ( "id" INTEGER PRIMARY KEY ) + +Text fields or numeric fields are created as columns directly in the table: + + $ tests -schema "entity" <<EOF + > { + > "content": [ + > { + > "id": "entity", + > "section": [ + > { + > "field": [ + > { + > "name": "name", + > "label": {}, + > "type": "text", + > "required": true + > }, + > { + > "name": "year", + > "label": {}, + > "type": "integer" + > } + > ] + > } + > ] + > } + > ] + > } + > EOF + CREATE TABLE "entity" + ( "id" INTEGER PRIMARY KEY + , "year" INTEGER + , "name" VARCHAR ) + +A subcontent is linked to the parent: + + $ tests -schema "details" <<EOF + > { + > "content": [ + > { + > "id": "entity", + > "subcontent": [ + > { + > "id": "details" + > } + > ] + > } + > ] + > } + > EOF + CREATE TABLE "details" + ( "parent" INTEGER NOT NULL + , "id" INTEGER PRIMARY KEY + , FOREIGN KEY("parent") REFERENCES entity("id") ) + +A reference field is declared as a foreign key to the linked element + + $ tests -schema "entity" <<EOF + > { + > "content": [ + > { + > "id": "entity", + > "section": [ + > { + > "field": [ + > { + > "name": "name", + > "label": {}, + > "type": "text", + > "required": true + > }, + > { + > "name": "user_type", + > "label": {}, + > "type": { + > "content": "user_type_list", + > "multivaluated": false + > } + > } + > ] + > } + > ] + > }, + > { + > "id": "user_type_list" + > } + > ] + > } + > EOF + CREATE TABLE "entity" + ( "id" INTEGER PRIMARY KEY + , "user_type" INTEGER + , "name" VARCHAR + , FOREIGN KEY("user_type") REFERENCES user_type_list("id") ) + +When the field is multivaluated, there is no column for this property in the +table but a dedicated table is created: + + $ tests -schema "entity" "entity.user_type" <<EOF + > { + > "content": [ + > { + > "id": "entity", + > "section": [ + > { + > "field": [ + > { + > "name": "user_type", + > "label": {}, + > "type": { + > "content": "user_type_list", + > "multivaluated": true + > } + > } + > ] + > } + > ] + > }, + > { + > "id": "user_type_list" + > } + > ] + > } + > EOF + CREATE TABLE "entity" + ( "id" INTEGER PRIMARY KEY ) + CREATE TABLE "entity.user_type" + ( "id" INTEGER PRIMARY KEY + , "parent" INTEGER NOT NULL + , "target" INTEGER NOT NULL + , FOREIGN KEY("parent") REFERENCES entity("id") + , FOREIGN KEY("target") REFERENCES user_type_list("id") ) diff --git a/lib/query/tests/dune b/lib/query/tests/dune new file mode 100644 index 0000000..c5913da --- /dev/null +++ b/lib/query/tests/dune @@ -0,0 +1,11 @@ +; Add the test library in the path + +(env + (_ + (binaries %{project_root}/test/tests.exe))) + +; And depend of it. The binary will be available in the +; cram tests under the name "tests" + +(cram + (deps %{bin:tests})) diff --git a/lib/query/tests/insert.t b/lib/query/tests/insert.t new file mode 100644 index 0000000..236bb97 --- /dev/null +++ b/lib/query/tests/insert.t @@ -0,0 +1,213 @@ +Test the capacity to insert elements in the database according a specific +schema + +The data to insert is given in the json format. This format is a subset from the +configuration (for example we can’t have a property with the same name as a +subcontent) + +Minimal exemple, a content without any field does not have any value: + + $ tests -insert <<EOF + > { + > "content": [ + > { + > "id": "entity", + > "values": [ {} ] + > } + > ] + > } + > EOF + entity:1 + {} + +Ensure an error is raised if the value does not match the expected type. + +Here, the year is declared as an integer, but the value is provided as string. +This error is expected to be checked and reported. + + $ tests -insert <<EOF + > { + > "content": [ + > { + > "id": "entity", + > "section": [ + > { + > "field": [ + > { + > "name": "year", + > "label": {}, + > "type": "integer" + > } + > ] + > } + > ], + > "values": [ { "year": "1234", } ] + > } + > ] + > } + > EOF + Fatal error: exception Query__Insert.TypeMismatch + [2] + + $ tests -insert <<EOF + > { + > "content": [ + > { + > "id": "entity", + > "section": [ + > { + > "field": [ + > { + > "name": "name", + > "label": {}, + > "type": "text", + > "required": true + > }, + > { + > "name": "year", + > "label": {}, + > "type": "integer" + > } + > ] + > } + > ], + > "values": [ + > { + > "name": "name", + > "year": 1234, + > } + > ] + > } + > ] + > } + > EOF + entity:1 + {"name":"name","year":1234} + +Any value can be omitted and will be replaced by the default value: + $ tests -insert <<EOF + > { + > "content": [ + > { + > "id": "entity", + > "section": [ + > { + > "field": [ + > { + > "name": "year", + > "label": {}, + > "type": "integer", + > } + > ] + > } + > ], + > "values": [ {} ] + > } + > ] + > } + > EOF + entity:1 + {"year":null} + +If the field is "required" the value is still inserted: the requirement feature +is only functionnal; this shall not block the creation of the content. + + $ tests -insert <<EOF + > { + > "content": [ + > { + > "id": "entity", + > "section": [ + > { + > "field": [ + > { + > "name": "year", + > "label": {}, + > "type": "integer", + > "required": true, + > } + > ] + > } + > ], + > "values": [ {} ] + > } + > ] + > } + > EOF + entity:1 + {"year":null} + +A subcontent is linked to the parent: + + $ tests -insert <<EOF + > { + > "content": [ + > { + > "id": "referential", + > }, + > { + > "id": "entity", + > "section": [ + > { + > "field": [ + > { + > "name": "idx", + > "label": {}, + > "type": "integer" + > }, + > { + > "name": "ref", + > "label": {}, + > "type": { + > "content": "referential", + > "multivaluated": true + > } + > } + > ] + > } + > ], + > "subcontent": [ + > { + > "id": "details", + > "section": [ + > { + > "field": [ + > { + > "name": "comment", + > "label": {}, + > "type": "text" + > }, + > ] + > } + > ], + > } + > ], + > "values": [ + > { + > "idx": 1, + > "details": [ + > {"comment": "lorem"}, + > {"comment": "ipsum"} + > ] + > }, + > { + > "idx": 2, + > "details": [ + > {"comment": "lorem 2"}, + > ] + > } + > ] + > } + > ] + > } + > EOF + entity:1 + {"idx":1} + details:1 + {"comment":"lorem","parent":1} + details:2 + {"comment":"ipsum","parent":1} + entity:2 + {"idx":2} + details:3 + {"comment":"lorem 2","parent":2} diff --git a/lib/splay/dune b/lib/splay/dune new file mode 100644 index 0000000..34da79e --- /dev/null +++ b/lib/splay/dune @@ -0,0 +1,2 @@ +(library + (name splay)) diff --git a/lib/splay/splay.ml b/lib/splay/splay.ml new file mode 100644 index 0000000..bf0a2ac --- /dev/null +++ b/lib/splay/splay.ml @@ -0,0 +1,198 @@ +module type KEY = sig + type t + + val compare : t -> t -> int + val pp : Format.formatter -> t -> unit +end + +module Make (El : KEY) = struct + type leaf + (** Fantom type for typing the tree *) + + type node + (** Fantom type for typing the tree *) + + type ('a, 'v) branch = + | Leaf : (leaf, 'v) branch + | Node : (_, 'v) branch * (El.t * 'v) * (_, 'v) branch -> (node, 'v) branch + + type 'v t = T : ('a, 'v) branch ref -> 'v t [@@unboxed] + + let empty () = T (ref Leaf) + + let isEmpty : type a. a t -> bool = + fun (T tree) -> match !tree with Leaf -> true | _ -> false + + let rec splay : El.t -> (node, 'any) branch -> (node, 'any) branch = + fun x t -> + let (Node (l, y, r)) = t in + begin match El.compare x (fst y) with + | 0 -> t + | v when v < 0 -> begin + match l with + | Leaf -> t + | Node (ll, z, rr) -> begin + match El.compare x (fst z) with + | 0 -> Node (ll, z, Node (rr, y, r)) + | v when v < 0 -> begin + match ll with + | Leaf -> Node (ll, z, Node (rr, y, r)) + | Node _ as ll -> + let (Node (newL, newV, newR)) = splay x ll in + Node (newL, newV, Node (newR, z, Node (rr, y, r))) + end + | _ -> ( + match rr with + | Leaf -> Node (ll, z, Node (rr, y, r)) + | Node _ as rr -> + let (Node (newL, newV, newR)) = splay x rr in + Node (Node (ll, z, newL), newV, Node (newR, y, r))) + end + end + | _ -> ( + match r with + | Leaf -> t + | Node (ll, z, rr) -> ( + match El.compare x (fst z) with + | 0 -> Node (Node (l, y, ll), z, rr) + | v when v < 0 -> begin + match ll with + | Leaf -> Node (Node (l, y, ll), z, rr) + | Node _ as ll -> + let (Node (newL, newV, newR)) = splay x ll in + Node (Node (l, y, newL), newV, Node (newR, z, rr)) + end + | _ -> ( + match rr with + | Leaf -> Node (Node (l, y, ll), z, rr) + | Node _ as rr -> + let (Node (newL, newV, newR)) = splay x rr in + Node (Node (Node (l, y, ll), z, newL), newV, newR)))) + end + + let member : type a. El.t -> a t -> bool = + fun x (T t) -> + match !t with + | Leaf -> false + | Node _ as root -> ( + let root' = splay x root in + t := root'; + let (Node (_, c', _)) = root' in + match El.compare (fst c') x with 0 -> true | _ -> false) + + let find : type a. El.t -> a t -> a option = + fun x (T t) -> + match !t with + | Leaf -> None + | Node _ as root -> ( + let root' = splay x root in + t := root'; + let (Node (_, c', _)) = root' in + match El.compare (fst c') x with 0 -> Some (snd c') | _ -> None) + + let add : type a. El.t -> a -> a t -> a t = + fun key value (T t) -> + match !t with + | Leaf -> T (ref (Node (Leaf, (key, value), Leaf))) + | Node _ as root -> ( + let root' = splay key root in + let (Node (l, y, r)) = root' in + match El.compare key (fst y) with + | 0 -> T (ref (Node (l, (key, value), r))) + | v when v < 0 -> T (ref (Node (l, (key, value), Node (Leaf, y, r)))) + | _ -> T (ref (Node (Node (l, y, Leaf), (key, value), r)))) + + let rec _subtree_maximum : type a. (a, 'any) branch -> (a, 'any) branch = + fun t -> + match t with + | Leaf -> Leaf + | Node (_, _, (Node (_, _, _) as x)) -> _subtree_maximum x + | Node (_, (key, value), Leaf) -> + ignore value; + splay key t + + let rec _subtree_minimum : type a. (a, 'any) branch -> (a, 'any) branch = + fun t -> + match t with + | Leaf -> Leaf + | Node ((Node (_, _, _) as x), _, _) -> _subtree_minimum x + | Node (Leaf, (key, value), _) -> + ignore value; + splay key t + + let remove : type a. El.t -> a t -> a t = + fun key (T t) -> + match !t with + | Leaf -> empty () + | Node _ as root -> + let root' = splay key root in + let (Node (l, c', r)) = root' in + begin match El.compare (fst c') key with + | 0 -> begin + match _subtree_maximum l with + | Node (l, c, Leaf) -> T (ref (Node (l, c, r))) + | Node (_, _, _) -> raise Not_found + | Leaf -> ( + match _subtree_minimum r with + | Leaf -> empty () + | Node (Leaf, c, r) -> T (ref (Node (l, c, r))) + | Node (_, _, _) -> raise Not_found) + end + (* The key is not present, return the splayed tree *) + | _ -> T (ref root') + end + + (** Existencial type for the branches *) + type 'a exBranch = Branch : (_, 'a) branch -> 'a exBranch [@@unboxed] + + let fold f init (T t) = + let rec _fold : type b. + ((El.t * 'a) * 'a exBranch) list -> 'acc -> (b, 'a) branch -> 'acc = + fun acc v -> function + (* We have a node : we accumulate the right part, and process the left + branch *) + | Node (left, (key, value), right) -> + let c = (key, value) in + (_fold [@tailcall]) ((c, Branch right) :: acc) v left + (* We have nothing left, we process the values delayed *) + | Leaf -> begin + match acc with + | [] -> v + | (c, Branch right) :: tl -> (_fold [@tailcall]) tl (f v c) right + end + in + _fold [] init !t + + let choose (T tree) = + match _subtree_minimum !tree with + | Leaf -> None + | Node (left, (key, value), right) -> + ignore left; + ignore right; + Some (key, value) + + let pp formatter (T t) = + let leaf_id = ref 0 in + let repr_edge from formatter dest = + Format.fprintf formatter "\"%a\" -> \"%a\"@;" El.pp from El.pp dest + in + + let rec repr' : type b. El.t -> Format.formatter -> (b, _) branch -> unit = + fun parent formatter -> function + | Leaf -> + Format.fprintf formatter "leaf_%d [shape=point]@;" !leaf_id; + Format.fprintf formatter "\"%a\" -> leaf_%d@;" El.pp parent !leaf_id; + incr leaf_id + | Node (l, c, r) -> + let key = fst c in + Format.fprintf formatter "%a%a%a" (repr_edge parent) key (repr' key) + l (repr' key) r + in + + match !t with + | Leaf -> Format.fprintf formatter "digraph G {}" + | Node (l, c, r) -> + let key = fst c in + Format.fprintf formatter "@[<v 2>digraph G {@;%a%a@]}" (repr' key) l + (repr' key) r +end diff --git a/lib/splay/splay.mli b/lib/splay/splay.mli new file mode 100644 index 0000000..f484651 --- /dev/null +++ b/lib/splay/splay.mli @@ -0,0 +1,36 @@ +module type KEY = sig + type t + + val compare : t -> t -> int + val pp : Format.formatter -> t -> unit +end + +module Make (El : KEY) : sig + type 'a t + + val empty : unit -> 'a t + (** Create an empty tree *) + + val isEmpty : 'a t -> bool + + val find : El.t -> 'a t -> 'a option + (** Return the element in the tree with the given key *) + + val add : El.t -> 'a -> 'a t -> 'a t + (** Add one element in the tree, if the key is already present, the associated + element is replaced. *) + + val member : El.t -> 'a t -> bool + (** Check if the key exists *) + + val remove : El.t -> 'a t -> 'a t + val fold : ('a -> El.t * 'b -> 'a) -> 'a -> 'b t -> 'a + + val choose : 'a t -> (El.t * 'a) option + (** Return one element of the given tree, or raise Not_found if the tree is + empty. Which element is chosen is unspecified, but equal elements will be + chosen for equal trees. *) + + val pp : Format.formatter -> 'a t -> unit + (** Represent the content in dot syntax *) +end diff --git a/lib/splay/tests/dune b/lib/splay/tests/dune new file mode 100644 index 0000000..c5913da --- /dev/null +++ b/lib/splay/tests/dune @@ -0,0 +1,11 @@ +; Add the test library in the path + +(env + (_ + (binaries %{project_root}/test/tests.exe))) + +; And depend of it. The binary will be available in the +; cram tests under the name "tests" + +(cram + (deps %{bin:tests})) diff --git a/lib/splay/tests/splay.t b/lib/splay/tests/splay.t new file mode 100644 index 0000000..628ccaa --- /dev/null +++ b/lib/splay/tests/splay.t @@ -0,0 +1,93 @@ +Tests for the splay tree. The tree representation used in the tests follow the +dot syntax + +See https://en.wikipedia.org/wiki/Splay_tree + + +The root is the latest inserted node: + + $ tests -splay_tree \ + > -add 5 \ + > -add 3 + digraph G { + leaf_0 [shape=point] + "3" -> leaf_0 + "3" -> "5" + leaf_1 [shape=point] + "5" -> leaf_1 + leaf_2 [shape=point] + "5" -> leaf_2 + } + + $ tests -splay_tree \ + > -add 3 \ + > -add 5 + digraph G { + "5" -> "3" + leaf_0 [shape=point] + "3" -> leaf_0 + leaf_1 [shape=point] + "3" -> leaf_1 + leaf_2 [shape=point] + "5" -> leaf_2 + } + +Collecting an element in the tree will push this node at the root: + + $ tests -splay_tree \ + > -add 1 \ + > -add 2 \ + > -add 3 \ + > -get 2 + digraph G { + "2" -> "1" + leaf_0 [shape=point] + "1" -> leaf_0 + leaf_1 [shape=point] + "1" -> leaf_1 + "2" -> "3" + leaf_2 [shape=point] + "3" -> leaf_2 + leaf_3 [shape=point] + "3" -> leaf_3 + } + + $ tests -splay_tree \ + > -add 1 \ + > -add 2 \ + > -add 3 \ + > -add 4 \ + > -get 1 + digraph G { + leaf_0 [shape=point] + "1" -> leaf_0 + "1" -> "3" + "3" -> "2" + leaf_1 [shape=point] + "2" -> leaf_1 + leaf_2 [shape=point] + "2" -> leaf_2 + "3" -> "4" + leaf_3 [shape=point] + "4" -> leaf_3 + leaf_4 [shape=point] + "4" -> leaf_4 + } + +Removing an element from the tree modify the structure + + $ tests -splay_tree \ + > -add 1 \ + > -add 2 \ + > -add 3 \ + > -del 2 + digraph G { + leaf_0 [shape=point] + "1" -> leaf_0 + "1" -> "3" + leaf_1 [shape=point] + "3" -> leaf_1 + leaf_2 [shape=point] + "3" -> leaf_2 + } + diff --git a/test/common.ml b/test/common.ml new file mode 100644 index 0000000..807289a --- /dev/null +++ b/test/common.ml @@ -0,0 +1,13 @@ +(** Common fuctions shared between the tests *) + +let ( let* ) = Lwt.bind + +(** Connect to the database in memory and create a schema matching the given + configuration *) +let connect : Configuration.Ast.setting -> Caqti_lwt.connection Lwt.t = + fun conf -> + let* conn = Caqti_lwt_unix.connect (Uri.of_string "sqlite3::memory:") in + let* db = Caqti_lwt.or_fail conn in + let module Db = (val db) in + let* () = Query.create db conf in + Lwt.return db diff --git a/test/configuration_.ml b/test/configuration_.ml new file mode 100644 index 0000000..0fd42fb --- /dev/null +++ b/test/configuration_.ml @@ -0,0 +1,27 @@ +let name = "configuration" +let description = "Load the configuration file and report errors" +let printer = ref (fun formatter _ -> Format.pp_print_nothing formatter ()) + +let speclist = + [ + ( "-tree", + Arg.Unit + (fun () -> + printer := + fun formater conf -> + Configuration.Graph_tree.pp formater (Configuration.Ast.tree conf)), + "Print the depenncy tree between root contents" ); + ] + +type t = (Configuration.Ast.setting, Configuration.Read_conf.error) result + +let pp : Format.formatter -> t -> unit = + Format.pp_print_result ~error:Configuration.Read_conf.pp_error + ~ok:(fun formater conf -> !printer formater conf) + +let exec : string list -> t = + fun _ -> + let stdin = In_channel.input_all stdin in + let ( let+ ) opt cont = Result.map cont opt in + let+ configuration = Configuration.Read_conf.read_string_conf stdin in + configuration diff --git a/test/dune b/test/dune new file mode 100644 index 0000000..51fa57a --- /dev/null +++ b/test/dune @@ -0,0 +1,20 @@ +(executable + (name tests) + (libraries + lwt + lwt.unix + dream + dwr_dream + dwr_cohttp + services_impl + caqti + caqti-lwt + caqti-lwt.unix + caqti-driver-sqlite3 + decoders + uri + splay + configuration + model + html + query)) diff --git a/test/hash.ml b/test/hash.ml new file mode 100644 index 0000000..83f7d5c --- /dev/null +++ b/test/hash.ml @@ -0,0 +1,20 @@ +(** Just a proof of concept. + + Display the hash of the configuration *) + +let name = __FILE__ +let description = "Print the hash of the configuration" +let speclist = [] + +type t = (int, Configuration.Read_conf.error) result + +let pp : Format.formatter -> t -> unit = + Format.pp_print_result ~error:Configuration.Read_conf.pp_error + ~ok:Format.pp_print_int + +let exec : string list -> t = + fun _ -> + let stdin = In_channel.input_all stdin in + let ( let+ ) opt cont = Result.map cont opt in + let+ configuration = Configuration.Read_conf.read_string_conf stdin in + Hashtbl.hash configuration diff --git a/test/insert.ml b/test/insert.ml new file mode 100644 index 0000000..eaa132f --- /dev/null +++ b/test/insert.ml @@ -0,0 +1,186 @@ +open StdLabels + +let name = __FILE__ +let description = "Insert data and check the result" +let speclist = [] + +type t = + ((string * Int64.t * string) list, Configuration.Read_conf.error) result + +let pp : Format.formatter -> t -> unit = + Format.pp_print_result ~error:Configuration.Read_conf.pp_error + ~ok: + (Format.pp_print_list ~pp_sep:Format.pp_print_cut + (fun formatter (content_id, id, content) -> + Format.fprintf formatter "@[<v 2>%s:%Ld@;%s@]" content_id id content)) + +(** Read the values to insert in the configuration *) +module Make (S : Decoders.Decode.S) = struct + let ( let* ) = S.( let* ) + let ( let+ ) = S.( let+ ) + + type value = Model.Reference.t Model.Typ.value + + (** The values are encoded in a very simple way, depending of the nature of + the field in the json, we create a property in for text or numeric *) + let value : value S.decoder = + S.one_of + [ + ( "numeric", + S.map (fun v -> Model.Typ.(V (Integer, Int64.of_int v))) S.int ); + ("text", S.map (fun v -> Model.Typ.(V (Text, v))) S.string); + ("other", S.map (fun _ -> Model.Typ.None) S.value); + ] + + type content = Model.Reference.t Model.Content.t + type properties = (string * value) list + type content_to_insert = content * properties list + + let rec properties : + Configuration.Ast.setting -> + string -> + (content * (properties * content_to_insert list) list) S.decoder = + fun conf name -> + (* We are loading the same configuration template, the content is supposed + to exists by definition and will never be None *) + let content = Configuration.Ast.get_content conf name |> Option.get in + let* properties = + S.field_opt_or ~default:[] "values" (S.list (S.key_value_pairs value)) + in + let* subcontents = + S.field_opt_or ~default:[] "values" (S.list (subcontents conf)) + in + let to_insert = List.combine properties subcontents in + S.succeed (content, to_insert) + + and subcontents : + Configuration.Ast.setting -> content_to_insert list S.decoder = + fun conf -> + let* properties = + S.key_value_pairs_seq (fun key -> + S.one_of + [ + ( "subcontent", + fun v -> + match Configuration.Ast.get_content conf key with + | None -> Error (Decoders.Error.make "no content") + | Some subcontent -> + let res = S.list (S.key_value_pairs value) v in + let v = Result.map (fun v -> Some (subcontent, v)) res in + v ); + ("other", fun _ -> Ok None); + ]) + in + let properties = List.filter_map ~f:(fun v -> v) properties in + S.succeed properties + + let content : + Configuration.Ast.setting -> + (content * (properties * content_to_insert list) list) S.decoder = + fun conf -> + let* name = S.field "id" S.string in + properties conf name + + let configuration : + Configuration.Ast.setting -> + (content * (properties * content_to_insert list) list) list S.decoder = + fun conf -> S.field "content" (S.list (content conf)) +end + +module D = Make (Configuration.Json5.Decode) + +let query_columns : 'a Model.Content.t -> string = + fun content -> + let fields = + Model.Content.fields content + (* Remove the multivaluated fields from the query *) + |> Seq.filter (fun t -> + let (Model.Field.T ty) = Model.Field.type_ t in + match ty with Model.Typ.MultiReference _ -> false | _ -> true) + in + let buff = Buffer.create 64 in + let () = + Seq.iter + (fun field -> + Buffer.add_char buff '\''; + Buffer.add_string buff (Model.Field.name field); + + Buffer.add_string buff "',"; + Buffer.add_string buff (Model.Field.name field); + Buffer.add_string buff ",") + fields + in + + let () = + match Model.Content.parent content with + | None -> + let length = Buffer.length buff in + if length > 1 then Buffer.truncate buff (length - 1); + () + | Some _ -> Buffer.add_string buff "'parent',parent" + in + + Buffer.contents buff + +let query table = + Caqti_request.Infix.(Caqti_type.(int64) ->! Caqti_type.string) + ~oneshot:true + ("SELECT json_object(" ^ query_columns table ^ ") from " + ^ Model.Content.id table ^ " where id=?") + +let insert_and_get_result ?parent db content entry = + let ( let* ) = Lwt.bind in + let* id = + Query.insert ?parent db content (fun v -> + match List.assoc_opt v entry with Some v -> v | None -> Model.Typ.None) + in + let content_id = Model.Content.id content in + let module Db = (val db) in + let* json_result = Db.find (query content) id in + let* json = Caqti_lwt.or_fail json_result in + Lwt.return (content_id, id, json) + +let exec : string list -> t = + fun _ -> + let stdin = In_channel.input_all stdin in + let ( let* ) = Result.bind in + let* configuration = Configuration.Read_conf.read_string_conf stdin in + let* inserts = + Configuration.Json5.Decode.decode_string + (D.configuration configuration) + stdin + in + Lwt_main.run + (let ( let* ) = Lwt.bind in + let* db = Common.connect configuration in + let module Db = (val db) in + let* insertions = + Lwt_list.fold_left_s + (fun acc (content, entries) -> + Lwt_list.fold_left_s + (fun acc (entry, subcontents) -> + let* content_id, id, json = + insert_and_get_result db content entry + in + + let acc = (content_id, id, json) :: acc in + + (* Insert the subcontent associated *) + Lwt_list.fold_left_s + (fun acc (subcontent, entries) -> + let* acc = + Lwt_list.fold_left_s + (fun acc entry -> + let* subcontent_id, id, json = + insert_and_get_result ~parent:id db subcontent entry + in + Lwt.return ((subcontent_id, id, json) :: acc)) + acc entries + in + + Lwt.return acc) + acc subcontents) + acc entries) + [] inserts + in + Lwt.return_ok (List.rev insertions)) diff --git a/test/intf.ml b/test/intf.ml new file mode 100644 index 0000000..a68fa88 --- /dev/null +++ b/test/intf.ml @@ -0,0 +1,9 @@ +module type T = sig + type t + + val exec : string list -> t + val pp : Format.formatter -> t -> unit + val speclist : (string * Arg.spec * string) list + val name : string + val description : string +end diff --git a/test/parent.ml b/test/parent.ml new file mode 100644 index 0000000..4a15bfa --- /dev/null +++ b/test/parent.ml @@ -0,0 +1,42 @@ +let name = __FILE__ + +let description = + "Return the parent of the given content. The configuration is read on the \ + standard input" + +let parent = ref Model.Content.parent + +let speclist = + [ + ( "-root", + Arg.Unit + (fun () -> parent := fun content -> Some (Model.Content.root content)), + "Return the root element instead of the parent" ); + ] + +type t = (string option option, Configuration.Read_conf.error) result + +let pp : Format.formatter -> t -> unit = + Format.pp_print_result ~error:Configuration.Read_conf.pp_error + ~ok: + (Format.pp_print_option ~none:(fun f () -> + Format.pp_print_string f "[Content not found]") + @@ Format.pp_print_option ~none:(fun f () -> + Format.pp_print_string f "[No parent]") + @@ fun f -> Format.fprintf f "\"%s\"") + +let exec : string list -> t = function + | [ subcontent_id ] -> + let parent_id = + let stdin = In_channel.input_all stdin in + let ( let+ ) opt cont = Result.map cont opt in + let+ configuration = Configuration.Read_conf.read_string_conf stdin in + let ( let+ ) opt cont = Option.map cont opt in + let+ subcontent = + Configuration.Ast.get_content configuration subcontent_id + in + let+ v = !parent subcontent in + Model.Content.id v + in + parent_id + | _ -> failwith "Invalid arguments" diff --git a/test/printer.ml b/test/printer.ml new file mode 100644 index 0000000..5469d5e --- /dev/null +++ b/test/printer.ml @@ -0,0 +1,22 @@ +let name = __FILE__ +let description = "Print the configuration in json format" +let speclist = [] + +type t = (Configuration.Ast.setting, Configuration.Read_conf.error) result + +module TomlConf = Configuration.Read_conf.Make (Configuration.Toml.Decode) + +let read_conf : + string -> + (Configuration.Ast.setting, Configuration.Toml.Decode.error) result = + fun file -> Configuration.Toml.Decode.decode_file TomlConf.t file + +module ToJson = Configuration.Read_conf.Make (Configuration.Json5.Encode) + +let print_conf : + Configuration.Ast.setting -> Configuration.Json5.Json_encodeable.value = + fun _ -> raise Not_found + +let pp : Format.formatter -> t -> unit = + Format.pp_print_result ~error:Configuration.Read_conf.pp_error + ~ok:Format.pp_print_int diff --git a/test/schema.ml b/test/schema.ml new file mode 100644 index 0000000..0dc386d --- /dev/null +++ b/test/schema.ml @@ -0,0 +1,32 @@ +let name = __FILE__ +let description = "Print the schema for the given tables" +let speclist = [] + +type t = (string list, Configuration.Read_conf.error) result + +let pp : Format.formatter -> t -> unit = + Format.pp_print_result ~error:Configuration.Read_conf.pp_error + ~ok: + (Format.pp_print_list ~pp_sep:Format.pp_print_newline + Format.pp_print_string) + +let ( let* ) = Lwt.bind +let ( let+ ) opt cont = Result.map cont opt + +let schema_query = + Caqti_request.Infix.(Caqti_type.(string) ->! Caqti_type.string) + "SELECT sql from sqlite_schema where name=?" + +let get_schema : Caqti_lwt.connection -> string -> string Lwt.t = + fun db table_name -> + let module Db = (val db) in + let* result = Db.find schema_query table_name in + Caqti_lwt.or_fail result + +let exec : string list -> t = + fun tables -> + let stdin = In_channel.input_all stdin in + let+ configuration = Configuration.Read_conf.read_string_conf stdin in + Lwt_main.run + (let* db = Common.connect configuration in + Lwt_list.map_s (get_schema db) (List.rev tables)) diff --git a/test/splay_tree.ml b/test/splay_tree.ml new file mode 100644 index 0000000..318fc96 --- /dev/null +++ b/test/splay_tree.ml @@ -0,0 +1,28 @@ +let name = __FILE__ +let description = "Display the tree content after operations" + +module T = Splay.Make (struct + include Int + + let pp = Format.pp_print_int +end) + +type t = unit T.t + +let pp : Format.formatter -> t -> unit = T.pp +let tree : unit T.t ref = ref (T.empty ()) + +let speclist = + [ + ( "-add", + Arg.Int (fun n -> tree := T.add n () !tree), + "Add an element in the tree" ); + ( "-del", + Arg.Int (fun n -> tree := T.remove n !tree), + "Remove an element from the tree" ); + ( "-get", + Arg.Int (fun n -> ignore @@ T.find n !tree), + "Get an element from the tree" ); + ] + +let exec : string list -> t = fun _ -> !tree diff --git a/test/tests.ml b/test/tests.ml new file mode 100644 index 0000000..5e2bd59 --- /dev/null +++ b/test/tests.ml @@ -0,0 +1,50 @@ +(** Test library entry point. + + This library is a companion for the CRAM tests exopsing functions for the + test. + + Each module can be executed by giving its name as an argument to the binary. + The arguments expected by each test module are not specified *) + +let submodule = ref None +let speclist = ref [] + +let register : (module Intf.T) -> string * Arg.spec * string = + fun (module T) -> + let name = + T.name |> String.lowercase_ascii |> Filename.remove_extension + |> Filename.basename + in + ( "-" ^ name, + Arg.Unit + (fun () -> + speclist := T.speclist; + submodule := Some (module T : Intf.T)), + T.description ) + +(** Register all the tests in the library *) +let () = + speclist := + List.sort + (fun (n1, _, _) (n2, _, _) -> String.compare n1 n2) + [ + register (module Splay_tree); + register (module Parent); + register (module Schema); + register (module Hash); + register (module Configuration_); + register (module Insert); + ] + +let args = ref [] +let annon_fun arg = args := arg :: !args +let () = Arg.parse_dynamic speclist annon_fun "Start the tests" + +let () = + match !submodule with + | None -> + prerr_endline "Please select a test from the library to run"; + exit 1 + | Some (module SubCommand : Intf.T) -> + let result = SubCommand.exec !args in + Format.printf "@[<v 0>%a@]@." SubCommand.pp result |
