This repository has been archived by the owner on Mar 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 41eaa83
Showing
15 changed files
with
4,239 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
!* | ||
*.test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (C) 2014 The go-rst Authors | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
of the Software, and to permit persons to whom the Software is furnished to do | ||
so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
================================ | ||
go-rst - reStructuredText for Go | ||
================================ | ||
|
||
A reStructuredText parser written in Go. | ||
|
||
============ | ||
Contributors | ||
============ | ||
|
||
Jesus Alvarez |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// go-rst - A reStructuredText parser for Go | ||
// 2014 (c) The go-rst Authors | ||
// MIT Licensed. See LICENSE for details. | ||
package rst | ||
|
||
import ( | ||
"github.com/demizer/go-rst/parse" | ||
) | ||
|
||
type Document struct { | ||
name string | ||
*parse.Tree | ||
} | ||
|
||
func New(name string) *Document { | ||
|
||
return &Document{ | ||
name: name, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// go-rst - A reStructuredText parser for Go | ||
// 2014 (c) The go-rst Authors | ||
// MIT Licensed. See LICENSE for details. | ||
package rst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// go-rst - A reStructuredText parser for Go | ||
// 2014 (c) The go-rst Authors | ||
// MIT Licensed. See LICENSE for details. | ||
package parse | ||
|
||
type itemElements int | ||
|
||
const ( | ||
itemEOF itemElements = iota | ||
itemBodyParagraph | ||
itemBodyText | ||
itemBodyInlineEmphasis | ||
itemBodyInlineStrong | ||
itemBodyInlineInterpreted | ||
itemBodyInlineInternalTarget | ||
itemBodyInlineFootnote | ||
itemBodyInlineHyperLink | ||
itemBodyBulletList | ||
itemBodyEnumeratedList | ||
itemBodyDefinitionList | ||
itemBodyFieldList | ||
itemBodyBibliographicField | ||
itemBodyOptionList | ||
itemBodyLiteralBlock | ||
itemBodyLiteralBlockIndented | ||
itemBodyQuotedBlock | ||
) | ||
|
||
type stateFn func(*lexer) stateFn | ||
|
||
type item struct { | ||
typ itemElements | ||
pos Pos | ||
val string | ||
} | ||
|
||
type lexer struct { | ||
name string | ||
input string | ||
state stateFn | ||
pos Pos | ||
start Pos | ||
width Pos | ||
lastPos Pos | ||
items chan item | ||
} | ||
|
||
func lex(name, input string) *lexer { | ||
l := &lexer{ | ||
name: name, | ||
input: input, | ||
items: make(chan item), | ||
} | ||
go l.run() | ||
return l | ||
} | ||
|
||
func (l *lexer) run() { | ||
for l.state = lexText; l.state != nil; { | ||
l.state = l.state(l) | ||
} | ||
} | ||
|
||
func lexText(l *lexer) stateFn { | ||
// for { | ||
// if strings.HasPrefix(l.input[l.pos:], l.leftDelim) { | ||
// if l.pos > l.start { | ||
// l.emit(itemText) | ||
// } | ||
// return lexLeftDelim | ||
// } | ||
// if l.next() == eof { | ||
// break | ||
// } | ||
// } | ||
// // Correctly reached EOF. | ||
// if l.pos > l.start { | ||
// l.emit(itemText) | ||
// } | ||
// l.emit(itemEOF) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// go-rst - A reStructuredText parser for Go | ||
// 2014 (c) The go-rst Authors | ||
// MIT Licensed. See LICENSE for details. | ||
package parse | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"os" | ||
"strings" | ||
"testing" | ||
"encoding/json" | ||
) | ||
|
||
type lexTest struct { | ||
description []byte | ||
input []byte | ||
expectJson []byte | ||
} | ||
|
||
func parseTestData(filepath string) ([]lexTest, error) { | ||
testData, err := os.Open(filepath) | ||
defer testData.Close() | ||
if err != nil { | ||
return nil, err | ||
} | ||
var lexTests []lexTest | ||
var curTest lexTest | ||
var buffer []byte | ||
scanner := bufio.NewScanner(testData) | ||
for scanner.Scan() { | ||
switch scanner.Text() { | ||
case "#description": | ||
if len(buffer) > 0 { | ||
curTest.expectJson = buffer | ||
lexTests = append(lexTests, curTest) | ||
curTest = lexTest{} | ||
} else { | ||
curTest = lexTest{} | ||
} | ||
buffer = nil | ||
case "#data": | ||
curTest.description = buffer | ||
buffer = nil | ||
case "#tree": | ||
curTest.input = buffer | ||
buffer = nil | ||
default: | ||
if len(scanner.Text()) == 0 || | ||
strings.TrimLeft(scanner.Text(), " ")[0] == '#' { | ||
continue | ||
} | ||
buffer = append(buffer, scanner.Bytes()...) | ||
} | ||
} | ||
return lexTests, nil | ||
} | ||
|
||
func TestSection(t *testing.T) { | ||
lexTests, err := parseTestData("../testdata/test_section_headers.dat") | ||
if err != nil { | ||
t.FailNow() | ||
} | ||
// for _, iTest := range lexTests { | ||
// fmt.Printf("DESCRIPTION: %#v\n", iTest.description) | ||
// fmt.Printf("INPUT: %#v\n", iTest.input) | ||
// fmt.Printf("JSON: %#v\n", iTest.expectJson) | ||
// } | ||
var i interface{} | ||
err = json.Unmarshal(lexTests[0].expectJson, &i) | ||
if err != nil { | ||
t.Errorf("JSON Error: %s, IN: %s", err, lexTests[0]) | ||
} | ||
fmt.Printf("%#v\n", i) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// go-rst - A reStructuredText parser for Go | ||
// 2014 (c) The go-rst Authors | ||
// MIT Licensed. See LICENSE for details. | ||
package parse | ||
|
||
type Pos int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package parse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// go-rst - A reStructuredText parser for Go | ||
// 2014 (c) The go-rst Authors | ||
// MIT Licensed. See LICENSE for details. | ||
package parse | ||
|
||
type Tree struct { | ||
Name string | ||
text string | ||
// Document *ListNode | ||
lex *lexer | ||
} | ||
|
||
func New(name string) *Tree { | ||
return &Tree{ | ||
Name: name, | ||
} | ||
} | ||
|
||
func (t *Tree) Parse(text string) (tree *Tree, err error) { | ||
return nil, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// go-rst - A reStructuredText parser for Go | ||
// 2014 (c) The go-rst Authors | ||
// MIT Licensed. See LICENSE for details. | ||
package parse |
Oops, something went wrong.