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
13
votes
2 answers

Are there any known parser combinator library's in F# that can parse binary (not text) files?

I am familiar with some of the basics of fparsec but it seems to be geared towards text files or streams. Are there any other F# library's that can efficiently parse binary files? Or can fparsec be easily modified to work efficiently with binary…
7sharp9
  • 2,147
  • 16
  • 27
12
votes
2 answers

Sample grammars in FParsec going beyond the samples?

I am looking for some sample grammars written in FParsec that would go beyond the samples in the project repository. I have found this very nice grammar of GLSL, but this is the only sample I found. What I need is a grammar for a language similar to…
Alexander Galkin
  • 12,086
  • 12
  • 63
  • 115
11
votes
1 answer

Recursive grammars in FParsec

I've decided to check out FParsec, and tried to write a parser for λ expressions. As it turns out, eagerness makes recursive parsing difficult. How can I solve this? Code: open FParsec type λExpr = | Variable of char | Application of λExpr…
Ramon Snir
  • 7,520
  • 3
  • 43
  • 61
10
votes
1 answer

Problems when trying to run FParsec in F# Interactive

I'm trying to run some FParsec code in F# Interactive but with no success. I am able to build and run this tutorial.fs file, but the same isn't happening with FSI, as it didn't recognize FParsec.dll. I've already tried running the #r "Parsec"…
devoured elysium
  • 101,373
  • 131
  • 340
  • 557
8
votes
1 answer

Parsing numbers in FParsec

I've started learning FParsec. It has a very flexible way to parse numbers; I can provide a set of number formats I want to use: type Number = | Numeral of int | Decimal of float | Hexadecimal of int | Binary of int let numberFormat…
pad
  • 41,040
  • 7
  • 92
  • 166
8
votes
1 answer

How to parse comments with FParsec

I'm attempting to parse lisp-style comments from an s-expression language with FParsec. I got a bit of help with parsing single-line comments in this previous thread - How to convert an FParsec parser to parse whitespace While that was resolved, I…
Bryan Edds
  • 1,696
  • 12
  • 28
8
votes
1 answer

FParsec: How do I save the text on which a parser succeeds

In order to create better error messages in a later step I want to save the positions on which a parser succeeds as well as the text. Getting the positions seems pretty easy (since there is the getPosition parser), but I don't know how I can access…
danielspaniol
  • 2,228
  • 21
  • 38
8
votes
1 answer

Detect when FParsec has not parsed all the input

How can you detect when an FParsec parser has stopped without parsing all the input? For example, the following parser p stops when it finds the unexpected character d and does not continue to parse the remainder of the input. let test p str = …
Sean Kearon
  • 10,987
  • 13
  • 77
  • 93
8
votes
2 answers

Parsing int or float with FParsec

I'm trying to parse a file, using FParsec, which consists of either float or int values. I'm facing two problems that I can't find a good solution for. 1 Both pint32 and pfloat will successfully parse the same string, but give different answers,…
larsjr
  • 665
  • 7
  • 17
7
votes
1 answer

Parsing function application with FParsec using OperatorPrecedenceParser?

The question is similar to this one, but I want to parse an expression with function application using the OperatorPrecedenceParser in FParsec. Here is my AST: type Expression = | Float of float | Variable of VarIdentifier | BinaryOperation of…
Alexander Galkin
  • 12,086
  • 12
  • 63
  • 115
7
votes
1 answer

A simple lambda calculus parser with FParsec

I'm new to F# and have a pretty annoying problem. I want to parse the following grammar: Application := Expression Expression Expression := "(" "lambda" Name "." Application ")" | Name Name := [a-z]+ That would match things…
gosukiwi
  • 1,569
  • 1
  • 27
  • 44
7
votes
3 answers

Use FParsec to parse a self-describing input

I'm using FParsec to parse an input that describes its own format. For example, consider this input: int,str,int:4,'hello',3 The first part of the input (before the colon) describes the format of the second part of the input. In this case, the…
Brian Berns
  • 15,499
  • 2
  • 30
  • 40
7
votes
1 answer

Is possible to parse "off-side" (indentation-based) languages with fparsec?

I wish to use FParsec for a python-like language, indentation-based. I understand that this must be done in the lexing phase, but FParsec don't have a lexing phase. Is possible to use FParsec, or, how can feed it after lexing? P.D: I'm new at F#,…
mamcx
  • 15,916
  • 26
  • 101
  • 189
6
votes
1 answer

Basic error recovery with FParsec

Assume I've this parser: let test p str = match run p str with | Success(result, _, _) -> printfn "Success: %A" result | Failure(errorMsg, _, _) -> printfn "Failure: %s" errorMsg let myStatement = choice (seq [ …
Lasse Espeholt
  • 17,622
  • 5
  • 63
  • 99
6
votes
1 answer

Position information in fparsec

My AST model needs to carry location information (filename, line, index). Is there any built in way to access this information? From the reference docs, the stream seems to carry the position, but I'd prefer that I dont have to implement a dummy…
hammett
  • 705
  • 4
  • 13
1
2 3
12 13