about summary refs log tree commit diff
path: root/src/comp/syntax/parse/parser.rs
diff options
context:
space:
mode:
authorMarijn Haverbeke <marijnh@gmail.com>2012-01-26 15:52:28 +0100
committerMarijn Haverbeke <marijnh@gmail.com>2012-01-26 15:52:28 +0100
commit6bead0e4ccfa65a89bee8db6d4587e297fba1a57 (patch)
treec50c451789f8c0227ff0f5a38b3b39d078d0f7e8 /src/comp/syntax/parse/parser.rs
parent3aed4b04cee15408536e9d89b866dc16447d1afb (diff)
downloadrust-6bead0e4ccfa65a89bee8db6d4587e297fba1a57.tar.gz
rust-6bead0e4ccfa65a89bee8db6d4587e297fba1a57.zip
Use operator names for operator methods
The methods used to implement operators now simply use
the name of the operator itself, except for unary -, which is called
min to not clash with binary -. Index is called [].

Closes #1520
Diffstat (limited to 'src/comp/syntax/parse/parser.rs')
-rw-r--r--src/comp/syntax/parse/parser.rs13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs
index 3d6b76db628..8b2d6cf36a7 100644
--- a/src/comp/syntax/parse/parser.rs
+++ b/src/comp/syntax/parse/parser.rs
@@ -284,7 +284,7 @@ fn parse_ty_methods(p: parser) -> [ast::ty_method] {
     parse_seq(token::LBRACE, token::RBRACE, seq_sep_none(), {|p|
         let flo = p.span.lo;
         expect_word(p, "fn");
-        let ident = parse_value_ident(p);
+        let ident = parse_method_name(p);
         let tps = parse_ty_params(p);
         let f = parse_ty_fn(ast::proto_bare, p), fhi = p.last_span.hi;
         expect(p, token::SEMI);
@@ -1824,10 +1824,19 @@ fn parse_item_fn(p: parser, purity: ast::purity,
                 ast::item_fn(decl, t.tps, body), attrs);
 }
 
+fn parse_method_name(p: parser) -> ast::ident {
+    alt p.token {
+      token::BINOP(op) { p.bump(); token::binop_to_str(op) }
+      token::NOT { p.bump(); "!" }
+      token::LBRACKET { p.bump(); expect(p, token::RBRACKET); "[]" }
+      _ { parse_value_ident(p) }
+    }
+}
+
 fn parse_method(p: parser) -> @ast::method {
     let lo = p.span.lo;
     expect_word(p, "fn");
-    let ident = parse_value_ident(p);
+    let ident = parse_method_name(p);
     let tps = parse_ty_params(p);
     let decl = parse_fn_decl(p, ast::impure_fn);
     let body = parse_block(p);