Skip to content

Instantly share code, notes, and snippets.

@moriyoshi
Last active August 29, 2015 14:02
Show Gist options
  • Save moriyoshi/edd45964c9666b7305dc to your computer and use it in GitHub Desktop.
Save moriyoshi/edd45964c9666b7305dc to your computer and use it in GitHub Desktop.
Allowing a colon between the argument name and type
diff -r 5bf1a8b3aeea src/cmd/gc/go.y
--- a/src/cmd/gc/go.y Thu May 29 13:47:31 2014 -0400
+++ b/src/cmd/gc/go.y Tue Jun 03 11:47:44 2014 +0900
@@ -43,6 +43,7 @@
%token <sym> LIF LIMPORT LINTERFACE LMAP LNAME
%token <sym> LPACKAGE LRANGE LRETURN LSELECT LSTRUCT LSWITCH
%token <sym> LTYPE LVAR
+%token <sym> LRARROW
%token LANDAND LANDNOT LBODY LCOMM LDEC LEQ LGE LGT
%token LIGNORE LINC LLE LLSH LLT LNE LOROR LRSH
@@ -1446,19 +1447,22 @@
$$ = list1(nod(OEMPTY, N, N));
}
+orarrow:
+| LRARROW
+
fnres:
%prec NotParen
{
$$ = nil;
}
-| fnret_type
+| orarrow fnret_type
{
- $$ = list1(nod(ODCLFIELD, N, $1));
+ $$ = list1(nod(ODCLFIELD, N, $2));
}
-| '(' oarg_type_list_ocomma ')'
+| orarrow '(' oarg_type_list_ocomma ')'
{
- $2 = checkarglist($2, 0);
- $$ = $2;
+ $3 = checkarglist($3, 0);
+ $$ = $3;
}
fnlitdcl:
@@ -1655,6 +1659,12 @@
*/
arg_type:
name_or_type
+| sym ':' name_or_type
+ {
+ $$ = nod(ONONAME, N, N);
+ $$->sym = $1;
+ $$ = nod(OKEY, $$, $3);
+ }
| sym name_or_type
{
$$ = nod(ONONAME, N, N);
diff -r 5bf1a8b3aeea src/cmd/gc/lex.c
--- a/src/cmd/gc/lex.c Thu May 29 13:47:31 2014 -0400
+++ b/src/cmd/gc/lex.c Tue Jun 03 11:47:44 2014 +0900
@@ -1121,6 +1121,10 @@
c = OSUB;
goto asop;
}
+ if(c1 == '>') {
+ c = LRARROW;
+ goto lx;
+ }
break;
case '>':
@@ -2210,6 +2214,7 @@
LRANGE, "RANGE",
LRETURN, "RETURN",
LRSH, "RSH",
+ LRARROW, "->",
LSELECT, "SELECT",
LSTRUCT, "STRUCT",
LSWITCH, "SWITCH",
@@ -2262,6 +2267,7 @@
"LPACKAGE", "package",
"LRANGE", "range",
"LRETURN", "return",
+ "LRARROW", "->",
"LSELECT", "select",
"LSTRUCT", "struct",
"LSWITCH", "switch",
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment