diff options
author | Thomas Voss <mail@thomasvoss.com> | 2023-11-01 16:38:49 +0100 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2023-11-01 16:38:49 +0100 |
commit | 1f83fa89d8585b1fa59df7a400157f8df93ff681 (patch) | |
tree | dc80afa3ea2f17f76705e7a4b695f41386320845 /parser | |
parent | eced3e62c922ee121429759eaa5d4956eb17085d (diff) |
Remove the ‘>’ prefixv3.0.0
The rationale was explained on the mailing list[1].
[1]: https://paste.thomasvoss.com/353
Diffstat (limited to 'parser')
-rw-r--r-- | parser/parser.go | 9 | ||||
-rw-r--r-- | parser/parser_test.go | 10 |
2 files changed, 6 insertions, 13 deletions
diff --git a/parser/parser.go b/parser/parser.go index b333506..7d69e30 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -32,7 +32,6 @@ type AstNode struct { Text string Attrs []Attr Children []AstNode - Newline bool } // ParseFile reads and parses a GSP-formatted text file and returns a GSP AST. @@ -73,14 +72,8 @@ func (reader *reader) parseNode() (node AstNode, err error) { return } - switch r { - case '-', '=': + if r == '-' || r == '=' { return reader.parseText(r == '=') - case '>': - node.Newline = true - if _, err = reader.readRune(); err != nil { - return - } } if node.Text, err = reader.parseNodeName(); err != nil { diff --git a/parser/parser_test.go b/parser/parser_test.go index 1851307..66a76bf 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -11,14 +11,14 @@ import ( func TestParseFile(t *testing.T) { s := ` html lang="en" { - >head attr { - >title {- + head attr { + title {- My Website } meta .→{} x="y"{} } - >body { - >div #some-id {} + body { + div #some-id {} div key="val" .class-1 .class-2 { p {- This is some @em{-emphatic} text } } @@ -39,7 +39,7 @@ func TestParseFile(t *testing.T) { s = fmt.Sprintf("%+v", ast) result := `{Type:1 Text: Attrs:[] Children:[{Type:0 Text:html Attrs:[{Key:lang Value:en}] Children:[{Type:0 Text:head Attrs:[{Key:attr Value:}] Children:[{Type:0 Text:title Attrs:[] Children:[{Type:1 Text: Attrs:[] Children:[{Type:3 Text: My Website - Attrs:[] Children:[] Newline:false}] Newline:false}] Newline:true} {Type:0 Text:meta Attrs:[{Key:class Value:→{}} {Key:x Value:y}] Children:[] Newline:false}] Newline:true} {Type:0 Text:body Attrs:[] Children:[{Type:0 Text:div Attrs:[{Key:id Value:some-id}] Children:[] Newline:true} {Type:0 Text:div Attrs:[{Key:key Value:val} {Key:class Value:class-1} {Key:class Value:class-2}] Children:[{Type:0 Text:p Attrs:[] Children:[{Type:1 Text: Attrs:[] Children:[{Type:3 Text: This is some Attrs:[] Children:[] Newline:false} {Type:0 Text:em Attrs:[] Children:[{Type:1 Text: Attrs:[] Children:[{Type:3 Text:emphatic Attrs:[] Children:[] Newline:false}] Newline:false}] Newline:false} {Type:3 Text: text Attrs:[] Children:[] Newline:false}] Newline:false}] Newline:false}] Newline:false} {Type:0 Text:tags Attrs:[{Key:key Value:Some long value}] Children:[] Newline:false}] Newline:true}] Newline:false}] Newline:false}` + Attrs:[] Children:[]}]}]} {Type:0 Text:meta Attrs:[{Key:class Value:→{}} {Key:x Value:y}] Children:[]}]} {Type:0 Text:body Attrs:[] Children:[{Type:0 Text:div Attrs:[{Key:id Value:some-id}] Children:[]} {Type:0 Text:div Attrs:[{Key:key Value:val} {Key:class Value:class-1} {Key:class Value:class-2}] Children:[{Type:0 Text:p Attrs:[] Children:[{Type:1 Text: Attrs:[] Children:[{Type:3 Text: This is some Attrs:[] Children:[]} {Type:0 Text:em Attrs:[] Children:[{Type:1 Text: Attrs:[] Children:[{Type:3 Text:emphatic Attrs:[] Children:[]}]}]} {Type:3 Text: text Attrs:[] Children:[]}]}]}]} {Type:0 Text:tags Attrs:[{Key:key Value:Some long value}] Children:[]}]}]}]}` if s != result { t.Fatalf("ParseFile() parsed unexpected AST ‘%s’", s) } |