mirror of
https://github.com/Ratstail91/sineQL.git
synced 2025-11-29 02:34:28 +11:00
Split the library into smaller files
This commit is contained in:
26
source/utils.js
Normal file
26
source/utils.js
Normal file
@@ -0,0 +1,26 @@
|
||||
//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,
|
||||
}
|
||||
Reference in New Issue
Block a user