11// @flow
2+ import typeof { Token } from 'chevrotain' ;
3+
24import { Parser } from 'chevrotain' ;
35import {
46 HeaderNameT ,
@@ -18,6 +20,8 @@ type value = string|number|boolean;
1820type section = Map < key , Array < value >> ;
1921type sectionKey = string ;
2022type config = Map < sectionKey , section > ;
23+ type path = string ;
24+ type interpret = ( path , config ) => config ;
2125
2226/*
2327 top ::= (header body)*
@@ -28,22 +32,19 @@ type config = Map<sectionKey, section>;
2832*/
2933class ConfigParser extends Parser {
3034
35+ _interpret : interpret ;
3136 _map : config ;
3237
33- constructor (
34- interpret ,
35- config
36- ) {
37- super ( [ ] , lexicalGrammar , config ) ;
38+ constructor ( interpret : interpret , parserOptions : Object ) {
39+ super ( [ ] , lexicalGrammar , parserOptions ) ;
3840 this . _interpret = interpret ;
3941 Parser . performSelfAnalysis ( this ) ;
4042 }
4143
42- parse ( input , map = new Map ) {
44+ execute ( input : Array < Token > , map : config ) : void {
4345 this . _map = map ;
4446 super . input = input ;
4547 super . SUBRULE ( this . top , [ map ] ) ;
46- return map ;
4748 }
4849
4950 top = super . RULE ( 'top' , ( map ) => {
@@ -95,6 +96,11 @@ class ConfigParser extends Parser {
9596 } ) ;
9697
9798 body = super . RULE ( 'body' , ( map : section ) => {
99+ // here is where we know if a key is an actual path
100+ // such that if this path key is within a special section
101+ // that being of include or includeIf
102+ // then we actually perform the inclusion and the recursive interpretation
103+ // so we need to pass in that information as a parameter
98104 super . MANY ( ( ) => {
99105 const key = super . SUBRULE ( this . key ) ;
100106 let values = map . get ( key ) ;
@@ -139,4 +145,12 @@ class ConfigParser extends Parser {
139145
140146export default ConfigParser ;
141147
142- export type { config , sectionKey , section , key , value } ;
148+ export type {
149+ interpret ,
150+ path ,
151+ config ,
152+ sectionKey ,
153+ section ,
154+ key ,
155+ value
156+ } ;
0 commit comments