1 /**
2 * Copyright © DiamondMVC 2019
3 * License: MIT (https://github.com/DiamondMVC/Diamond/blob/master/LICENSE)
4 * Author: Jacob Jensen (bausshf)
5 */
6 module diamond.templates.grammar;
7 
8 import diamond.templates.contentmode;
9 import diamond.templates.characterincludemode;
10 
11 /// A wrapper around the basic template grammar for parsing a diamond template.
12 final class Grammar
13 {
14   private:
15   /// The name.
16   string _name;
17   /// The start character.
18   char _startCharacter;
19   /// The end character.
20   char _endCharacter;
21   /// The content mode.
22   ContentMode _contentMode;
23   /// The character include mode.
24   CharacterIncludeMode _characterIncludeMode;
25   /// Boolean determining whether the statement character should be included.
26   bool _includeStatementCharacter;
27   /// Boolean determining whether the grammar should ignore depth of characters or not.
28   bool _ignoreDepth;
29   /// A character that must follow the start character.
30   char _mandatoryStartCharacter;
31 
32   public:
33   final:
34   /**
35   * Creates a new template grammar.
36   * Params:
37   *   name =            The name of the grammar.
38   *   startCharacter =  The start character.
39   *   endCharacter =    The end character.
40   *   contentMode =               The content mode.
41   *   characterIncludeMode =      The character include mode.
42   *   includeStatementCharacter = Boolean determining whether the statement character should be included.
43   */
44   this(string name, char startCharacter, char endCharacter,
45     ContentMode contentMode, CharacterIncludeMode characterIncludeMode,
46     bool includeStatementCharacter, bool ignoreDepth,
47     char mandatoryStartCharacter = '\0')
48   {
49     _name = name;
50     _startCharacter = startCharacter;
51     _endCharacter = endCharacter;
52     _contentMode = contentMode;
53     _characterIncludeMode = characterIncludeMode;
54     _includeStatementCharacter = includeStatementCharacter;
55     _ignoreDepth = ignoreDepth;
56     _mandatoryStartCharacter = mandatoryStartCharacter;
57   }
58 
59   @property {
60     /// Gets the name.
61     const(string) name() { return _name; }
62 
63     /// Gets the start character.
64     const(char) startCharacter() { return _startCharacter; }
65 
66     /// Gets the end character.
67     const(char) endCharacter() nothrow { return _endCharacter; }
68 
69     /// Gets the content mode.
70     const(ContentMode) contentMode() { return _contentMode; }
71 
72     /// Gets the character include mode.
73     const(CharacterIncludeMode) characterIncludeMode() { return _characterIncludeMode; }
74 
75     /// Gets a boolean determining whether the statement character should be included.
76     const(bool) includeStatementCharacter() { return _includeStatementCharacter; }
77 
78     /// Gets a boolean determining whether the grammar should ignore depth or not.
79     const(bool) ignoreDepth() { return _ignoreDepth; }
80 
81     /// Gets a character that must follow the start character. '\0' indicates no character.
82     const(char) mandatoryStartCharacter() { return _mandatoryStartCharacter; }
83   }
84 }