yitzchak / tree-sitter-latex

LaTeX grammar for tree-sitter
MIT License
11 stars 5 forks source link

Fall back to saved catcodes #19

Closed Aerijo closed 5 years ago

Aerijo commented 5 years ago

If I've understood it right, this should let the saved_catcodes do it's job.

Seeing as there are two maps, and the "main" one appears to hold a known set of keys, I think it should be easy to convert it to a switch / array. By this, I'm imagining something like

Category catcodes[30] = { FOO, FOO, BAR, ... };

get_catcode(char c) {
  switch (c) {
    case '\\': return catcodes[0];
    case '{': return catcodes[1];
    ...
    default:
     auto it = saved_catcodes.find(c);
     return it->second;
  }
}

So we can still change the values of the fixed characters. I also think we can hard code letters as always letters, because 1) I don't think anyone is crazy enough to change that, and 2) if they do change it, what if we don't detect when they reverted it?

yitzchak commented 5 years ago

@Aerijo No, that is not what saved_catcodes was for.

It turns out \ExplSyntaxOn saves the current value of the catcodes it overwrites which it then restores with \ExplSyntaxOff.

I probably didn't name it well and haven't added comments yet. Sorry about that.

Aerijo commented 5 years ago

I'm going to try sleeping instead.