sptc 0.0.26 → 0.0.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,6 +12,7 @@ const Tokens={
12
12
  T_UNDEF: '#undef',
13
13
 
14
14
  T_INCLUDE: '#include',
15
+ T_INCLUDE_ONCE: '#include_once',
15
16
 
16
17
  T_DEFINE: '#define',
17
18
  T_CALL_DEFINE: '@',
@@ -28,6 +29,7 @@ function lexer(content) {
28
29
  T_UNDEF,
29
30
 
30
31
  T_INCLUDE,
32
+ T_INCLUDE_ONCE,
31
33
 
32
34
  T_DEFINE,
33
35
  T_CALL_DEFINE,
@@ -42,6 +44,7 @@ function lexer(content) {
42
44
  T_IFNDEF,
43
45
  T_DEF,
44
46
  T_UNDEF,
47
+ T_INCLUDE_ONCE,
45
48
  T_INCLUDE,
46
49
  T_DEFINE,
47
50
  ].join('|')+')\\b)((?:\\s+).+)?|(.+)'
@@ -95,6 +98,7 @@ function transformToAst(tokens) {
95
98
  T_UNDEF,
96
99
 
97
100
  T_INCLUDE,
101
+ T_INCLUDE_ONCE,
98
102
 
99
103
  T_DEFINE,
100
104
  T_CALL_DEFINE,
@@ -148,10 +152,11 @@ function transformToAst(tokens) {
148
152
  type: O_UNDEF,
149
153
  def: x.tk_params,
150
154
  })
151
- }else if(x.tk===T_INCLUDE) {
155
+ }else if(x.tk===T_INCLUDE || x.tk===T_INCLUDE_ONCE) {
152
156
  Object.assign(d, {
153
157
  type: O_INCLUDE,
154
- include: x.tk_params,
158
+ include: x.tk_params.replace(/^"|\\"|"$/gi, ''),
159
+ once: x.tk===T_INCLUDE_ONCE,
155
160
  })
156
161
  }else if(x.tk===T_DEFINE) {
157
162
  const re_define_func=/^([A-Za-z\d_]+)\(([^)]+)\)\s+(.+)/
@@ -58,8 +58,12 @@ function execute(ctx, ast) {
58
58
  ctx.defs.delete(p.def)
59
59
  }else if(p.type===O_INCLUDE) {
60
60
  const filename=path.resolve(ctx.filename+'/..', p.include)
61
- const nctx=Object.assign({}, ctx, {filename})
62
- ret+=executeMacroContext(nctx)
61
+ if(!p.once || !ctx.include_files[filename]) {
62
+ const nctx=Object.assign({}, ctx, {filename})
63
+ ret+=executeMacroContext(nctx)
64
+ ctx.include_files=ctx.include_files || {}
65
+ ctx.include_files[filename]=true
66
+ }
63
67
  }else{
64
68
  throw new Error('unsupported node: '+JSON.stringify(p))
65
69
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sptc",
3
- "version": "0.0.26",
3
+ "version": "0.0.27",
4
4
  "description": "Simple Pretreat Toolkit CLI",
5
5
  "main": "engine/index.js",
6
6
  "engines": {