can instaparse be used to parse significant-whitespace-indentation-things, in the python sense?
not really, primarily because of how the "levels" work in said indentation-heavy languages
@aengelberg can you change your username to ængelberg
thanks
done
okay well that's disappointing because I'm parsing such a thing and I guess I'll have to do it tediously by hand have you seen any general tools that can handle it?
if you could somehow pre-tokenize all of the indentation before passing it to instaparse, that might work
what I mean is that you'd have to convert
def f(x):
if x == 1:
return 2;
else:
return 3;
into
def f(x):
→if x == 1:
→return 2;
←else:
→return 3;
←←
if that makes sense
and the arrows act like brackets?
basically
because instaparse can't keep state of how far to the right you should be at any given point
based on higher-level indentations
I think the combination of writing that code and having to write a grammar is probably more tedious than parsing it manually
perhaps
oh also you could maybe get sneaky with nested parsing
where, say, the top level parser gives you back
[:def "f(x)"
[:nested-block
"if x == 1:"
" return 2;"
"else:"
" return 3;"]]
and then you have some code that then takes said nested blocks and re-runs the parser on it
and so on
oh interesting
if you're not trampolining your parser, why bother getting up in the morning?
you would have to re-append those nested block lines (with newlines in between)
sure
the grammar would look like
S = def | if | ...
def = <'def '> thing-you're-deffing <':\n'> nested-block
nested-block = (' ' #".*\n?")*