@gulujs/toml
Version:
TOML parser and serializer
191 lines (174 loc) • 4.38 kB
JavaScript
export const RE_FIRST_CHARACTER = /^[ \t]*(?:([-\w'"])|(\[(?!\[))|(\[\[)|(#)|(?:(?:\r?\n)?$))/g;
export const RE_WHITESPACE_OR_COMMENT = /([ \t]*)(?:#(.*))?(?:\r?\n)?$/g;
/*
([ \t]*)
(?:
(?:(?<!'|")([\w-]+))
|
(?:'(.*?)')
|
(?:
"
(.*?)
(?:
(?:(?<!\\)")
|
(?:(?<=(?<!\\)(?:\\\\)+)")
)
)
)
(?:[ \t]*(?:\.|(?:(=)[ \t]*)))
*/
export const RE_KEY = /([ \t]*)(?:(?:(?<!'|")([\w-]+))|(?:'(.*?)')|(?:"(.*?)(?:(?:(?<!\\)")|(?:(?<=(?<!\\)(?:\\\\)+)"))))(?:[ \t]*(?:\.|(?:(=)[ \t]*)))/g;
export const RE_TABLE_KEY = /([ \t]*)(?:(?:(?<!'|")([\w-]+))|(?:'(.*?)')|(?:"(.*?)(?:(?:(?<!\\)")|(?:(?<=(?<!\\)(?:\\\\)+)"))))(?:[ \t]*(?:\.|(?:(\])[ \t]*)))/g;
export const RE_ARRAY_TABLE_KEY = /([ \t]*)(?:(?:(?<!'|")([\w-]+))|(?:'(.*?)')|(?:"(.*?)(?:(?:(?<!\\)")|(?:(?<=(?<!\\)(?:\\\\)+)"))))(?:[ \t]*(?:\.|(?:(\]\])[ \t]*)))/g;
export const RE_INVALID_CHARACTER_WITHOUT_REPLACEMENT_CHARACTER = /[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F]|(?:\u000D(?!\u000A))/g;
export const RE_INVALID_CHARACTER_WITH_REPLACEMENT_CHARACTER = /[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F\uFFFD]|(?:\u000D(?!\u000A))/g;
export const RE_ESCAPE_CHARACTER = /\\\\|\\b|\\t|\\n|\\f|\\r|\\"|\\u([\da-fA-F]{4})|\\U([\da-fA-F]{8})|\\./g;
export const ESCAPE_CHARACTER_MAP = {
'\\\\': '\\',
'\\b': '\b',
'\\t': '\t',
'\\n': '\n',
'\\f': '\f',
'\\r': '\r',
'\\"': '"'
};
export const RE_BOOLEAN = /[ \t]*(true|false)(?=.|(?:\r?\n)|$)/g;
/*
([ \t]*)
([-+]?)
(?:
(?:0x(?:0+_?)*((?:[\da-fA-F]+_)*[\da-fA-F]+)(?=[^\da-fA-F]|$))
|
(?:0o(?:0+_?)*((?:[0-7]+_)*[0-7]+)(?=[^0-7]|$))
|
(?:0b(?:0+_?)*((?:[01]+_)*[01]+)(?=[^01]|$))
|
(?:((?:0+_?)*)((?:\d+_)*\d+)(?=[^\d]|$))
)
*/
export const RE_INTEGER = /([ \t]*)([-+]?)(?:(?:0x(?:0+_?)*((?:[\da-fA-F]+_)*[\da-fA-F]+)(?=[^\da-fA-F]|$))|(?:0o(?:0+_?)*((?:[0-7]+_)*[0-7]+)(?=[^0-7]|$))|(?:0b(?:0+_?)*((?:[01]+_)*[01]+)(?=[^01]|$))|(?:((?:0+_?)*)((?:\d+_)*\d+)(?=[^\d]|$)))/g;
/*
([ \t]*)
(?:
(
[-+]?
((?:0+_?)*)
(?:\d+_)*\d+
(?:
(?:
(?:\.(?:\d+_)*\d+)
(?:[eE][-+]?(?:\d+_)*\d+)?
)
|
(?:[eE][-+]?(?:\d+_)*\d+)
)
(?=[^\d]|$)
)
|
([-+]?inf(?=.|(?:\r?\n)|$))
|
([-+]?nan(?=.|(?:\r?\n)|$))
)
*/
export const RE_FLOAT = /([ \t]*)(?:([-+]?((?:0+_?)*)(?:\d+_)*\d+(?:(?:(?:\.(?:\d+_)*\d+)(?:[eE][-+]?(?:\d+_)*\d+)?)|(?:[eE][-+]?(?:\d+_)*\d+))(?=[^\d]|$))|([-+]?inf(?=.|(?:\r?\n)|$))|([-+]?nan(?=.|(?:\r?\n)|$)))/g;
/*
([ \t]*)
(?:
(
\d{4}-\d{2}-\d{2}
(
[tT ]
(\d{2}):\d{2}:\d{2}
(?:\.\d+)?
(
[zZ]
|
(?:[-+]\d{2}:\d{2})
)?
)?
)
|
(
\d{2}:\d{2}:\d{2}
(?:\.\d+)?
)
)
(?=.|(?:\r?\n)|$)
*/
export const RE_DATETIME = /([ \t]*)(?:(\d{4}-\d{2}-\d{2}([tT ](\d{2}):\d{2}:\d{2}(?:\.\d+)?([zZ]|(?:[-+]\d{2}:\d{2}))?)?)|(\d{2}:\d{2}:\d{2}(?:\.\d+)?))(?=.|(?:\r?\n)|$)/g;
export const RE_THREE_SINGLE_QUOTES = /([ \t]*''')(.*?)(?:(''')|(?:(\r?\n)?$))/g;
export const RE_THREE_SINGLE_QUOTES_END = /^(.*?)'''/g;
/*
([ \t]*""")
(.*?)
(?:
(
(?:(?<!\\)""")
|
(?:(?<=(?<!\\)(?:\\\\)+)""")
)
|
(?:
(
(?:(?<!\\)\\)
|
(?:(?<=(?<!\\)(?:\\\\)+)\\)
)?
([ \t]*\r?\n)?$
)
)
*/
export const RE_THREE_DOUBLE_QUOTES = /([ \t]*""")(.*?)(?:((?:(?<!\\)""")|(?:(?<=(?<!\\)(?:\\\\)+)"""))|(?:((?:(?<!\\)\\)|(?:(?<=(?<!\\)(?:\\\\)+)\\))?([ \t]*\r?\n)?$))/g;
/*
^([ \t]*)
(.*?)
(?:
(
(?:(?<!\\)""")
|
(?:(?<=(?<!\\)(?:\\\\)+)""")
)
|
(?:
(
(?:(?<!\\)\\)
|
(?:(?<=(?<!\\)(?:\\\\)+)\\)
)?
([ \t]*\r?\n)?$
)
)
*/
export const RE_THREE_DOUBLE_QUOTES_END = /^([ \t]*)(.*?)(?:((?:(?<!\\)""")|(?:(?<=(?<!\\)(?:\\\\)+)"""))|(?:((?:(?<!\\)\\)|(?:(?<=(?<!\\)(?:\\\\)+)\\))?([ \t]*\r?\n)?$))/g;
export const RE_ONE_QUOTE = /([ \t]*)(?:(?:'(.*?)')|(?:"(.*?)(?:(?:(?<!\\)")|(?:(?<=(?<!\\)(?:\\\\)+)"))))/g;
export const RE_INLINE_TABLE_START = /[ \t]*{/g;
export const RE_INLINE_TABLE_END = /[ \t]*(,|})/g;
export const RE_ARRAY_START = /[ \t]*\[/g;
/*
[ \t]*
(?:
(])
|
(?:
(,)?
[ \t]*
(?:#(.*))?
(\r?\n)?
)
)
*/
export const RE_ARRAY_END_OR_CONTINUE = /[ \t]*(?:(])|(?:(,)?[ \t]*(?:#(.*))?(\r?\n)?))/g;
/*
([ \t]*)
(?:
(])
|
(?:
(?:#(.*))?
(\r?\n)?$
)
)
*/
export const RE_ARRAY_END_ONLY = /([ \t]*)(?:(])|(?:(?:#(.*))?(\r?\n)?$))/g;