Parses the source until the first occurence of delimiter which is not in a string or a comment.
If ignoreLineComment is true, it will still count if the delimiter occurs in a line comment.
If ignoreNesting is true, it will stop at the first bracket, not taking into account if the bracket part of nesting or not. See example above.
It returns an object with the structure:
start: 0,//index of first character ofstringend: 13,//index of first character after the endofstring
src: 'source string'
parseChar(character, state = defaultState())
Parses the single character and returns the state. See parse for the structure of the returned state object. N.B. character must be a single character not a multi character string.
Get a default starting state.
TOKEN_TYPES & BRACKETS
Objects whose values can be a frame in the stack property of a State (documented below).
A state is an object with the following structure
stack: , // stack of detected brackets; the outermost is regexpStart: false, // true if a slash is just encountered and a REGEXP state has just been added to the stackescaped: false, // true if in a string and the last character was an escape characterhasDollar: false, // true if in a template string and the last character was a dollar signsrc: '', // the concatenated source stringhistory: '', // reversed `src`lastChar: ''// last parsed character
stack property can contain any of the following:
Any of the property values of characterParser.TOKEN_TYPES
Any of the property values of characterParser.BRACKETS (the end bracket, not the starting bracket)
It also has the following useful methods:
.current() returns the innermost bracket (i.e. the last stack frame).
.isString() returns true if the current location is inside a string.
.isComment() returns true if the current location is inside a comment.
.isNesting([opts]) returns true if the current location is not at the top level, i.e. if the stack is not empty. If opts.ignoreLineComment is true, line comments are not counted as a level, so for // a it will still return false.
All errors thrown by character-parser has a code property attached to it that allows one to identify what sort of error is thrown. For errors thrown from parse and parseUntil, an additional index property is available.
Transition from v1
In [email protected], we have changed the APIs quite a bit. These are some notes that will help you transition to the new version.
State Object Changes
Instead of keeping depths of different brackets, we are now keeping a stack. We also removed some properties: