Open Serhioromano opened 3 years ago
Thank you for using gocc. Sorry about the frustration caused. Parser generators have a learning curve, just know you are not alone.
Here are some oddities I spotted that might or might not be worth investigating:
<< nil >>
you are not capturing anything{_nl}
, zero or more new lines, maybe you would prefer one or more _nl {_nl}
In the SDT rules << nil >> you are not capturing anything
I know that. I thought that my errors because I do not have those, that is why I added them.
You also do not seem to be parsing any text that is not in a title.
For now, I do not want to. All I want to find all titles inside the text, then I'll add more elements. I need to make working at least one.
I am also not sure about the use of
{_nl}
, zero or more new lines, maybe you would prefer one or more_nl {_nl}
Good point, thank you.
So do you know answer how to find title2 in my example?
Sorry my experience isn't fresh enough to quickly spot the problem here. Also, I can't remember any time that I didn't parse into an AST.
Hi, serhi; there are a couple of problems:
parse(...)
is going to receive the left-value << nil, ... >> of the outermost match,I would suggest you start with just matching h1 and proceed from there.
Go Code:
package main
import "fmt"
import "github.com/kfsone/scratch/lexer" // << replace with YOUR path
import "github.com/kfsone/scratch/parser"
//import "github.com/kfsone/scratch/token"
func main() {
sample := "This\ncan be\r\nignored!\n# This is my header\r\nhello\n"
l := lexer.NewLexer([]byte(sample))
p := parser.NewParser()
ast, err := p.Parse(l)
if err != nil {
panic(err)
}
fmt.Printf("ast value: %#+v\n", ast)
}
I try to build Markdown compiler. not actually compiler to machine code but to HTML, XML, JSON and other formats. Would be better to call it Markdown processor. I wanted it to be CLI tool that would work on any platform. When I read about
gocc
I thought that it would be ideal tool to do it. I want to make processor with a lot of new syntax goodies.Anyway, I want to make a simple task. Here is my BHF. All I want is to find titles.
And here is my GO file
and my markdown
But this only print data on first title and only if file begins with it. If I place few lines before it, it fails to find any title. What did I do wrong here?