Permalink
Browse files

Fix the parse failure ...

  • Loading branch information...
1 parent d08fe3d commit 7b7f0a437d890df971c32e985b42be81f1b36fd3 @samoht committed Nov 26, 2010
Showing with 33 additions and 10 deletions.
  1. +33 −10 pa_lib/cass_parser.ml
View
@@ -1,3 +1,19 @@
+(*
+ * Copyright (c) 2010 Thomas Gazagnaire <thomas@gazagnaire.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *)
+
open Cass_ast
let debug = true
@@ -228,10 +244,12 @@ let rec elt tokens =
and expr tokens =
with_rule "expr" (fun () ->
let elt = elt tokens in
+ let snapshot = copy tokens in
try
let expr = expr tokens in
ESeq (elt, expr)
with Parse_error _ ->
+ restore ~snapshot tokens;
elt)
and exprs tokens =
@@ -240,6 +258,7 @@ and exprs tokens =
let expr = expr tokens in
match look 1 tokens with
| [COMMA] ->
+ ef " COMMA\n";
seek 1 tokens;
let exprs = exprs tokens in
Comma (expr, exprs)
@@ -248,51 +267,55 @@ and exprs tokens =
and prop tokens =
with_rule "prop" (fun () ->
- match look 1 tokens with
- | [PROP p] ->
+ match look 2 tokens with
+ | [PROP p; _ ] ->
ef " PROP: %s\n" p;
seek 1 tokens;
let exprs = exprs tokens in
expect SEMI tokens;
Rule (String p, exprs)
- | [DOLLAR aq] ->
- ef " DOLLAR %s" aq;
- seek 1 tokens;
- maybe SEMI tokens;
- Ant (Cass_location.get (), aq)
| _ ->
let snapshot = copy tokens in
try
let exprs = exprs tokens in
- ef " DECL: ";
expect OPEN tokens;
- ef "(\n";
+ ef " (\n";
let props = props tokens in
expect CLOSE tokens;
ef " )\n";
Decl(exprs, props)
with e ->
restore ~snapshot tokens;
- raise e)
+ match look 1 tokens with
+ | [DOLLAR aq] ->
+ ef " DOLLAR: %s\n" aq;
+ seek 1 tokens;
+ maybe SEMI tokens;
+ Ant (Cass_location.get (), aq)
+ | _ -> raise e)
and props tokens =
with_rule "props" (fun () ->
let prop = prop tokens in
+ let snapshot = copy tokens in
try
let props = props tokens in
RSeq(prop, props)
with Parse_error _ ->
+ restore ~snapshot tokens;
prop)
and all tokens =
with_rule "all" (fun () ->
+ let snapshot = copy tokens in
try
ef " Trying PROP branch:\n";
let res = props tokens in
ef " PROP: success!\n";
res
with Parse_error _ ->
ef " PROP: failed!\n Trying EXPR instead:\n";
+ restore ~snapshot tokens;
let res = exprs tokens in
ef " EXPR: success!\n";
res

0 comments on commit 7b7f0a4

Please sign in to comment.