Questions tagged [fparsec]

A parser combinator library for F#.

FParsec is a parser combinator library for F#.

FParsec’s features include:

  • support for context‐sensitive, infinite look‐ahead grammars,
  • automatically generated, highly readable error messages,
  • Unicode support,
  • efficient support for very large files,
  • an embeddable, runtime‐configurable operator‐precedence parser component,
  • a simple, efficient and easily extensible API,
  • an implementation thoroughly optimized for performance,
  • comprehensive documentation,
  • a permissive open source license.

FParsec is an F# adaptation of Parsec, the popular parser combinator library for Haskell.

FParsec is optimized for an applicative programming style, but it also supports a monadic syntax similar to Parsec's.

See http://www.quanttec.com/fparsec/ for more information.

191 questions
4
votes
1 answer

fparsec OperatorPrecedenceParser : How to deal with incomplete parentheses

This code will read this input "(WEEKEND-SUNDAY)" and then return "SATURDAY" but input "WEEKEND-SUNDAY)" still return "SATURDAY" => this parser ignore last ')' let pDayOfWeekKeyWords = choice [ pstring "MONDAY" ; …
user6826023
4
votes
1 answer

FParsec list of string between special char

When trying to parse {asdc,456,ghji,abc} and I run run specialListParser "{asdc,456,ghji,abc}" the parser fails with The error occurred at the end of the input stream. Expecting: any char not in ‘,’, ',' or '}' I defined my parser based on this…
abhishek
  • 373
  • 1
  • 9
4
votes
1 answer

how do I handle an optional trailing comma?

given the following let maxCount = System.Int32.MaxValue let pmlcomment = pstring "/*" >>. skipCharsTillString "*/" true (maxCount) let ws = pspaces >>. many (pspaces >>. pmlcomment .>> pspaces) |>> (function | [] -> () | _ -> ()) let str_ws s =…
Maslow
  • 18,464
  • 20
  • 106
  • 193
4
votes
1 answer

How to add a condition that a parsed number must satisfy in FParsec?

I am trying to parse an int32 with FParsec but have an additional restriction that the number must be less than some maximum value. Is their a way to perform this without writing my own custom parser (as below) and/or is my custom parser (below) the…
Sam
  • 2,745
  • 3
  • 20
  • 42
4
votes
1 answer

How to parse a very large file in F# using FParsec

I'm trying to parse a very large file using FParsec. The file's size is 61GB, which is too big to hold in RAM, so I'd like to generate a sequence of results (i.e. seq<'Result>), rather than a list, if possible. Can this be done with FParsec? (I've…
Brian Berns
  • 15,499
  • 2
  • 30
  • 40
4
votes
1 answer

How do I test for exactly 2 characters with fparsec?

I have the following program that runs. It takes a line of text and splits it into two parts, the first is an identifier and the second is the remainder of the line. My parser for the identifier (factID) takes any string of characters as the…
JonnyBoats
  • 5,177
  • 1
  • 36
  • 60
4
votes
2 answers

Representing epsilon productions with FParsec parser combinators

It is often convenient to express grammar productions in BNF like A ::= "car" | "bike" | ε where ε represents an empty production rule; i.e., the nonterminal "A" could expand to the terminals "car", "bike", or nothing. However, unless I…
Dan Barowy
  • 2,270
  • 24
  • 35
4
votes
1 answer

Compiling an F# 2.0 project in VS2012

I have a solution for VS2010 that includes some F# projects that work against the F# 2.0 compiler/SDK, leveraging fparsec and fsharp powerpack. I then upgraded my main development machine to VS2012, loaded the solution and was able to compile just…
Bittercoder
  • 11,753
  • 10
  • 58
  • 76
3
votes
1 answer

FParsec Reactive Example

I'm hopeful that someone could potentially post an example of using FParsec where the data is based on some sort of incoming live stream. Some examples could be producing a result based on mouse gestures, generating an alert or notification based on…
Dave
  • 2,386
  • 1
  • 20
  • 38
3
votes
1 answer

Tail-recursion in FParsec

I have encounter a problem with parsers having two branches of recursion. To demonstrate the problem easier, I use a simple grammar of a lambda calculus from the article written by Luca Bolognese as the example: ::= |
pad
  • 41,040
  • 7
  • 92
  • 166
3
votes
2 answers

Parse case-insensitive operators using OperatorPrecedenceParser

Is it possible to parse a non-symbolic operator (e.g., AND, OR) case-insensitively using OperatorPrecedenceParser?
Daniel
  • 47,404
  • 11
  • 101
  • 179
3
votes
2 answers

Improving the readability of a FParsec parser

I have a hand-written CSS parser done in C# which is getting unmanageable and was trying to do it i FParsec to make it more mantainable. Here's a snippet that parses a css selector element made with regexes: var tagRegex =…
Gustavo Guerra
  • 5,319
  • 24
  • 42
3
votes
2 answers

"The value is not a function and cannot be applied." error in F#

I was trying to run the following FParsec code, until by some reason it stopped working: The error I am getting is "The value is not a function and cannot be applied." If I comment out the last line of code (test ns "..") it will not yield an…
devoured elysium
  • 101,373
  • 131
  • 340
  • 557
3
votes
1 answer

FParsec ‘many’ primitive fails when stream.UserState updated

The following routine is a minor and simplified change of the official documentation, "Tracing a parser"“ parser tracing wrapper. let () (parser: Parser<_,USER_STATE>) label : Parser<_,USER_STATE> = fun stream -> do stream.UserState…
rfreytag
  • 955
  • 1
  • 8
  • 24
3
votes
1 answer

F# - Accessing Reference Cells from Different Projects

I'm writing a recursive parser with FParsec, so I'm creating a dummy parser and reference cell with createParserForwardedToRef like so: let pstatement, pstatementref = createParserForwardedToRef() The reference cell is eventually…
Ambika E
  • 93
  • 5