Permalink
Browse files

Changed parser ignore function to forget in order to avoid name colli…

…sion
  • Loading branch information...
devhawk committed Dec 3, 2008
1 parent 1ca850f commit 29466c826cd86f83ea4816d60a58b9704483c2c8
Showing with 28 additions and 29 deletions.
  1. +6 −6 Cashel/Cashel.Peg/peg.fs
  2. +17 −17 Cashel/Cashel.Peg/peg2.fs
  3. +1 −1 Cashel/Cashel.Tests/primitives_test.fs
  4. +4 −5 Cashel/Cashel/primitives.fs
View
@@ -251,7 +251,7 @@ let Class =
parser {
do! skip_item '['
let! rl = repeat_until Range (item_equal ']')
- do! ignore Spacing
+ do! forget Spacing
return rl
}
@@ -260,7 +260,7 @@ let Literal =
let literal_workhorse ch = parser {
do! skip_item ch
let! cl = repeat_until Char (item_equal ch)
- do! ignore Spacing
+ do! forget Spacing
return cl }
literal_workhorse ''' +++ literal_workhorse '"'
@@ -275,7 +275,7 @@ let Identifier =
parser {
let! c = IdentStart
let! cs = repeat IdentCont
- do! ignore Spacing
+ do! forget Spacing
return c::cs }
@@ -288,9 +288,9 @@ let rec pPrimary =
return Primary.Identifier(id) }
+++
parser {
- do! ignore OPEN
+ do! forget OPEN
let! exp = Expression
- do! ignore CLOSE
+ do! forget CLOSE
return Primary.Expression(exp) }
+++
parser {
@@ -328,7 +328,7 @@ and Expression =
let Definition =
parser {
let! id = Identifier
- do! ignore LEFTARROW
+ do! forget LEFTARROW
let! ex = Expression
return {name=id;exp=ex} }
View
@@ -202,34 +202,34 @@ let _EndOfFile = !~ item
let _EndOfLine = parser {
return! items_equal (List.of_seq "\r\n")
return! item_equal '\n' |> listify
- return! item_equal '\r' |> listify } |> ignore
+ return! item_equal '\r' |> listify } |> forget
///Space <- ' ' / '\t' / EndOfLine
let _Space = parser {
- return! item_equal ' ' |> ignore
- return! item_equal '\t' |> ignore
- return! _EndOfLine } |> ignore
+ return! item_equal ' ' |> forget
+ return! item_equal '\t' |> forget
+ return! _EndOfLine } |> forget
///SlashComment <- '//' (!EndOfLine .)* EndOfLine
let _SlashComment = parser {
do! skip_items ['/';'/']
- do! repeat_until item _EndOfLine |> ignore
+ do! repeat_until item _EndOfLine |> forget
return () }
///Comment <- '#' (!EndOfLine .)* EndOfLine
let _Comment = parser {
do! skip_item '#'
- do! repeat_until item _EndOfLine |> ignore
+ do! repeat_until item _EndOfLine |> forget
return () }
///Spacing <- (Space / Comment)*
-let _Spacing = ignore (parser {
+let _Spacing = forget (parser {
return! _Space
return! _SlashComment
return! _Comment } |> repeat)
let parse p = _Spacing >>. p
-let token p = ignore (p .>> _Spacing)
+let token p = forget (p .>> _Spacing)
///DOT <- '.' Spacing
let _DOT = token (item_equal '.')
@@ -327,7 +327,7 @@ let _Class =
parser {
do! skip_item '['
let! rl = repeat_until _Range (item_equal ']')
- do! ignore _Spacing
+ do! forget _Spacing
return rl
}
@@ -337,7 +337,7 @@ let _Literal =
parser {
do! skip_item ch
let! cl = repeat_until _Char (item_equal ch)
- do! ignore _Spacing
+ do! forget _Spacing
return List2String cl }
literal_workhorse ''' +++ literal_workhorse '"'
@@ -347,7 +347,7 @@ let _Identifier =
parser {
let! c = any_of (['_'] @ ['a'..'z'] @ ['A'..'Z'])
let! cs = repeat (any_of (['_'] @ ['a'..'z'] @ ['A'..'Z'] @ ['0'..'9']))
- do! ignore _Spacing
+ do! forget _Spacing
return List2String (c::cs) }
//Stub out Action for now
@@ -361,9 +361,9 @@ let rec _Primary =
return Identifier(id) }
+++
parser {
- do! ignore _OPAREN
+ do! forget _OPAREN
let! prod = _Production
- do! ignore _CPAREN
+ do! forget _CPAREN
return Production(prod) }
+++
parser {
@@ -388,7 +388,7 @@ and _PatternItem =
+++
parser {
let! id = _Identifier
- do! _COLON |> ignore
+ do! _COLON |> forget
return Variable(id) }
let _Arity =
@@ -415,16 +415,16 @@ and _Production =
let _Rule =
parser {
let! id = _Identifier
- do! ignore _LEFTARROW
+ do! forget _LEFTARROW
let! p = _Production
let! pl = repeat (_SLASH >>. _Production)
- do! ignore _SEMICOLON
+ do! forget _SEMICOLON
return {name=id;productions=p::pl} }
///Grammar <- Spacing Identifier OCURLY Rule+ CCURLY EndOfFile
let _Grammar =
parser {
- do! ignore _Spacing
+ do! forget _Spacing
let! id = _Identifier
do! _OCURLY
let! rl = repeat1 _Rule
@@ -24,7 +24,7 @@ let test_item_single_item () =
[<Fact>]
let test_ignore_with_item () =
let exp = Some((), !!"est")
- ignore item !!"test" |> should equal exp
+ forget item !!"test" |> should equal exp
[<Fact>]
let test_listify_with_item () =
@@ -18,8 +18,8 @@ let (.>>) p1 p2 = p1 >>= (fun v -> p2 >>= (fun _ -> result v))
///Custom bind operator .>> binds p1 to p2, then returns the parse value of p2
let (>>.) p1 p2 = p1 >>= (fun _ -> p2 >>= (fun v -> result v))
-///ignore tosses the result of parsing function p
-let ignore p = p >>$ ()
+///forget tosses the result of parsing function p
+let forget p = p >>$ ()
///listify turns the result of parsing function p into a single item list
let listify p = p >>= (fun x -> result [x])
@@ -86,10 +86,10 @@ let rec items_equal l =
| x::xs -> item_equal x >>= (fun i -> items_equal xs >>= (fun is -> result (i::is)))
///skip_item calls item_equal but tosses the parse value
-let skip_item v = item_equal v |> ignore
+let skip_item v = item_equal v |> forget
///skip_items calls items_equal but tosses the parse value
-let skip_items l = items_equal l |> ignore
+let skip_items l = items_equal l |> forget
//-------------------------char list primitives-------------------------------------------
@@ -104,4 +104,3 @@ let add_line_and_col cl =
| [] -> []
worker cl 1 1
-

0 comments on commit 29466c8

Please sign in to comment.