Introducing Barb
The first thing you need to know about Barb is how to generate a function. This is done by calling the buildExpr function with the types you expect as well as your expected result.
1: 2: 3: 4: 5: 6: |
|
Barb was originally designed for queries on DOM-like data trees. Let's start with a simple example.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: |
|
You can easily query this simple record for various information. To do this efficiently first generate the function and then call it as you'd like over each record. Members of the input type are automatically put into scope as variables to make this easy.
1: 2: 3: |
|
This is where set operators come into play, as they allow you to do simple contains/overlap queries easily. In this example we're using the has-intersection operator.
1: 2: 3: |
|
Sometimes you may want to map a method call over a collection of items. This can be done with the .. syntax (one dot per level of collection).
1: 2: 3: |
|
When a Barb fails it tries its best gives you the offset where something went wrong. Here we're going to access a variable that doesn't exist. This makes it easy to report what went wrong to the user, even when they have a long function string.
1: 2: 3: 4: 5: 6: 7: 8: 9: |
|
from Barb
Full name: Tutorial.func
Full name: Barb.Compiler.buildExpr
Full name: Microsoft.FSharp.Core.unit
val string : value:'T -> string
Full name: Microsoft.FSharp.Core.Operators.string
--------------------
type string = System.String
Full name: Microsoft.FSharp.Core.string
Full name: Tutorial.result
Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
{Name: string;
Countries: string [];}
Full name: Tutorial.MyRecord
val string : value:'T -> string
Full name: Microsoft.FSharp.Core.Operators.string
--------------------
type string = String
Full name: Microsoft.FSharp.Core.string
Full name: Tutorial.testRecords
Full name: Tutorial.rickFun
Full name: Microsoft.FSharp.Core.bool
module List
from Microsoft.FSharp.Collections
--------------------
type List<'T> =
| ( [] )
| ( :: ) of Head: 'T * Tail: 'T list
interface IEnumerable
interface IEnumerable<'T>
member GetSlice : startIndex:int option * endIndex:int option -> 'T list
member Head : 'T
member IsEmpty : bool
member Item : index:int -> 'T with get
member Length : int
member Tail : 'T list
static member Cons : head:'T * tail:'T list -> 'T list
static member Empty : 'T list
Full name: Microsoft.FSharp.Collections.List<_>
Full name: Microsoft.FSharp.Collections.List.filter
Full name: Tutorial.countryFun
Full name: Tutorial.dotFun
from Barb
Full name: Tutorial.failFunStr
Full name: Microsoft.FSharp.Collections.List.map
Full name: Microsoft.FSharp.Core.Operators.ignore
type BarbException =
inherit Exception
new : message:string * offset:uint32 * length:uint32 -> BarbException
member Length : uint32
member Offset : uint32
Full name: Barb.Representation.BarbException
--------------------
new : message:string * offset:uint32 * length:uint32 -> BarbException
String.Substring(startIndex: int, length: int) : string
val int : value:'T -> int (requires member op_Explicit)
Full name: Microsoft.FSharp.Core.Operators.int
--------------------
type int = int32
Full name: Microsoft.FSharp.Core.int
--------------------
type int<'Measure> = int
Full name: Microsoft.FSharp.Core.int<_>