Skip to content

Commit

Permalink
Reverted support for quotes in comments, because of pb with quotes in…
Browse files Browse the repository at this point in the history
… tip names #9
  • Loading branch information
fredericlemoine committed Oct 4, 2023
1 parent c7e2aa1 commit 753a65f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
2 changes: 0 additions & 2 deletions io/newick/newick_lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ func (s *Scanner) Scan(ignoreSemiColumn bool) (tok Token, lit string) {
return OPENBRACK, string(ch)
case ']':
return CLOSEBRACK, string(ch)
case '\'':
return LABEL, string(ch)
case ',':
return NEWSIBLING, string(ch)
case ';':
Expand Down
8 changes: 4 additions & 4 deletions io/newick/newick_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (p *Parser) scanIgnoreWhitespace() (tok Token, lit string) {
func (p *Parser) Parse() (newtree *tree.Tree, err error) {
// May have information inside [] before the tree
tok, lit := p.scanIgnoreWhitespace()
if tok == OPENBRACK || tok == LABEL {
if tok == OPENBRACK {
if _, err = p.consumeComment(tok, lit); err != nil {
return
}
Expand Down Expand Up @@ -159,7 +159,7 @@ func (p *Parser) parseIter(t *tree.Tree, level *int) (prevTok Token, err error)
return
}
node, edge, _ = nodeStack.Head()
case OPENBRACK, LABEL:
case OPENBRACK:
var comment string
//if prevTok == OPENPAR || prevTok == NEWSIBLING || prevTok == -1 {
if comment, err = p.consumeComment(tok, lit); err != nil {
Expand Down Expand Up @@ -293,9 +293,9 @@ func (p *Parser) parseIter(t *tree.Tree, level *int) (prevTok Token, err error)
// At the end returns the matching ] token and lit.
// If the given token is not a [, then returns an error
func (p *Parser) consumeComment(curtoken Token, curlit string) (comment string, err error) {
if curtoken == OPENBRACK || curtoken == LABEL {
if curtoken == OPENBRACK {
commenttoken, commentlit := p.scan(true)
for (curtoken == LABEL && commenttoken != LABEL) || (curtoken == OPENBRACK && commenttoken != CLOSEBRACK) {
for commenttoken != CLOSEBRACK {
if commenttoken == EOF || commenttoken == ILLEGAL {
err = fmt.Errorf("unmatched bracket: %s (%s)", comment, commentlit)
return
Expand Down
3 changes: 1 addition & 2 deletions io/newick/newick_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const (
STARTLEN // :
OPENBRACK // [ : For comment
CLOSEBRACK // ] : For comment
LABEL // ' : For comment associated to nodes/edges
NEWSIBLING // ,
EOT // ;
)
Expand All @@ -36,5 +35,5 @@ func isIdent(ch rune, ignoreSemiColumn bool) bool {
return ch != '[' && ch != ']' &&
ch != '(' && ch != ')' &&
ch != ',' && ch != ':' &&
(ignoreSemiColumn || ch != ';') && ch != '\''
(ignoreSemiColumn || ch != ';')
}

0 comments on commit 753a65f

Please sign in to comment.