-
Notifications
You must be signed in to change notification settings - Fork 63
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
Python bindings: Make Cryptol quasiquotation easier #1188
Comments
I wonder if we could get away with something simpler than the linked solution – I'm somewhat put off by the fact that it uses If we're okay with only allowing expressions like from string import Formatter
import sys
class CryptolFormatter(Formatter):
def format_field(self, value, spec):
return f"({super().format_field(value, spec)})"
def cry(str):
previous_frame = sys._getframe(1)
locals_and_globals = {**previous_frame.f_locals, **globals()}
return CryptolFormatter().format(str, **locals_and_globals)
a = cry('g x')
b = cry('foo {a}')
print(repr(a)) # prints 'g x'
print(repr(b)) # prints 'foo (g x)' And of course, we could have |
We should probably come up with a few potential solutions, document their pros and cons, and then decide. W.r.t. the two quasiquoting solutions so far, I personally prefer the one that allows arbitrary expressions in the escape holes. Unless I'm missing something, the use of Another approach might be to just embrace Python strings themselves as our canonical quasiquotation technique for Cryptol syntax. At that point, we could use plain old f-strings to combine expressions. As long as every Cryptol expression and value has a proper |
I was able to figure out a solution using reflection in GaloisInc/cryptol#1307 that replicates f-string syntax exactly. I never actually posted about this here, but I found that the solution linked in the initial post suffers from an issue with nested brackets, e.g. when quoting a dict: |
Now that #1550 has landed, the SAW Python client offers a |
Let's close it. |
In SAWScript, you can embed Cryptol expressions inside of other Cryptol expressions automatically, e.g.,
However, the equivalent of this in Python is not as ergonomic:
Ideally, both
a
andb
would be Cryptol expressions, and moreover, you wouldn't need to explicitly add parentheses around{a}
.@pnwamk has this to say about the idea:
This issue aims to track this idea.
The text was updated successfully, but these errors were encountered: