Documentation
¶
Overview ¶
Package parser implements a parser for mexdown source. It takes in an io.Reader as input and outputs an *ast.File.
It is the responsibility of the generator to parse commands attached to directive nodes.
The parser adheres to the following grammar for mexdown source files:
unicode_char = /* an arbitrary Unicode code point except newline */ .
newline = /* the Unicode code point U+000A */ .
tab = /* the Unicode code point U+0009 */ .
octothorpe = /* the Unicode code point U+0023 */ .
backtick = /* the Unicode code point U+0060 */ .
hyphen = /* the Unicode code point U+002D */ .
asterisk = /* the Unicode code point U+002A */ .
lbrack = /* the Unicode code point U+005B */ .
rbrack = /* the Unicode code point U+005D */ .
lparen = /* the Unicode code point U+0028 */ .
rparen = /* the Unicode code point U+0029 */ .
underscore = /* the Unicode code point U+005F */ .
colon = /* the Unicode code point U+003A */ .
citation = lbrack text rbrack colon string .
paragraph = text .
list_item = { tab } hyphen [ lbrack text rbrack ] text .
list = { list_item newline } [ list_item ] .
string = { unicode_char | newline } .
command = unicode_char { unicode_char } .
dirbody = backtick dirbody backtick | [ command ] newline string .
directive = backtick backtick backtick dirbody backtick backtick backtick .
text = unicode_char { unicode_char } |
lbrack text rbrack lparen text rparen |
asterisk text asterisk |
asterisk asterisk text asterisk asterisk |
underscore text underscore |
hyphen hyphen text hyphen hyphen |
backtick text backtick .
header = octothorpe { octothorpe } text .
statement = header | directive | list | paragraph | citation .
source_file = { statement [ newline ] [ newline ] } .
In the relevant context, the following characters are escaped (in Go syntax):
'\\', '#', '`', '-', '*', '[', ']', '(', ')', '_'
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MustParse ¶
MustParse is like Parse but panics if the source cannot be parsed.
Example ¶
package main
import (
"fmt"
"strings"
"akhil.cc/mexdown/ast"
"akhil.cc/mexdown/parser"
)
func main() {
src := `# Favorite Hobbits
- Frodo
- Samwise
- Bilbo
- Merry
- Pippin
`
file := parser.MustParse(strings.NewReader(src))
for _, stmt := range file.List {
switch t := stmt.(type) {
case *ast.Header:
fmt.Println(t.Text.Body)
case *ast.List:
for _, item := range t.Items {
fmt.Println(item.Text.Body)
}
}
}
}
Output: Favorite Hobbits Frodo Samwise Bilbo Merry Pippin
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.