Compile backtick commands as __command() calls with ${} interpolation

Backtick expressions now compile as calls to a global __command()
function instead of being treated as plain strings. Interpolation
via ${expr} is supported, with each interpolated value wrapped in
tostring() for type safety. Commands are parsed in primaryexp so
suffix operations like `.stdout` work directly.

Adds a stub __command that returns {code, stdout, stderr} for testing
until the real implementation (issue #03).
This commit is contained in:
Cormac Shannon
2026-02-19 20:00:15 +00:00
parent db6f39a2a4
commit a773398cab
4 changed files with 239 additions and 5 deletions

6
llex.h
View File

@@ -39,7 +39,9 @@ enum RESERVED {
TK_IDIV, TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE,
TK_SHL, TK_SHR,
TK_DBCOLON, TK_EOS,
TK_FLT, TK_INT, TK_NAME, TK_STRING
TK_FLT, TK_INT, TK_NAME, TK_STRING,
TK_COMMAND,
TK_COMMAND_INTERP
};
/* number of reserved words */
@@ -77,6 +79,7 @@ typedef struct LexState {
TString *envn; /* environment variable name */
TString *brkn; /* "break" name (used as a label) */
TString *glbn; /* "global" name (when not a reserved word) */
lu_byte in_command; /* nonzero when continuing a backtick string after ${} */
} LexState;
@@ -88,6 +91,7 @@ LUAI_FUNC void luaX_next (LexState *ls);
LUAI_FUNC int luaX_lookahead (LexState *ls);
LUAI_FUNC l_noret luaX_syntaxerror (LexState *ls, const char *s);
LUAI_FUNC const char *luaX_token2str (LexState *ls, int token);
LUAI_FUNC int luaX_readcommandcont (LexState *ls);
#endif