Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

removed: negate; renamed: ahead -> (git diff)

  • Loading branch information...
commit fcfd1bbb9a0b9aeab113269f7430b25b49b4b77a 1 parent acc1098
@cetinsert cetinsert authored
Showing with 40 additions and 47 deletions.
  1. +24 −28 XParsec.fs
  2. +16 −19 XParsec.fsi
View
52 XParsec.fs
@@ -12,9 +12,9 @@ module XParsec
open System
-
let inline Δ<'a> = Unchecked.defaultof<'a>
+
[<Struct>]
type Source<'s,'a> =
val State : 's
@@ -45,8 +45,7 @@ module Combinators =
let inline current (s : Source<_,_>) = S <| s.Current,s
let inline future () = let r = ref Δ in (fun s-> !r s), r : Parser<_,_,_> * Parser<_,_,_> ref
- let inline ahead (p : Parser<_,_,_>) s = let r,_ = p s in r,s
@cetinsert Owner

Was confusing as ahead could be used in any direction, not just forward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
- let inline negate (p : Parser<_,_,_>) s = let r,s = p s in Reply<_>.negate r,s
@cetinsert Owner

(~-) provides the same functionality!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ let inline (!!) (p : Parser<_,_,_>) s = let r,_ = p s in r,s
@cetinsert Owner

Following the selector subject syntax from CSS4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
let inline (~-) (p : Parser<_,_,_>) s = let r,s = p s in Reply<_>.negate r,s
let inline (=>) (p : Parser<_,_,_>) f s = let r,s = p s in Reply<_>.map f r,s
let inline (?>) (p : Parser<_,_,_>) f s = let r,s = p s in Reply<_>.choose f r,s
@@ -83,6 +82,27 @@ module Combinators =
let inline (>>=) (p : Parser<'s,'a,'b>) f s = let r,s = p s in match r with Q -> Q,s | F -> F,s | S b -> f b s
+module Array =
+
+ type Position = Int32
+ type 'a Stream = Source<'a [], Position>
+ let pre = Position.MinValue
+ let post = Position.MaxValue
+
+ let inline clamp l u n = l |> max <| n |> min <| u
+ let inline (|?|) a i = i > - 1 && i < (a:_[]).Length
+
+ module Array =
+ let inline source i (s : _ seq) = let a = Seq.toArray s in let i = clamp -1 a.Length i in Source(Source(a, i), if a |?| i then a.[i] else Δ)
+
+ module Navigation =
+ type Σ<'s,'a> = Source<'s,'a>
+ let inline σ (s : Source< _, _>) = s.State
+ let inline χ (s : Source< _, _>) = s.Current
+ let inline next s = let a : _ [] = σ (σ s) in let c = χ (σ s) + 1 in match c < a.Length with false -> Q,s | true -> S a.[c],Σ(Σ(a,c),a.[c])
+ let inline prev s = let a : _ [] = σ (σ s) in let c = χ (σ s) - 1 in match c > -1 with false -> Q,s | true -> S a.[c],Σ(Σ(a,c),a.[c])
+
+
module Xml =
@cetinsert Owner

Will be moved to its own file as it depends on assemblies System.Xml and System.Xml.Linq which should not be forced on anyone who wants use XParsec with other elemental types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
open System.Xml.Linq
@@ -92,7 +112,6 @@ module Xml =
type N = string
type V = string
-
module Operators =
let inline (!>) x = ( ^a : (static member op_Implicit : ^b -> ^a) x )
@@ -111,7 +130,6 @@ module Xml =
let inline value x = ( ^a : (member Value : string) x )
open Operators
-
module Parsers =
@@ -123,7 +141,6 @@ module Xml =
let inline ( @~? ) n v (s : Source<_,E>) = ((s.Current @? n <| v) |> Reply<_>.fromBool),s
let inline ( @~! ) n v (s : Source<_,E>) = ((s.Current @! n <| v) |> Reply<_>.fromBool),s
-
module Navigation =
type N = XNode
@@ -141,25 +158,4 @@ module Xml =
module Parsers =
open Combinators
- let inline children p = ahead (child>.p .>. many (next>.p)) => function c,cs -> c::cs
-
-
-module Array =
-
- type Position = Int32
- type 'a Stream = Source<'a [], Position>
- let pre = Position.MinValue
- let post = Position.MaxValue
-
- let inline clamp l u n = l |> max <| n |> min <| u
- let inline (|?|) a i = i > - 1 && i < (a:_[]).Length
-
- module Array =
- let inline source i (s : _ seq) = let a = Seq.toArray s in let i = clamp -1 a.Length i in Source(Source(a, i), if a |?| i then a.[i] else Δ)
-
- module Navigation =
- type Σ<'s,'a> = Source<'s,'a>
- let inline σ (s : Source< _, _>) = s.State
- let inline χ (s : Source< _, _>) = s.Current
- let inline next s = let a : _ [] = σ (σ s) in let c = χ (σ s) + 1 in match c < a.Length with false -> Q,s | true -> S a.[c],Σ(Σ(a,c),a.[c])
- let inline prev s = let a : _ [] = σ (σ s) in let c = χ (σ s) - 1 in match c > -1 with false -> Q,s | true -> S a.[c],Σ(Σ(a,c),a.[c])
+ let inline children p = ahead (child>.p .>. many (next>.p)) => function c,cs -> c::cs
View
35 XParsec.fsi
@@ -5,9 +5,9 @@ module XParsec
open System
-
val inline Δ<'a> : 'a
+
[<Struct>]
type Source<'s,'a> =
val State : 's
@@ -38,8 +38,7 @@ module Combinators =
val inline current : Parser<'s,'a,'a>
val inline future : unit -> Parser<'s,'a,'b> * Parser<'s,'a,'b> ref
- val inline ahead : Parser<'s,'a,'b> -> Parser<'s,'a,'b>
- val inline negate : Parser<'s,'a,'b> -> Parser<'s,'a,unit>
+ val inline ( !! ) : Parser<'s,'a,'b> -> Parser<'s,'a,'b>
val inline ( ~- ) : Parser<'s,'a,'b> -> Parser<'s,'a,unit>
val inline ( => ) : Parser<'s,'a,'b> -> ('b -> 'c) -> Parser<'s,'a,'c>
val inline ( ?> ) : Parser<'s,'a,'b> -> ('b -> 'c option) -> Parser<'s,'a,'c>
@@ -65,6 +64,19 @@ module Combinators =
val inline ( >>= ) : Parser<'s,'a,'b> -> ('b -> Parser<'s,'a,'c>) -> Parser<'s,'a,'c>
+
+module Array =
+ type Position = Int32
+ type 'a Stream = Source<'a [], Position>
+ val pre : Position
+ val post : Position
+ module Array = val inline source : Position -> 'a seq -> Source<'a Stream,'a>
+ [<AutoOpen>]
+ module Navigation =
+ val inline next : Parser<'a Stream,'a,'a>
+ val inline prev : Parser<'a Stream,'a,'a>
+
+
module Xml =
open System.Xml.Linq
@@ -74,7 +86,6 @@ module Xml =
type N = string
type V = string
-
[<AutoOpen>]
module Operators =
val inline ( !> ) : ^b -> ^a when ^a : (static member op_Implicit : ^b -> ^a)
@@ -92,7 +103,6 @@ module Xml =
val inline name : ^x -> N when ^x : (member Name : XName)
val inline value : ^x -> V when ^x : (member Value : V)
-
[<AutoOpen>]
module Parsers =
val inline ( !<> ) : N -> Parser<'s,E,E>
@@ -103,7 +113,6 @@ module Xml =
val inline ( @~? ) : N -> V -> Parser<'s,E,unit>
val inline ( @~! ) : N -> V -> Parser<'s,E,unit>
-
[<AutoOpen>]
module Navigation =
type XElement with
@@ -117,16 +126,4 @@ module Xml =
val child : Parser<E,E,E>
[<AutoOpen>]
module Parsers =
- val inline children : Parser<E,E,'b> -> Parser<E,E,'b list>
-
-
-module Array =
- type Position = Int32
- type 'a Stream = Source<'a [], Position>
- val pre : Position
- val post : Position
- module Array = val inline source : Position -> 'a seq -> Source<'a Stream,'a>
- [<AutoOpen>]
- module Navigation =
- val inline next : Parser<'a Stream,'a,'a>
- val inline prev : Parser<'a Stream,'a,'a>
+ val inline children : Parser<E,E,'b> -> Parser<E,E,'b list>
Please sign in to comment.
Something went wrong with that request. Please try again.