* Returns the expanded macro as a reversed array of tokens and a macro * argument count. Or returns `null` if no such macro.
(name)
| 14120 | |
| 14121 | |
| 14122 | _getExpansion(name) { |
| 14123 | const definition = this.macros.get(name); |
| 14124 | |
| 14125 | if (definition == null) { |
| 14126 | // mainly checking for undefined here |
| 14127 | return definition; |
| 14128 | } |
| 14129 | |
| 14130 | const expansion = typeof definition === "function" ? definition(this) : definition; |
| 14131 | |
| 14132 | if (typeof expansion === "string") { |
| 14133 | let numArgs = 0; |
| 14134 | |
| 14135 | if (expansion.indexOf("#") !== -1) { |
| 14136 | const stripped = expansion.replace(/##/g, ""); |
| 14137 | |
| 14138 | while (stripped.indexOf("#" + (numArgs + 1)) !== -1) { |
| 14139 | ++numArgs; |
| 14140 | } |
| 14141 | } |
| 14142 | |
| 14143 | const bodyLexer = new Lexer(expansion, this.settings); |
| 14144 | const tokens = []; |
| 14145 | let tok = bodyLexer.lex(); |
| 14146 | |
| 14147 | while (tok.text !== "EOF") { |
| 14148 | tokens.push(tok); |
| 14149 | tok = bodyLexer.lex(); |
| 14150 | } |
| 14151 | |
| 14152 | tokens.reverse(); // to fit in with stack using push and pop |
| 14153 | |
| 14154 | const expanded = { |
| 14155 | tokens, |
| 14156 | numArgs |
| 14157 | }; |
| 14158 | return expanded; |
| 14159 | } |
| 14160 | |
| 14161 | return expansion; |
| 14162 | } |
| 14163 | /** |
| 14164 | * Determine whether a command is currently "defined" (has some |
| 14165 | * functionality), meaning that it's a macro (in the current group), |
no test coverage detected