# Example for an AbstractToken from TextParse for a JuliaDB

**URL:** <https://discourse.julialang.org/t/example-for-an-abstracttoken-from-textparse-for-a-juliadb/20945>\
**Category:** General Usage\
**Tags:** question, juliadb\
**Created:** [February 18, 2019, 6:12pm UTC](https://discourse.julialang.org/t/example-for-an-abstracttoken-from-textparse-for-a-juliadb/20945 "2019-02-18T18:12:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [February 18, 2019, 6:12pm UTC](https://discourse.julialang.org/t/example-for-an-abstracttoken-from-textparse-for-a-juliadb/20945/1 "2019-02-18T18:12:24Z")

</div>

In `JuliaDB`’s [documentation](https://github.com/JuliaComputing/JuliaDB.jl/blob/bcbd5f6e05b0d5afa7cb75f63f6d6e2a4bec5588/src/io.jl#L55) for `loadtable`, there is an explanation of how to use an `AbstractToken` object from `TextParse` in order to parse columns from a `CSV` file.

Has anyone managed to do that? Say correctly parse numbers to `Nanosecond` or some such? Do you have a simple example of that? I understand that I need to implement `tryparsenext` but I’d appreciate seeing a short example of how to do that for something simple (like the `Nanosecond` thing).

Thanks!

---

<div class="post-metadata">

**Author:** ![Glen1](https://avatars.discourse-cdn.com/v4/letter/g/ee7513/32.png) [@Glen1](https://discourse.julialang.org/u/Glen1)\
**Post date:** [February 26, 2019, 6:52pm UTC](https://discourse.julialang.org/t/example-for-an-abstracttoken-from-textparse-for-a-juliadb/20945/2 "2019-02-26T18:52:39Z")

</div>

> [@yakir12](#):
>
> Say correctly parse numbers to `Nanosecond` or some su

I’d also love to find the answer to this!

---

<div class="post-metadata">

**Author:** ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)\
**Post date:** [March 18, 2019, 3:55am UTC](https://discourse.julialang.org/t/example-for-an-abstracttoken-from-textparse-for-a-juliadb/20945/3 "2019-03-18T03:55:54Z")

</div>

The docs in [TextParse.jl](https://github.com/JuliaComputing/TextParse.jl) for this are incorrect right now, a [fix](https://github.com/JuliaComputing/TextParse.jl/pull/122) is coming.

Here is an example that works:

```julia
myparser = CustomParser(Bool) do str, i, len, opts
    if i+3 <= len && str[i:i+3] == "true"
        return Nullable(true), i+4
    elseif i+4 <= len && str[i:i+4] == "false"
        return Nullable(false), i+5
    else
        return Nullable{Bool}(), i
    end
end

csvread("test.csv", colparsers=Dict(2=>myparser))

```

For the kind of use-case you mentioned, you would probably call one of the existing `tryparsenext` methods from `TextParse` first, and then just convert the result into something else.

We should make that use case a bit easier, see [here](https://github.com/JuliaComputing/TextParse.jl/issues/123).
