Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP:Update regex grammar for the special character #119

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions grammar.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ attr
path = i:identifierName { return { type: 'literal', value: i }; }
type = "type(" _ t:[^ )]+ _ ")" { return { type: 'type', value: t.join('') }; }
flags = [imsu]+
regex = "/" d:[^/]+ "/" flgs:flags? { return {
type: 'regexp', value: new RegExp(d.join(''), flgs ? flgs.join('') : '') };
regex = "/" pattern:$RegularExpressionBody "/" flgs:flags? { return {
type: 'regexp', value: new RegExp(pattern, flgs ? flgs.join('') : '') };
}

field = "." i:identifierName is:("." identifierName)* {
Expand All @@ -107,3 +107,35 @@ nthLastChild = ":nth-last-child(" _ n:[0-9]+ _ ")" { return nthLast(parseInt(n.j
class = ":" c:("statement"i / "expression"i / "declaration"i / "function"i / "pattern"i) {
return { type: 'class', name: c };
}

RegularExpressionBody
= RegularExpressionFirstChar RegularExpressionChar*

RegularExpressionFirstChar
= ![*\\/[] RegularExpressionNonTerminator
/ RegularExpressionBackslashSequence
/ RegularExpressionClass

RegularExpressionChar
= ![\\/[] RegularExpressionNonTerminator
/ RegularExpressionBackslashSequence
/ RegularExpressionClass

RegularExpressionBackslashSequence
= "\\" RegularExpressionNonTerminator

RegularExpressionNonTerminator
= !LineTerminator SourceCharacter

RegularExpressionClass
= "[" RegularExpressionClassChar* "]"

RegularExpressionClassChar
= ![\]\\] RegularExpressionNonTerminator
/ RegularExpressionBackslashSequence

LineTerminator
= [\n\r\u2028\u2029]

SourceCharacter
= .