Skip to content

Commit

Permalink
refactor: extract handling ignore pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
Seasawher committed Oct 6, 2024
1 parent 9329da6 commit aa6a085
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions MkExercise/Extract.lean
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,31 @@ def findWhere (line : String) (tgt : String) : Option Nat := Id.run do
return some i
return none

/-- remove some content from the given content
and replace it with `sorry` -/
def extractExercise (lines : List String) : String := Id.run do
let mut listen := true
let mut content := ""
/-- handle ignore pattern -/
def filterIgnored (lines : List String) : List String := Id.run do
let mut result := []
let mut «--##--» := false
for line in lines do
-- ignore pattern for a line
if line.endsWith "--##" then
if line.trim.endsWith "--##" then
continue

-- ignore pattern for a block
if line.trim = "--##--" then
if line.trim.endsWith "--##--" then
«--##--» := ! «--##--»
continue
if «--##--» then
continue

result := line :: result
return result.reverse

/-- remove some content from the given content
and replace it with `sorry` -/
def extractExercise (lines : List String) : String := Id.run do
let lines := filterIgnored lines
let mut listen := true
let mut content := ""
for line in lines do
if let some index := findWhere line "-- sorry" then
listen := ! listen
if ! listen then
Expand Down

0 comments on commit aa6a085

Please sign in to comment.