summary refs log tree commit diff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--bin/man1/order.15
-rw-r--r--bin/order.y45
2 files changed, 37 insertions, 13 deletions
diff --git a/bin/man1/order.1 b/bin/man1/order.1
index 2eb730f1..f042102f 100644
--- a/bin/man1/order.1
+++ b/bin/man1/order.1
@@ -1,4 +1,4 @@
-.Dd May 15, 2019
+.Dd May 18, 2019
 .Dt ORDER 1
 .Os
 .
@@ -30,5 +30,4 @@ $ order 'a & b << 1'
 .Nm
 does not support the
 .Sy (type)
-operator
-or the compound assignment operators.
+operator.
diff --git a/bin/order.y b/bin/order.y
index a7bb817f..78051fe1 100644
--- a/bin/order.y
+++ b/bin/order.y
@@ -44,10 +44,8 @@ static int yylex(void);
 
 %}
 
-%token Var
-
 %left ','
-%right '='
+%right '=' MulAss DivAss ModAss AddAss SubAss ShlAss ShrAss AndAss XorAss OrAss
 %right '?' ':'
 %left Or
 %left And
@@ -60,7 +58,9 @@ static int yylex(void);
 %left '+' '-'
 %left '*' '/' '%'
 %right '!' '~' Inc Dec Sizeof
-%left '[' ']' Arr '.'
+%left '(' ')' '[' ']' Arr '.'
+
+%token Var
 
 %%
 
@@ -103,10 +103,24 @@ expr:
 	| expr And expr { $$ = fmt("(%s && %s)", $1, $3); }
 	| expr Or expr { $$ = fmt("(%s || %s)", $1, $3); }
 	| expr '?' expr ':' expr { $$ = fmt("(%s ? %s : %s)", $1, $3, $5); }
-	| expr '=' expr { $$ = fmt("(%s = %s)", $1, $3); }
+	| expr ass expr %prec '=' { $$ = fmt("(%s %s %s)", $1, $2, $3); }
 	| expr ',' expr { $$ = fmt("(%s, %s)", $1, $3); }
 	;
 
+ass:
+	'=' { $$ = "="; }
+	| MulAss { $$ = "*="; }
+	| DivAss { $$ = "/="; }
+	| ModAss { $$ = "%="; }
+	| AddAss { $$ = "+="; }
+	| SubAss { $$ = "-="; }
+	| ShlAss { $$ = "<<="; }
+	| ShrAss { $$ = ">>="; }
+	| AndAss { $$ = "&="; }
+	| XorAss { $$ = "^="; }
+	| OrAss { $$ = "|="; }
+	;
+
 %%
 
 #define T(a, b) ((int)(a) << 8 | (int)(b))
@@ -129,7 +143,7 @@ static int yylex(void) {
 		return Var;
 	}
 
-	int tok = 0;
+	int tok;
 	switch (T(input[0], input[1])) {
 		break; case T('-', '>'): tok = Arr;
 		break; case T('+', '+'): tok = Inc;
@@ -142,13 +156,24 @@ static int yylex(void) {
 		break; case T('!', '='): tok = Ne;
 		break; case T('&', '&'): tok = And;
 		break; case T('|', '|'): tok = Or;
+		break; case T('*', '='): tok = MulAss;
+		break; case T('/', '='): tok = DivAss;
+		break; case T('%', '='): tok = ModAss;
+		break; case T('+', '='): tok = AddAss;
+		break; case T('-', '='): tok = SubAss;
+		break; case T('&', '='): tok = AndAss;
+		break; case T('^', '='): tok = XorAss;
+		break; case T('|', '='): tok = OrAss;
+		break; default: return *input++;
 	}
-	if (tok) {
-		input += 2;
-		return tok;
+	input += 2;
+
+	switch (T(tok, input[0])) {
+		case T(Shl, '='): input++; return ShlAss;
+		case T(Shr, '='): input++; return ShrAss;
 	}
 
-	return *input++;
+	return tok;
 }
 
 int main(int argc, char *argv[]) {
='/catgirl/commit/window.c?id=073cebec7a5a07ab2b829e40ce47ec3b1d774bd9&follow=1'>Factor out input handling to input.cJune McEnroe 2022-02-19Factor out window management to window.cJune McEnroe 2022-02-19Enable -Wmissing-prototypesJune McEnroe In other words, warn when a function is missing static. I don't see why this isn't in -Wextra. 2022-02-19Fix edit.[ch] license notice additional permissionsJune McEnroe 2022-02-19Run line editing testsJune McEnroe I know, it feels wrong. 2022-02-18Implement new line editing "library"June McEnroe Losing tab complete and text macros, for now. This new implementation works on an instance of a struct and does not interact with the rest of catgirl, making it possible to copy into another project. Unlike existing line editing libraries, this one is entirely abstract and can be rendered externally. My goal with this library is to be able to implement vi mode. Since it operates on struct instances rather than globals, it might also be possible to give catgirl separate line editing buffers for each window, which would be a nice UX improvement. 2022-02-18Simplify cursor positioning in inputJune McEnroe Do some extra work by adding the portion before the cursor to the input window twice, but simplify the interaction with the split point. This fixes the awkward behaviour when moving the cursor across colour codes where the code would be partially interpreted up to the cursor. 2022-02-18Fix M-f orderingJune McEnroe 2022-02-12Move sandman build to scripts/MakefileJune McEnroe 2022-02-12Use compat_readpassphrase.c on LinuxJune McEnroe 2022-02-12Copy RPP defines from oconfigureJune McEnroe2021-02-07Finish configuring xtermJune McEnroe 2021-02-06Enable tapping, reverse scroll, set scaling in wsconsctlJune McEnroe 2021-02-06Set root window to black on purple snowJune McEnroe 2021-02-06Add xmodmap configurationJune McEnroe 2021-02-06Add initial OpenBSD X configurationJune McEnroe cwm still needs a lot more rebinding, and I need to actually look at its other options. xterm definitely still needs some configuration, but I at least managed to get it to use a decent looking font. Very happy that OpenBSD includes Luxi Mono, which is what my usual font, Go Mono, is based on anyway. Still missing is xmodmap and such. 2021-02-06Add xterm output to schemeJune McEnroe