diff options
Diffstat (limited to 'src/parser')
| -rw-r--r-- | src/parser/index.ts | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/parser/index.ts b/src/parser/index.ts index a336b83..7f0e945 100644 --- a/src/parser/index.ts +++ b/src/parser/index.ts @@ -129,9 +129,22 @@ const stringLiteral: Parser<Literal> = mapTo( s => Literal.String(s.join('')), ) +const REGEX_FLAGS = ['m', 'g', 'i', 'd', 's', 'u', 'y'] +const regexDelimiter = prefixed(optional(matchChar('\\')), matchChar('/')) +const regexLiteral: Parser<Literal> = mapTo( + prefixed( + regexDelimiter, + pair( + manyTill(satisfyChar(_ => true), regexDelimiter), + many0(satisfyChar(c => REGEX_FLAGS.includes(c))) + ), + ), + ([rs, flags]) => Literal.RegExp(new RegExp(rs.join(''), flags.join(''))), +) + const literalP: Parser<Literal> = delimited( whitespaces0, - or([booleanLiteral, numberLiteral, stringLiteral]), + or([booleanLiteral, numberLiteral, stringLiteral, regexLiteral]), whitespaces0, ) |
