Skip to content

Instantly share code, notes, and snippets.

@buoyad
Created August 7, 2017 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save buoyad/7ab3f245ebf141e16ed30b487a019af3 to your computer and use it in GitHub Desktop.
Save buoyad/7ab3f245ebf141e16ed30b487a019af3 to your computer and use it in GitHub Desktop.
Code example for keybase.io
func lexText(l *lexer) stateFn {
/* What are we looking at right now? */
s := l.input[l.pos:]
if hp(s, atxHeader) {
return lexAtxHeader
} else if hp(s, ul0) || hp(s, ul2) {
return lexHr
} else if hp(s, ul1) && s[1] == ' ' {
l.acceptRun(" " + string(ul1))
return lexUl
} else if hp(s, ol) && s[2] == ' ' {
return lexOl
}
l.acceptUntilNewLine()
lexTextNewLine(l)
// Cursor now immediately after newline
/* What were we just looking at? */
l.acceptRun(" ") // Ignore leading spaces
s = l.input[l.pos:] // Start checking line contents
if hp(s, setTextHeader1) || hp(s, setTextHeader2) { // Previous line was setTextheader
l.acceptRun(string(setTextHeader1) + string(setTextHeader2) + " ") // Accept all ='s, -'s and trailing spaces
if !hp(l.input[l.pos:], br) { // settext header stuff has trailing chars
l.acceptUntilNewLine()
lexTextNewLine(l)
return lexText
}
// valid settext header declaration
l.emit(itemSetTextHeader)
l.nextNTimes(len(br))
l.ignore()
l.emit(itemNewLine)
}
return lexText
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment