cenotelie / hime

Apache License 2.0
27 stars 4 forks source link

Dynamic/Associated context sensitive rules? #90

Open stevefan1999-personal opened 11 months ago

stevefan1999-personal commented 11 months ago

Consider an XML file:

<foo>
</foo>

And this:

<foo>
</bar>

Clearly the latter is wrong. Right now there is no way to add tags with regards to context sensitive rules in runtime but only lexical scope: https://cenotelie.fr/projects/hime/referenceLangContextSensitive

Technically speaking, whitespace sensitive programming language like Python also fall under this category of having associated data in runtime.

In this case, we track the number of whitespaces and try our best to match their multiplications on each line For example, I have 2 whitespaces predating on line 2, so I should have 4 whitespaces or 2 whitespace per indent x at least 2 indents = at least 4 whitespaces:

def foo():
  if bar:
    return "foo bar"

Related: #53

woutersl commented 11 months ago

Thing is, Hime handles context-free grammars (with some extensions for context-sensitive lexing indeed). XML is a prime example of context-sensitive grammar with the repetition of the tag name for closing tags.

Handling (and defining!) such grammars is a huge undertaking, outside the scope of Hime. In general for such languages, people hand-roll their own parsing scheme. See the plethora of XML parsers and the headache that is parsing Python.