Skip to content

Commit

Permalink
feat(parser): parsing quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
xNaCly committed Apr 13, 2023
1 parent 7ebf212 commit ccdc7c7
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ func (p *Parser) Parse() []Tag {
}

func (p *Parser) tag() Tag {
if p.check(scanner.BANG) {
if p.check(scanner.GREATERTHAN) {
return p.quote()
return p.img()
} else if p.check(scanner.BACKTICK) {
return p.code()
Expand All @@ -45,6 +46,41 @@ func (p *Parser) tag() Tag {
}
}

func (p *Parser) quote() Tag {
// skip the >
p.advance()

children := make([]Tag, 0)

for !p.check(scanner.EMPTYLINE) && !p.isAtEnd() {
switch p.peek().Kind {
case scanner.GREATERTHAN:
p.advance()
continue
case scanner.BANG:
children = append(children, p.img())
case scanner.HASH:
children = append(children, p.heading())
case scanner.STRAIGHTBRACEOPEN:
children = append(children, p.link())
case scanner.BACKTICK:
children = append(children, p.code(true))
case scanner.STAR, scanner.UNDERSCORE:
children = append(children, p.emphasis())
case scanner.TEXT:
children = append(children, Text{content: p.peek().Value})
p.advance()
default:
children = append(children, Text{content: string(scanner.TOKEN_SYMBOL_MAP[p.peek().Kind])})
p.advance()
}
}

return Quote{
children: children,
}
}

func (p *Parser) img() Tag {
p.advance()

Expand Down

0 comments on commit ccdc7c7

Please sign in to comment.