File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -81,15 +81,24 @@ def fromExpr (expr : Expr) : Regex :=
8181 { nfa := nfa, wf := Regex.NFA.compile_wf, optimizationInfo := optimizationInfo }
8282
8383/--
84- Parses a regular expression string into a `Regex` structure.
85-
84+ Parses a regular expression string into a `Regex` structure with options.
8685* `s`: The regular expression string to parse
86+ * `options`: Parsing options
8787* Returns: Either a compiled `Regex` or a parsing error
8888 -/
89- def parse (s : String) : Except Regex.Syntax.Parser.Error Regex := do
90- let expr ← Regex.Syntax.Parser.parse s
89+ def parseAux (s : String) (options : Regex.Syntax.Parser.ParseOption ) : Except Regex.Syntax.Parser.Error Regex := do
90+ let expr ← Regex.Syntax.Parser.parseAux s options
9191 return Regex.fromExpr expr
9292
93+ /--
94+ Parses a regular expression string into a `Regex` structure with default options.
95+
96+ * `s`: The regular expression string to parse
97+ * Returns: Either a compiled `Regex` or a parsing error
98+ -/
99+ def parse (s : String) : Except Regex.Syntax.Parser.Error Regex :=
100+ parseAux s {}
101+
93102/--
94103Parses a regular expression string into a `Regex` structure, panicking on parse error.
95104
Original file line number Diff line number Diff line change @@ -333,14 +333,19 @@ termination_by (pos, 100)
333333
334334end
335335
336+ structure ParseOption where
337+ caseInsensitive : Bool := false
338+
336339def parseAst (input : String) : Except Error Ast :=
337340 regex input.startPos
338341 |>.complete .expectedEof
339342 |>.toExcept
340343
341- def parse (input : String) : Except Error Expr :=
344+ def parseAux (input : String) (options : ParseOption ) : Except Error Expr :=
342345 parseAst input
343- |>.map fun ast => Ast.toRegex (.group ast)
346+ |>.map fun ast => Ast.toRegexAux (ToRegexState.mk 0 options.caseInsensitive) (.group ast) |>.2
347+
348+ def parse (input : String) : Except Error Expr := parseAux input {}
344349
345350def parse! (input : String) : Expr :=
346351 match parse input with
You can’t perform that action at this time.
0 commit comments