Compare commits

...

4 Commits

Author SHA1 Message Date
Johan Commelin
f83f8d9c60 add example of git conflict test 2024-10-18 05:47:05 +02:00
Kyle Miller
cd53aa51b1 enable parser.git.useIncoming 2024-10-02 12:26:37 +10:00
Kim Morrison
fa5534cc7a chore: update stage0 2024-10-02 12:26:37 +10:00
Kyle Miller
4fcbc1be07 hack implementation for experiment
makes git conflict notation act as a comment

needs stage0 update to get option to control incoming/current
2024-10-02 12:23:59 +10:00
210 changed files with 102 additions and 1 deletions

View File

@@ -549,6 +549,56 @@ partial def finishCommentBlock (nesting : Nat) : ParserFn := fun c s =>
where
eoi s := s.mkUnexpectedError (pushMissing := pushMissingOnError) "unterminated comment"
def checkColZero (errorMsg : String) : ParserFn := fun c s =>
let pos := c.fileMap.toPosition s.pos
if pos.column = 0 then s
else s.mkError errorMsg
def parseStartDiff (errorMsg : String) : ParserFn :=
let p := satisfyFn (· == '<') errorMsg
andthenFn (checkColZero errorMsg)
(andthenFn p (andthenFn p (andthenFn p (andthenFn p (andthenFn p (andthenFn p (andthenFn p
(takeUntilFn (fun c => c = '\n')))))))))
def parseMidDiff (errorMsg : String) : ParserFn :=
let p := satisfyFn (· == '=') errorMsg
andthenFn (checkColZero errorMsg)
(andthenFn p (andthenFn p (andthenFn p (andthenFn p (andthenFn p (andthenFn p p))))))
partial def parseIncomingDiffBody : ParserFn := fun c s =>
let input := c.input
let i := s.pos
if h : input.atEnd i then s.mkUnexpectedError (pushMissing := false) "unterminated git conflict"
else
let s' := parseMidDiff "mid conflict" c s
if s'.hasError then
parseIncomingDiffBody c (s.next' input i h)
else
s'
def parseEndDiff (errorMsg : String) : ParserFn :=
let p := satisfyFn (· == '>') errorMsg
andthenFn (checkColZero errorMsg)
(andthenFn p (andthenFn p (andthenFn p (andthenFn p (andthenFn p (andthenFn p (andthenFn p
(takeUntilFn (fun c => c = '\n')))))))))
partial def parseOutgoingDiffBody : ParserFn := fun c s =>
let input := c.input
let i := s.pos
if h : input.atEnd i then s.mkUnexpectedError (pushMissing := false) "unterminated git conflict"
else
let s' := parseEndDiff "end conflict" c s
if s'.hasError then
parseOutgoingDiffBody c (s.next' input i h)
else
s'
register_builtin_option parser.git.useIncoming : Bool := {
defValue := true
group := "pp"
descr := "(parser) for git conflicts, when true parses only the incoming code, and when false parses only the current code"
}
/-- Consume whitespace and comments -/
partial def whitespace : ParserFn := fun c s =>
let input := c.input
@@ -575,7 +625,29 @@ partial def whitespace : ParserFn := fun c s =>
if curr == '-' || curr == '!' then s -- "/--" and "/-!" doc comment are actual tokens
else andthenFn (finishCommentBlock (pushMissingOnError := false) 1) whitespace c (s.next input i)
else s
else s
else
if parser.git.useIncoming.get c.options then
-- `<<<<<<< ... =======` and `>>>>>>>` are comments
let s' := parseStartDiff "start conflict" c s
if !s'.hasError then
(andthenFn parseIncomingDiffBody whitespace) c s'
else
let s' := parseEndDiff "end conflict" c s
if !s'.hasError then
whitespace c s'
else
s
else
-- `<<<<<<<` and `======= ... >>>>>>>` are comments
let s' := parseMidDiff "mid conflict" c s
if !s'.hasError then
(andthenFn parseOutgoingDiffBody whitespace) c s'
else
let s' := parseStartDiff "start conflict" c s
if !s'.hasError then
whitespace c s'
else
s
def mkEmptySubstringAt (s : String) (p : String.Pos) : Substring := {
str := s, startPos := p, stopPos := p

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
stage0/stdlib/Init/Data/Option/Attach.c generated Normal file

Binary file not shown.

BIN
stage0/stdlib/Init/Data/Option/List.c generated Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More