-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider allowing hotword expressions nested in bracketed expressions #59
Comments
This actually seems a bit more difficult than I first thought. We're relying on Python's parser in bracketed expressions, but the macro character ! probably shouldn't be valid inside of a string literal. We can probably recognize literal strings with the lexing regex though. Hmm. It does still seem doable. |
F-strings though. We'd want to be able to turn the macro back on in those. |
As convenient as this would be, it kind of doesn't seem worth it. The thing I miss the most in bracketed expressions so far is the module literals. It would be nice if we could at least preprocess those, but it seems about as difficult to do as the full expression macros. One can certainly write Python is capable of abbreviating this kind of thing. class Importer:
def __init__(self, module_path=()):
self.mpath = module_path
def __getattribute__(self, attr):
return Importer(object.__getattribute__(self,'mpath') + (attr,))
def __call__(self):
return import_module('.'.join(object.__getattribute__(self,'mpath'))) >>> M = Importer()
>>> M.collections.abc().Iterable
<class 'collections.abc.Iterable'> That's almost as good. You need a prefix like the |
Given f-strings, |
A macro like this wouldn't be too hard to write:
It feels more compact than the It could also be done positionally with an anaphor.
Or both at once. This seems like the 80% solution. Getting the parser to handle this properly seems a lot more difficult. |
Hissp has the Usage might end up looking something like the following:
You couldn't simply inject unbalanced parentheses this way, but a text macro could expand to an arbitrary fragment. Macros operate on the Hissp level. There's no need to change the parser here. |
While parsing a bracketed expression, we could recursively switch back to the base Hebigo parser when encountering a macro character that Python doesn't use, like
!
, until we finish the next Hebigo expression, then place the result of compiling that back into the Python string we're building. This would effectively be a builtin reader macro. For example,Maybe a bad example, since Python's expression syntax can handle this part fine.
But suppose we needed a macro.
We'd currently have to do something like
or
On the other hand, we might want to encourage using hotword expressions instead of Python expressions, because it's much easier to write macros to work with those.
The text was updated successfully, but these errors were encountered: