-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregex.ohm
61 lines (38 loc) · 1.35 KB
/
regex.ohm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
RegExp {
expression = "^"? (subExpression ( "|" subExpression )*)
subExpression = expressionItem*
expressionItem
= anchor
| group
| match
// | Backreference -- Not supported
group
= groupExpression
// | NamedGroupExpression -- Not supported
groupExpression = "(" "?:"? expression ")" quantifier?
// NamedGroupExpression = NamedGroupPrefix Expression ")" Quantifier?
match = matchItem quantifier?
matchItem = anyChar | matchCharacterClass | character
anyChar = "."
escapeCharacter = "\\"
specialCharacter = anyChar | "^" | "*" | "?" | "+" | "\\" | "[" | "]" | "(" | ")" | "\\\\" | "|"
characterClass = "\\w" | "\\W" | "\\d" | "\\D" | "\\s" | "\\S"
baseCharacter = ~specialCharacter any
character = escapeCharacter specialCharacter | escapeCharacter? baseCharacter
matchCharacterClass = characterGroup | characterClass
characterGroup = "[" "^"? characterGroupInner "]"
characterGroupInner = characterGroupItem*
characterGroupItem = characterClass | characterRange | character | anyChar
characterRange = characterRangeItem
characterRangeItem = alnum "-" alnum
anchor = "$"
quantifier = quantifierType "?"?
quantifierType
= "*"
| "+"
| "?"
| matchCount1
| matchCount2
matchCount1 = "{" digit+ "}"
matchCount2 = "{" (digit+)? "," (digit+)? "}"
}