Skip to content
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
= .