Skip to content

Commit

Permalink
bug: Allow Dynamic Content in Simple Titles (#59)
Browse files Browse the repository at this point in the history
Allows simple titles (##) to reference variables/attributes/etc

chore: Makes LexDocBlockNQString public
chore: Replaces TokenConfigDescLine => TokenConfigDescLineStart
  • Loading branch information
TekWizely authored Jul 27, 2022
1 parent e28963e commit c7d5bdd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
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

0 comments on commit c7d5bdd

Please sign in to comment.