CXuesong / MwParserFromScratch

A basic .NET Library for parsing wikitext into AST.
Apache License 2.0
18 stars 5 forks source link

Missing-token inferrence in parsing #6

Closed CXuesong closed 7 years ago

CXuesong commented 7 years ago

Now that I'm working on MwLanguageServer, to implement AST-based signature help and auto completion, language server needs some non-trivial node structures to figure out where user's caret is.

For example, if user is entering a template expression in the editor (I use $ to indicate the position of caret.

content content content {{Temp$
content content content

Now user want some hint on the unfinished template expression, but obviously, {{Temp itself is not a valid template expression, so WikitextParser will just parse the whole document as a huge PlainText node, and language server cannot figure out what kind of completion the user wants. This case also holds for WikiLink, and TagNode.

To fix this, we might allow some "error-handling" in WikitextParser, such as, to implicitly close the unclosed template expression, like this

content content content {{Temp$
content content content (}})

and we will get a large Template node now. Though it's not accurate, the server may do some work before finding out that the user is now in a template expression, and to the left of the caret, we have Temp already entered.