jsonc-simple-parser
Version:
A simple JSON parser that supports comments and optional trailing commas.
44 lines (43 loc) • 992 B
JavaScript
/* IMPORT */
import Context from '../tokenize/context.js';
import TokenizeTokens from '../tokenize/tokens.js';
/* HELPERS */
const Delete = (values) => {
Context.offset += values[0].length;
return '';
};
const Passthrough = (values) => {
const source = values.join('');
Context.offset += source.length;
return source;
};
const Unwrapped = (quasis, token) => {
return token;
};
Unwrapped.unwrapped = true;
/* MAIN */
const Tokens = {
...TokenizeTokens,
Passthrough,
Newline: Delete,
Whitespace: Delete,
CommentLine: Delete,
CommentBlock: Delete,
Comma: Unwrapped,
CommaTrailing: Delete,
Colon: Unwrapped,
Null: Unwrapped,
True: Unwrapped,
False: Unwrapped,
Number: Unwrapped,
String: Unwrapped,
ArrayOpen: Unwrapped,
ArrayClose: Unwrapped,
Array: Passthrough,
ObjectOpen: Unwrapped,
ObjectClose: Unwrapped,
Object: Passthrough,
Root: Passthrough
};
/* EXPORT */
export default Tokens;