Skip to content

Commit

Permalink
Merge pull request #9 from apterf/master
Browse files Browse the repository at this point in the history
bugfix: Missing plus symbol in cardinality set
  • Loading branch information
kaishuu0123 committed Jan 16, 2019
2 parents 1778493 + 67f255d commit 244cd5c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 16 deletions.
2 changes: 1 addition & 1 deletion erd.peg
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ newline_or_eot <- newline / EOT
space <- [ \t]+
string <- (!["\t\r\n/:,\[\]{} ].)+
string_in_quote <- (!["\t\r\n].)+
cardinality <- [01*]
cardinality <- [01*+]
39 changes: 28 additions & 11 deletions erd.peg.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ package main

import (
"fmt"
"io"
"math"
"os"
"sort"
"strconv"
)
Expand Down Expand Up @@ -136,19 +138,19 @@ type node32 struct {
up, next *node32
}

func (node *node32) print(pretty bool, buffer string) {
func (node *node32) print(w io.Writer, pretty bool, buffer string) {
var print func(node *node32, depth int)
print = func(node *node32, depth int) {
for node != nil {
for c := 0; c < depth; c++ {
fmt.Printf(" ")
fmt.Fprintf(w, " ")
}
rule := rul3s[node.pegRule]
quote := strconv.Quote(string(([]rune(buffer)[node.begin:node.end])))
if !pretty {
fmt.Printf("%v %v\n", rule, quote)
fmt.Fprintf(w, "%v %v\n", rule, quote)
} else {
fmt.Printf("\x1B[34m%v\x1B[m %v\n", rule, quote)
fmt.Fprintf(w, "\x1B[34m%v\x1B[m %v\n", rule, quote)
}
if node.up != nil {
print(node.up, depth+1)
Expand All @@ -159,12 +161,12 @@ func (node *node32) print(pretty bool, buffer string) {
print(node, 0)
}

func (node *node32) Print(buffer string) {
node.print(false, buffer)
func (node *node32) Print(w io.Writer, buffer string) {
node.print(w, false, buffer)
}

func (node *node32) PrettyPrint(buffer string) {
node.print(true, buffer)
func (node *node32) PrettyPrint(w io.Writer, buffer string) {
node.print(w, true, buffer)
}

type tokens32 struct {
Expand Down Expand Up @@ -207,11 +209,15 @@ func (t *tokens32) AST() *node32 {
}

func (t *tokens32) PrintSyntaxTree(buffer string) {
t.AST().Print(buffer)
t.AST().Print(os.Stdout, buffer)
}

func (t *tokens32) WriteSyntaxTree(w io.Writer, buffer string) {
t.AST().Print(w, buffer)
}

func (t *tokens32) PrettyPrintSyntaxTree(buffer string) {
t.AST().PrettyPrint(buffer)
t.AST().PrettyPrint(os.Stdout, buffer)
}

func (t *tokens32) Add(rule pegRule, begin, end, index uint32) {
Expand Down Expand Up @@ -319,6 +325,10 @@ func (p *Parser) PrintSyntaxTree() {
}
}

func (p *Parser) WriteSyntaxTree(w io.Writer) {
p.tokens32.WriteSyntaxTree(w, p.Buffer)
}

func (p *Parser) Execute() {
buffer, _buffer, text, begin, end := p.Buffer, p.buffer, "", 0, 0
for _, token := range p.Tokens() {
Expand Down Expand Up @@ -2109,7 +2119,7 @@ func (p *Parser) Init() {
position, tokenIndex = position238, tokenIndex238
return false
},
/* 31 cardinality <- <('0' / '1' / '*')> */
/* 31 cardinality <- <('0' / '1' / '*' / '+')> */
func() bool {
position252, tokenIndex252 := position, tokenIndex
{
Expand All @@ -2131,6 +2141,13 @@ func (p *Parser) Init() {
l256:
position, tokenIndex = position254, tokenIndex254
if buffer[position] != rune('*') {
goto l257
}
position++
goto l254
l257:
position, tokenIndex = position254, tokenIndex254
if buffer[position] != rune('+') {
goto l252
}
position++
Expand Down
2 changes: 1 addition & 1 deletion examples/nfldb.er
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ game *--1 team {label: "home"}
game *--1 team {label: "away"}
drive *--1 team
play *--1 team
play_player *--1 team
play_player +--1 team

game 1--* drive
game 1--* play
Expand Down
6 changes: 3 additions & 3 deletions templates_bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 244cd5c

Please sign in to comment.