@@ -62,17 +62,26 @@ class ParserManager {
6262 this . parser = null ;
6363 this . templateKind = templateKind ? templateKind : 'clause' ;
6464 this . currentTime = datetimeutil . setCurrentTime ( null ) ; // Default setting to now
65+ this . userParsingTable = parsingTable ;
66+ this . formulaEval = formulaEval ? formulaEval : defaultFormulaEval ;
67+
68+ // Initialize parsing table
69+ this . initParsingTable ( ) ;
70+ }
6571
72+ /**
73+ * Initialize parsing table
74+ */
75+ initParsingTable ( ) {
6676 // Mapping from types to parsers/drafters
6777 this . parserVisitor = new ToParserVisitor ( ) ;
6878 const parserHook = function ( ast , parameters ) {
6979 return ToParserVisitor . toParserWithParameters ( new ToParserVisitor ( ) , ast , parameters ) ;
7080 } ;
7181 this . parsingTable = new ParsingTable ( this . modelManager , parserHook , draftVisitNodes ) ;
72- if ( parsingTable ) {
73- this . parsingTable . addParsingTable ( parsingTable ) ;
82+ if ( this . userParsingTable ) {
83+ this . parsingTable . addParsingTable ( this . userParsingTable ) ;
7484 }
75- this . formulaEval = formulaEval ? formulaEval : defaultFormulaEval ;
7685 }
7786
7887 /**
@@ -154,17 +163,17 @@ class ParserManager {
154163 }
155164
156165 /**
157- * Sets parsing table for variables
166+ * Sets parsing table extension
158167 * @param {object } table the parsing table
159168 */
160169 setParsingTable ( table ) {
161- this . parsingTable = table ;
170+ this . userParsingTable = table ;
162171 }
163172
164173 /**
165- * Build the parser
174+ * Initialize the parser
166175 */
167- buildParser ( ) {
176+ initParser ( ) {
168177 if ( ! this . templateMark ) {
169178 const tokenStream = templateToTokens ( this . template ) ;
170179 const template = tokensToUntypedTemplateMark ( tokenStream , this . templateKind ) ;
@@ -173,6 +182,32 @@ class ParserManager {
173182 this . parser = this . parserVisitor . toParser ( this , this . templateMark , this . parsingTable ) ;
174183 }
175184
185+ /**
186+ * Build the parser
187+ */
188+ buildParser ( ) {
189+ if ( this . parser ) {
190+ this . rebuildParser ( ) ;
191+ } else {
192+ this . initParser ( ) ;
193+ }
194+ }
195+
196+ /**
197+ * Rebuild the parser
198+ */
199+ rebuildParser ( ) {
200+ // Clear the parser
201+ this . parser = null ;
202+ // Reinitialize the parsing table
203+ this . initParsingTable ( ) ;
204+ // Clear templateMark if a template grammar exists
205+ if ( this . template && this . templateMark ) {
206+ this . templateMark = null ;
207+ }
208+ this . initParser ( ) ;
209+ }
210+
176211 /**
177212 * Get the execute function for a given formula
178213 * @param {string } name - the name of that formula
0 commit comments