1 | var List = require('../common/List');
|
---|
2 | var SyntaxError = require('../common/SyntaxError');
|
---|
3 | var TokenStream = require('../common/TokenStream');
|
---|
4 | var Lexer = require('../lexer/Lexer');
|
---|
5 | var definitionSyntax = require('../definition-syntax');
|
---|
6 | var tokenize = require('../tokenizer');
|
---|
7 | var createParser = require('../parser/create');
|
---|
8 | var createGenerator = require('../generator/create');
|
---|
9 | var createConvertor = require('../convertor/create');
|
---|
10 | var createWalker = require('../walker/create');
|
---|
11 | var clone = require('../utils/clone');
|
---|
12 | var names = require('../utils/names');
|
---|
13 | var mix = require('./config/mix');
|
---|
14 |
|
---|
15 | function createSyntax(config) {
|
---|
16 | var parse = createParser(config);
|
---|
17 | var walk = createWalker(config);
|
---|
18 | var generate = createGenerator(config);
|
---|
19 | var convert = createConvertor(walk);
|
---|
20 |
|
---|
21 | var syntax = {
|
---|
22 | List: List,
|
---|
23 | SyntaxError: SyntaxError,
|
---|
24 | TokenStream: TokenStream,
|
---|
25 | Lexer: Lexer,
|
---|
26 |
|
---|
27 | vendorPrefix: names.vendorPrefix,
|
---|
28 | keyword: names.keyword,
|
---|
29 | property: names.property,
|
---|
30 | isCustomProperty: names.isCustomProperty,
|
---|
31 |
|
---|
32 | definitionSyntax: definitionSyntax,
|
---|
33 | lexer: null,
|
---|
34 | createLexer: function(config) {
|
---|
35 | return new Lexer(config, syntax, syntax.lexer.structure);
|
---|
36 | },
|
---|
37 |
|
---|
38 | tokenize: tokenize,
|
---|
39 | parse: parse,
|
---|
40 | walk: walk,
|
---|
41 | generate: generate,
|
---|
42 |
|
---|
43 | find: walk.find,
|
---|
44 | findLast: walk.findLast,
|
---|
45 | findAll: walk.findAll,
|
---|
46 |
|
---|
47 | clone: clone,
|
---|
48 | fromPlainObject: convert.fromPlainObject,
|
---|
49 | toPlainObject: convert.toPlainObject,
|
---|
50 |
|
---|
51 | createSyntax: function(config) {
|
---|
52 | return createSyntax(mix({}, config));
|
---|
53 | },
|
---|
54 | fork: function(extension) {
|
---|
55 | var base = mix({}, config); // copy of config
|
---|
56 | return createSyntax(
|
---|
57 | typeof extension === 'function'
|
---|
58 | ? extension(base, Object.assign)
|
---|
59 | : mix(base, extension)
|
---|
60 | );
|
---|
61 | }
|
---|
62 | };
|
---|
63 |
|
---|
64 | syntax.lexer = new Lexer({
|
---|
65 | generic: true,
|
---|
66 | types: config.types,
|
---|
67 | atrules: config.atrules,
|
---|
68 | properties: config.properties,
|
---|
69 | node: config.node
|
---|
70 | }, syntax);
|
---|
71 |
|
---|
72 | return syntax;
|
---|
73 | };
|
---|
74 |
|
---|
75 | exports.create = function(config) {
|
---|
76 | return createSyntax(mix({}, config));
|
---|
77 | };
|
---|