Fixed PKG_EXECPATH bug and added include directive
This commit is contained in:
parent
5063197c0b
commit
5cf2d8251b
5
cli.mjs
5
cli.mjs
@ -71,8 +71,11 @@ await new Promise((resolve, reject) => {
|
|||||||
|
|
||||||
// Spawn child process to execute script
|
// Spawn child process to execute script
|
||||||
let child = spawn(
|
let child = spawn(
|
||||||
|
'/usr/bin/env', [
|
||||||
|
'-u', 'PKG_EXECPATH',
|
||||||
path,
|
path,
|
||||||
scriptArgs, {
|
...scriptArgs
|
||||||
|
], {
|
||||||
stdio: 'inherit',
|
stdio: 'inherit',
|
||||||
argv0: fileName
|
argv0: fileName
|
||||||
}
|
}
|
||||||
|
@ -37,9 +37,9 @@ export class CharacterStream {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Peek first character after any characters that match predicate
|
// Peek first character after any characters that match predicate
|
||||||
peekAfter(predicate) {
|
peekAfter(predicate, length = 1) {
|
||||||
const skip = this.peekWhile(predicate);
|
const skip = this.peekWhile(predicate);
|
||||||
return this.peek(skip.length + 1).substring(skip.length);
|
return this.peek(skip.length + length).substring(skip.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
isNext(str) {
|
isNext(str) {
|
||||||
|
@ -45,6 +45,9 @@ export class TemplateEngine {
|
|||||||
case 'comment':
|
case 'comment':
|
||||||
buffer += this._renderComment(token.value);
|
buffer += this._renderComment(token.value);
|
||||||
break;
|
break;
|
||||||
|
case 'source':
|
||||||
|
buffer += this._renderSource(token.value);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error(`Unrecognized token: ${token.type}`);
|
throw new Error(`Unrecognized token: ${token.type}`);
|
||||||
}
|
}
|
||||||
@ -61,6 +64,10 @@ export class TemplateEngine {
|
|||||||
return `# ${value}\n`;
|
return `# ${value}\n`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_renderSource(value) {
|
||||||
|
return `source <(n0m -c "${value.trim()}")\n`;
|
||||||
|
}
|
||||||
|
|
||||||
_renderStatement(value) {
|
_renderStatement(value) {
|
||||||
return `${value}\n`;
|
return `${value}\n`;
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ export class TokenStream {
|
|||||||
static CLOSE_INLINE_STATEMENT_UNESCAPED = '%>';
|
static CLOSE_INLINE_STATEMENT_UNESCAPED = '%>';
|
||||||
static STATEMENT = '$';
|
static STATEMENT = '$';
|
||||||
static COMMENT = '#';
|
static COMMENT = '#';
|
||||||
|
static SOURCE = '.INCLUDE';
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.reset();
|
this.reset();
|
||||||
@ -73,7 +74,8 @@ export class TokenStream {
|
|||||||
TokenStream.OPEN_INLINE_STATEMENT,
|
TokenStream.OPEN_INLINE_STATEMENT,
|
||||||
TokenStream.OPEN_INLINE_STATEMENT_UNESCAPED,
|
TokenStream.OPEN_INLINE_STATEMENT_UNESCAPED,
|
||||||
TokenStream.STATEMENT,
|
TokenStream.STATEMENT,
|
||||||
TokenStream.COMMENT
|
TokenStream.COMMENT,
|
||||||
|
TokenStream.SOURCE
|
||||||
])) {
|
])) {
|
||||||
// Skip escape
|
// Skip escape
|
||||||
this._cs.next(TokenStream.ESCAPE.length);
|
this._cs.next(TokenStream.ESCAPE.length);
|
||||||
@ -89,16 +91,12 @@ export class TokenStream {
|
|||||||
return flushRaw() || this._readInlineStatement();
|
return flushRaw() || this._readInlineStatement();
|
||||||
} else if (this._cs.isNext(TokenStream.OPEN_INLINE_STATEMENT_UNESCAPED)) {
|
} else if (this._cs.isNext(TokenStream.OPEN_INLINE_STATEMENT_UNESCAPED)) {
|
||||||
return flushRaw() || this._readInlineStatementUnescaped();
|
return flushRaw() || this._readInlineStatementUnescaped();
|
||||||
} else if (
|
} else if (this._matchFullLine(TokenStream.STATEMENT)) {
|
||||||
this._cs.column === 0 &&
|
|
||||||
this._cs.peekAfter(this._isSpace) === TokenStream.STATEMENT
|
|
||||||
) {
|
|
||||||
return flushRaw() || this._readStatement();
|
return flushRaw() || this._readStatement();
|
||||||
} else if (
|
} else if (this._matchFullLine(TokenStream.COMMENT)) {
|
||||||
this._cs.column === 0 &&
|
|
||||||
this._cs.peekAfter(this._isSpace) === TokenStream.COMMENT
|
|
||||||
) {
|
|
||||||
return flushRaw() || this._readComment();
|
return flushRaw() || this._readComment();
|
||||||
|
} else if (this._matchFullLine(TokenStream.SOURCE)) {
|
||||||
|
return flushRaw() || this._readSource();
|
||||||
} else {
|
} else {
|
||||||
raw += this._cs.next();
|
raw += this._cs.next();
|
||||||
}
|
}
|
||||||
@ -248,6 +246,13 @@ export class TokenStream {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_readSource() {
|
||||||
|
return this._readFullLineGeneric(
|
||||||
|
'source',
|
||||||
|
TokenStream.SOURCE
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Utility methods
|
// Utility methods
|
||||||
_isSpace(c) {
|
_isSpace(c) {
|
||||||
return /[^\S\r\n]/.test(c);
|
return /[^\S\r\n]/.test(c);
|
||||||
@ -260,4 +265,11 @@ export class TokenStream {
|
|||||||
this._cs.isNext(TokenStream.ESCAPE + tag)
|
this._cs.isNext(TokenStream.ESCAPE + tag)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_matchFullLine(tag) {
|
||||||
|
return (
|
||||||
|
this._cs.column === 0 &&
|
||||||
|
this._cs.peekAfter(this._isSpace, tag.length) === tag
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user