Permalink
Browse files

Better type expr_ptr

  • Loading branch information...
1 parent 9ac75cc commit bc23f44fa156fc40d710dfd7a2755561f7137445 @jesse99 committed Apr 17, 2012
Showing with 6 additions and 10 deletions.
  1. +3 −5 README.md
  2. +3 −5 src/tests/test_expr.rs
View
@@ -28,12 +28,10 @@ Here is an example of a simple parser which can be used to evaluate mathematical
let int_literal = integer().space0();
// Parenthesized expressions require a forward reference to the expr parser
- // so we initialize a function pointer to something that always fails, create
+ // so we initialize a function pointer to something of the right type, create
// a parser using the parser expr_ptr points to, and fixup expr_ptr later.
- // (We're explicit about the expr_ref type because the type inference in
- // sub_expr has problems if not).
- let expr_ptr = @mut fails("null");
- let expr_ref: parser<int> = forward_ref(expr_ptr);
+ let expr_ptr = @mut return(0);
+ let expr_ref = forward_ref(expr_ptr);
// sub_expr := [-+]? '(' expr ')'
let sub_expr = alternative([
View
@@ -17,12 +17,10 @@ fn expr_parser() -> parser<int>
let int_literal = integer().space0();
// Parenthesized expressions require a forward reference to the expr parser
- // so we initialize a function pointer to something that always fails, create
+ // so we initialize a function pointer to something of the right type, create
// a parser using the parser expr_ptr points to, and fixup expr_ptr later.
- // (We're explicit about the expr_ref type because the type inference in
- // sub_expr has problems if not).
- let expr_ptr = @mut fails("null");
- let expr_ref: parser<int> = forward_ref(expr_ptr);
+ let expr_ptr = @mut return(0);
+ let expr_ref = forward_ref(expr_ptr);
// sub_expr := [-+]? '(' expr ')'
let sub_expr = alternative([

0 comments on commit bc23f44

Please sign in to comment.