From 8b51d09aa909e805119641e8958476697bf294ac Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Sun, 15 Apr 2018 11:27:18 +1000 Subject: [PATCH] Remove token ID/Key distinction, part 5 of N --- lang/token/list.go | 105 ++++++++++++++++++++++++--------------------- 1 file changed, 56 insertions(+), 49 deletions(-) diff --git a/lang/token/list.go b/lang/token/list.go index 96410b51..e49694c6 100644 --- a/lang/token/list.go +++ b/lang/token/list.go @@ -30,7 +30,6 @@ type Flags uint32 const ( FlagsOther = Flags(0x0001) - FlagsBinaryOp = Flags(0x0004) FlagsLiteral = Flags(0x0010) FlagsNumLiteral = Flags(0x0020) FlagsStrLiteral = Flags(0x0040) @@ -41,7 +40,7 @@ const ( // Key is the high 16 bits of an ID. It is the map key for a Map. type Key uint32 -func (k Key) isXOp() bool { return minXKey <= k && k <= maxXKey } +func (k Key) isXOp() bool { return minXOpKey <= k && k <= maxXOpKey } const ( FlagsBits = 16 @@ -68,9 +67,13 @@ func (x ID) Flags() Flags { return Flags(x & FlagsMask) } func (x ID) IsBuiltIn() bool { return Key(x>>KeyShift) < nBuiltInKeys } -func (x ID) IsUnaryOp() bool { return x.Key() <= 0xFF && x.UnaryForm() != 0 } -func (x ID) IsBinaryOp() bool { return Flags(x)&FlagsBinaryOp != 0 } -func (x ID) IsAssociativeOp() bool { return x.Key() <= 0xFF && x.AssociativeForm() != 0 } +func (x ID) IsUnaryOp() bool { return minOpKey <= x.Key() && x.Key() <= maxOpKey && x.UnaryForm() != 0 } +func (x ID) IsBinaryOp() bool { + return minOpKey <= x.Key() && x.Key() <= maxOpKey && x.BinaryForm() != 0 +} +func (x ID) IsAssociativeOp() bool { + return minOpKey <= x.Key() && x.Key() <= maxOpKey && x.AssociativeForm() != 0 +} func (x ID) IsLiteral() bool { return Flags(x)&FlagsLiteral != 0 } func (x ID) IsNumLiteral() bool { return Flags(x)&FlagsNumLiteral != 0 } @@ -141,6 +144,7 @@ type Token struct { // - [0x74, 0x77] are literals, such as "false" and "true". // - [0x78, 0xCF] are identifiers, such as "bool", "u32" and "read_u8". // - [0xD0, 0xFF] are disambiguation forms, e.g. unary "+" vs binary "+". +// TODO: move the ops and x-ops together. // // "Squiggly" means a sequence of non-alpha-numeric characters, such as "+" and // "&=". Roughly speaking, their Keys range in [0x01, 0x4F], or disambiguation @@ -380,31 +384,34 @@ const ( IDPercentEq = ID(0x2B<