Skip to content

Commit

Permalink
Merge pull request #1 from robbyriverside/block_scanner
Browse files Browse the repository at this point in the history
read block
  • Loading branch information
robbyriverside authored Jan 31, 2022
2 parents 5077c40 + 71afb6d commit e928379
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
27 changes: 27 additions & 0 deletions decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,10 @@ func (dec *Decoder) Decode() ([]*Node, error) {
}
case '#':
switch dec.State {
case KeyElem, KeyEmpty:
dec.Key = ""
dec.readBlock()
dec.State = KeyEmpty
case NewLine:
dec.State = OnFeature
default:
Expand All @@ -286,6 +290,29 @@ func (dec *Decoder) Decode() ([]*Node, error) {
return dec.Roots, nil
}

func (dec *Decoder) readBlock() error {
delim := dec.Text.Next()
if !strings.ContainsAny(string(delim), "|@$%") {
return dec.Error("invalid block delimiter: #" + string(delim))
}
var build strings.Builder
for ch := dec.Text.Next(); ch != scanner.EOF; ch = dec.Text.Next() {
if ch == delim {
at := dec.Text.Next()
if at == '#' {
dec.Token = build.String()
dec.setContent()
return nil
}
build.WriteRune(ch)
build.WriteRune(at)
continue
}
build.WriteRune(ch)
}
return dec.Error("Found EOF while reading block no matching " + string(delim))
}

func (dec *Decoder) contentFeature() {
content := strings.Trim(dec.Token, "`")
feature := strings.ToLower(dec.Feature)
Expand Down
10 changes: 8 additions & 2 deletions tests/test3.brief
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#include `test1.brief`
#include `test2.brief`
html class:foo
html class:foo #| now is the
#$time for `bupkis`$#
all good
|#
head
title `just for good measure`
title #@just for


good measure@#

0 comments on commit e928379

Please sign in to comment.