add object declarations
This commit is contained in:
@ -15,6 +15,7 @@ const PARAN_END = /^\)/
|
||||
const ARRAY_START = /^\[/
|
||||
const ARRAY_END = /^\]/
|
||||
const COMMA = /^,/
|
||||
const COLON = /^:/
|
||||
|
||||
export const isNumber = (character: string) => NUMBER.test(character)
|
||||
export const isWhitespace = (character: string) => WHITESPACE.test(character)
|
||||
@ -28,6 +29,7 @@ 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)
|
||||
export const isColon = (character: string) => COLON.test(character)
|
||||
|
||||
function matchFirst(str: string, regex: RegExp) {
|
||||
const theMatch = str.match(regex)
|
||||
@ -46,6 +48,7 @@ export interface Token {
|
||||
| 'brace'
|
||||
| 'whitespace'
|
||||
| 'comma'
|
||||
| 'colon'
|
||||
value: string
|
||||
start: number
|
||||
end: number
|
||||
@ -97,6 +100,9 @@ const returnTokenAtIndex = (str: string, startIndex: number): Token | null => {
|
||||
if (isWord(strFromIndex)) {
|
||||
return makeToken('word', matchFirst(strFromIndex, WORD), startIndex)
|
||||
}
|
||||
if (isColon(strFromIndex)) {
|
||||
return makeToken('colon', matchFirst(strFromIndex, COLON), startIndex)
|
||||
}
|
||||
if (isWhitespace(strFromIndex)) {
|
||||
return makeToken(
|
||||
'whitespace',
|
||||
|
Reference in New Issue
Block a user