add array declarations

This commit is contained in:
Kurt Hutten IrevDev
2022-12-30 21:53:50 +11:00
parent f6c4250947
commit 3d6f5982c2
8 changed files with 253 additions and 3 deletions

View File

@ -12,6 +12,8 @@ const BLOCK_START = /^\{/
const BLOCK_END = /^\}/
const PARAN_START = /^\(/
const PARAN_END = /^\)/
const ARRAY_START = /^\[/
const ARRAY_END = /^\]/
const COMMA = /^,/
export const isNumber = (character: string) => NUMBER.test(character)
@ -23,6 +25,8 @@ export const isBlockStart = (character: string) => BLOCK_START.test(character)
export const isBlockEnd = (character: string) => BLOCK_END.test(character)
export const isParanStart = (character: string) => PARAN_START.test(character)
export const isParanEnd = (character: string) => PARAN_END.test(character)
export const isArrayStart = (character: string) => ARRAY_START.test(character)
export const isArrayEnd = (character: string) => ARRAY_END.test(character)
export const isComma = (character: string) => COMMA.test(character)
function matchFirst(str: string, regex: RegExp) {
@ -75,6 +79,12 @@ const returnTokenAtIndex = (str: string, startIndex: number): Token | null => {
if (isBlockEnd(strFromIndex)) {
return makeToken('brace', matchFirst(strFromIndex, BLOCK_END), startIndex)
}
if (isArrayStart(strFromIndex)) {
return makeToken('brace', matchFirst(strFromIndex, ARRAY_START), startIndex)
}
if (isArrayEnd(strFromIndex)) {
return makeToken('brace', matchFirst(strFromIndex, ARRAY_END), startIndex)
}
if (isComma(strFromIndex)) {
return makeToken('comma', matchFirst(strFromIndex, COMMA), startIndex)
}