biscuit-auth / biscuit

delegated, decentralized, capabilities based authorization token
Apache License 2.0
961 stars 25 forks source link

Negation X2 #157

Open yaronf opened 6 months ago

yaronf commented 6 months ago

It's surprising that the language supports bitwise binary operators but not the C "complement" (~) operator. It is very useful when dealing with bit strings that represent flags, value & ~mask == desired. Granted that a workaround exists, XOR with -1.

A more complicated case is simple integer negation, -X. I just found out that the Go implementation does not support negative literal integers (-100) (the Rust code does, I believe). I tried to add them by tweaking the lexer but this results in a parser ambiguity, e.g. when parsing 200-100. One simple solution is for the lexer to only support positive literals and the parser to deal with the minus/negation distinction, but that would necessitate integer negation as a unary operator.

yaronf commented 6 months ago

Re: integer negation, the issue can be resolved within the Go implementation with no change to the language. Having said that, unary negation is indeed a standard arithmetic operator.