Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Allow Dynamic Content in Simple Titles #59

Merged
merged 1 commit into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions internal/lexer/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,8 @@ func LexMain(_ *LexContext, l *lexer.Lexer) LexFn {
//
if matchOneOrMore(l, isSpaceOrTab) {
l.Clear()
if matchOneOrMore(l, isPrintNonReturn) {
l.EmitToken(TokenConfigDescLine)
if matchNewline(l) {
l.Clear()
}
if l.CanPeek(1) && isPrintNonReturn(l.Peek(1)) {
l.EmitToken(TokenConfigDescLineStart)
return LexMain
}
}
Expand Down Expand Up @@ -536,7 +533,7 @@ func LexDocBlockDesc(ctx *LexContext, l *lexer.Lexer) LexFn {
// Desc line
//
ctx.PushFn(LexDocBlockDesc)
return lexDocBlockNQString
return LexDocBlockNQString
}
return LexDocBlockDesc
}
Expand All @@ -545,9 +542,9 @@ func LexDocBlockDesc(ctx *LexContext, l *lexer.Lexer) LexFn {
return nil
}

// lexDocBlockNQString
// LexDocBlockNQString lexes a doc block comment line
//
func lexDocBlockNQString(ctx *LexContext, l *lexer.Lexer) LexFn {
func LexDocBlockNQString(ctx *LexContext, l *lexer.Lexer) LexFn {
switch {
// Consume a run of printable, non-escape characters
//
Expand All @@ -568,7 +565,7 @@ func lexDocBlockNQString(ctx *LexContext, l *lexer.Lexer) LexFn {
//
case l.CanPeek(1) && l.Peek(1) == runeDollar:
if l.CanPeek(2) && l.Peek(2) == runeLBrace {
ctx.PushFn(lexDocBlockNQString)
ctx.PushFn(LexDocBlockNQString)
l.EmitType(TokenVarRefStart)
return LexVarRef
}
Expand All @@ -580,7 +577,7 @@ func lexDocBlockNQString(ctx *LexContext, l *lexer.Lexer) LexFn {
}
return nil
}
return lexDocBlockNQString
return LexDocBlockNQString
}

// LexDocBlockAttr lexes a doc block attribute line
Expand Down Expand Up @@ -636,7 +633,7 @@ func LexCmdConfigShell(ctx *LexContext, l *lexer.Lexer) LexFn {
//
func LexCmdConfigUsage(_ *LexContext, l *lexer.Lexer) LexFn {
ignoreSpace(l)
return lexDocBlockNQString
return LexDocBlockNQString
}

// LexCmdConfigOpt matches: name [-l] [--long] [<label>] ["desc"]
Expand Down Expand Up @@ -720,7 +717,7 @@ func LexCmdConfigOpt(_ *LexContext, l *lexer.Lexer) LexFn {

// Desc?
//
return lexDocBlockNQString
return LexDocBlockNQString
}

// LexCmdShellName lexes a command's shell
Expand Down
2 changes: 1 addition & 1 deletion internal/lexer/tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const (
TokenHashLine

TokenConfigShell
TokenConfigDescLine
TokenConfigDescLineStart
TokenConfigDescEnd
TokenConfigUsage
TokenConfigOpt
Expand Down
9 changes: 6 additions & 3 deletions internal/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,13 @@ func parseMain(ctx *parseContext, p *parser.Parser) parseFn {
}
// Doc Line
//
if tryPeekType(p, lexer.TokenConfigDescLine) {
line := p.Next()
if tryPeekType(p, lexer.TokenConfigDescLineStart) {
p.Next()
ctx.pushLexFn(ctx.l.Fn)
ctx.setLexFn(lexer.LexDocBlockNQString)
line := expectDocNQString(ctx, p)
cmdConfig = &ast.CmdConfig{}
cmdConfig.Desc = append(cmdConfig.Desc, &ast.ScopeValueRunes{Value: line.Value()})
cmdConfig.Desc = append(cmdConfig.Desc, line)
p.Clear()
tryMatchCmd(ctx, p, cmdConfig)
return parseMain
Expand Down