From 753a65f4fd977d03e6f777a818983d172328b98c Mon Sep 17 00:00:00 2001 From: Frederic Lemoine Date: Wed, 4 Oct 2023 17:40:15 +0200 Subject: [PATCH] Reverted support for quotes in comments, because of pb with quotes in tip names #9 --- io/newick/newick_lexer.go | 2 -- io/newick/newick_parser.go | 8 ++++---- io/newick/newick_token.go | 3 +-- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/io/newick/newick_lexer.go b/io/newick/newick_lexer.go index 82d52d1..0b14e2a 100644 --- a/io/newick/newick_lexer.go +++ b/io/newick/newick_lexer.go @@ -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 ';': diff --git a/io/newick/newick_parser.go b/io/newick/newick_parser.go index 989d479..51d5285 100644 --- a/io/newick/newick_parser.go +++ b/io/newick/newick_parser.go @@ -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 } @@ -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 { @@ -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 diff --git a/io/newick/newick_token.go b/io/newick/newick_token.go index be2dbd5..45ec5aa 100644 --- a/io/newick/newick_token.go +++ b/io/newick/newick_token.go @@ -15,7 +15,6 @@ const ( STARTLEN // : OPENBRACK // [ : For comment CLOSEBRACK // ] : For comment - LABEL // ' : For comment associated to nodes/edges NEWSIBLING // , EOT // ; ) @@ -36,5 +35,5 @@ func isIdent(ch rune, ignoreSemiColumn bool) bool { return ch != '[' && ch != ']' && ch != '(' && ch != ')' && ch != ',' && ch != ':' && - (ignoreSemiColumn || ch != ';') && ch != '\'' + (ignoreSemiColumn || ch != ';') }