github.com/aretext/aretext@v1.3.0/syntax/languages/gitrebase.go (about) 1 package languages 2 3 import ( 4 "unicode" 5 6 "github.com/aretext/aretext/syntax/parser" 7 ) 8 9 // GitRebaseParseFunc parses a git rebase. 10 func GitRebaseParseFunc() parser.Func { 11 keywords := []string{ 12 "pick", "reword", "edit", "squash", "fixup", 13 "exec", "break", "drop", "label", "reset", "merge", 14 "p", "r", "e", "s", "f", "e", "b", "d", "l", "t", "m", 15 } 16 17 isAlphaNumPunct := func(r rune) bool { 18 return unicode.IsLetter(r) || unicode.IsDigit(r) || unicode.IsPunct(r) 19 } 20 21 return consumeRunesLike(isAlphaNumPunct). 22 MapWithInput(recognizeKeywordOrConsume(keywords)). 23 Map(func(result parser.Result) parser.Result { 24 if len(result.ComputedTokens) == 0 { 25 // Fail if we didn't recognize a token so the parser 26 // falls back to the git commit parser. 27 return parser.FailedResult 28 } 29 return result 30 }). 31 Or(GitCommitParseFunc()) 32 }