Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Commit 8a87fa6

Browse files
committed
WIP
1 parent 7e65bee commit 8a87fa6

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

lib/config/ConfigInterpreter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class ConfigInterpreter {
1919
const text = this._readFile(path);
2020
const tokens = configLexer.tokenize(text).tokens;
2121
const parser = new ConfigParser(this.interpret.bind(this));
22-
parser.parse(tokens, map);
22+
parser.execute(tokens, map);
2323
return map;
2424
}
2525

lib/config/ConfigParser.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// @flow
2+
import typeof { Token } from 'chevrotain';
3+
24
import { Parser } from 'chevrotain';
35
import {
46
HeaderNameT,
@@ -18,6 +20,8 @@ type value = string|number|boolean;
1820
type section = Map<key, Array<value>>;
1921
type sectionKey = string;
2022
type 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
*/
2933
class 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

140146
export 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+
};

testy.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import fs from 'fs';
22
import { Lexer } from 'chevrotain';
33
import { lexicalGrammar } from './lib/config/ConfigLexer.js';
44
import ConfigParser from './lib/config/ConfigParser.js';
5+
import interpreter from './lib/config/ConfigInterpreter.js';
56
import util from 'util';
67

78
const lexer = new Lexer(lexicalGrammar);

0 commit comments

Comments
 (0)