Could you explain how parsers search for token patterns like in markdown?
I probably could come up with something matching only the braces pattern []() as soon as nested patterns are involved it blows my mind.
For example in something like this
foo [**baz**](baz) qux
the tokenizer probably explodes the string into these tokens
"foo ", "[", "**", "baz", "**", "]", "(", "baz", ")", " qux"
and passes it to the parser to recognize the patterns, that it's a link and that the braces match and then even understand the bold style inside the label.
I guess it's some kind of a state machine but does it really think that as soon as a [ ocurrs it might mean something so store the token and if the subsequent tokens don't match then discard this state and turn the separator tokens into a normal literal. This would mean that it had to go back change the meaning of everything else if there was no ( after the closing ]. Do I think too complex?
It looks like it was easy to implement when I look at it, but if I should invent an algorithm for it, I couldn't.
[foo]is only parsed as a link if that reference is defined. Otherwise, the square brackets are just literals. And nested links are impossible. And***foo** bar*is a strong emphasis within an emphasis, whereas***foo* bar**is an emphasis in a strong emphasis. That is far more complicated than a normal programming language. There's an attempt at a spec that tries to approach these problems.([]([]())), but then you talk about Markdown. If you want to know how Markdown parser works, look at the source code and/or the spec of Markdown. If you want to know more about nested patterns, independently of Markdown, then edit your question to remove the reference to Markdown.[]()doesn't seem to be so obvious. I mentioned markdown because it uses a very interesing syntax (language?) and I believe most visitors are already familiar with this one.[][]or[](). On each pass I need to upgrade a group of tokens to the next level that now stand for a concrete object not just random tokens. This way I think it should possible to build a tree step by step.