mirror of
https://github.com/Ratstail91/sineQL.git
synced 2025-11-29 02:34:28 +11:00
26 lines
610 B
JavaScript
26 lines
610 B
JavaScript
//legal identifiers can only begin with letters or underscore - can contain numbers otherwise
|
|
const checkAlphaNumeric = (str) => {
|
|
if (!/^[_a-z][_a-z0-9]*$/i.test(str)) {
|
|
throw 'Unexpected string ' + str;
|
|
}
|
|
};
|
|
|
|
//eats a "block" from the tokens list
|
|
const eatBlock = (tokens, pos) => {
|
|
while (tokens[pos++] && tokens[pos - 1] !== '}') {
|
|
if (tokens[pos] == '{') {
|
|
pos = eatBlock(tokens, pos);
|
|
}
|
|
}
|
|
|
|
if (tokens[pos - 1] !== '}') { //eat the final '}'
|
|
throw 'Expected \'}\' while eating block (found ' + tokens[pos - 1] + ')';
|
|
}
|
|
|
|
return pos;
|
|
};
|
|
|
|
module.exports = {
|
|
checkAlphaNumeric,
|
|
eatBlock,
|
|
} |