23 lines
549 B
JavaScript
23 lines
549 B
JavaScript
/**
|
|
* Token wrapper around {@link ./shell-lex.js} used by aliases, parse, and exec.
|
|
*/
|
|
import { lexShellLine } from './shell-lex.js'
|
|
|
|
/**
|
|
* @typedef {{ q: 'u' | 's' | 'd', t: string }} ShellWordPart
|
|
*/
|
|
|
|
/**
|
|
* @typedef {{ type: 'word', value: string, parts: ShellWordPart[] } | { type: 'op', value: string }} Token
|
|
*/
|
|
|
|
/** @param {Token} t */
|
|
export function shellWordText(t) {
|
|
return t && t.type === 'word' ? t.value : ''
|
|
}
|
|
|
|
/** @param {string} line */
|
|
export function tokenize(line) {
|
|
return /** @type {Token[]} */ (lexShellLine(line))
|
|
}
|