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
3
votes
1 answer

Simple FParsec list example

I'm just getting started with FParsec and can't wrap my head around a simple list parser. Given the input "{ a;b;c d; }" I want to get the result ['a';'b';'c';'d'] If I do let baseChars = ['0'..'9'] @ ['A'..'Z'] @ ['a'..'z'] @ ['_'; '-'] let…
Dylan
  • 1,306
  • 1
  • 11
  • 29
3
votes
2 answers

Recursive parsing grammar consumes input and fails to parse sequence

I'm attempting to write an Augmented Backus-Naur form parser. However, I am coming across a Stack Overflow exception whenever I attempt to parse alternatives. Below is an example which triggers the issue: #r…
Chris Altig
  • 680
  • 3
  • 8
  • 22
3
votes
1 answer

FParsec: how to parse date in fparsec (newbie)

I am using the Bill Casarin post on how to parse delimited files with fparsec, I am dumbing the logic down to get an understanding of how the code works. I am parsing a multi row delimited document into Cell list list structure (for now) where a…
akaphenom
  • 6,728
  • 10
  • 59
  • 109
3
votes
1 answer

F# FParsec parsing multiplication

I am trying to tackle the scariest part of programming for me and that is parsing and ASTs. I am working on a trivial example using F# and FParsec. I am wanting to parse a simple series of multiplications. I am only getting the first term back…
Matthew Crews
  • 4,105
  • 7
  • 33
  • 57
3
votes
1 answer

FParsec and pipe3 make the arguments explicit or add a type notation

I am trying to use the pipe3 function from the FParsec library but I get an error I don't know how to solve. Given the Record type Point = { x: float; y: float } and the following parser let plistoffloats' = pipe3 pfloat (pchar ',' .>> spaces)…
blfuentes
  • 2,731
  • 5
  • 44
  • 72
3
votes
1 answer

Why does FParsec not consume characters parsing a list separator?

The actual scenario below is made up. The purpose of the question is to understand more about what FParsec is doing here. I am parsing a list of the strings (w) and (x) that are separated by one or more space characters ' '. The parser for my…
Sean Kearon
  • 10,987
  • 13
  • 77
  • 93
3
votes
0 answers

FParsec Source Projects Won't Load in VS 2017

I just got the FParsec source from Github and tried to open the solutions in Visual Studio 2017. I have the latest update to VS 2017, version 15.4.4, including Nuget Package Manager 4.4.0. I have both the .NET Desktop and .NET Core workflows…
3
votes
1 answer

How to extract data from F# list

Following up my previous question, I'm slowly getting the hang of FParsec (though I do find it particularly hard to grok). My next newbie F# question is, how do I extract data from the list the parser creates? For example, I loaded the sample code…
David White
  • 3,014
  • 1
  • 32
  • 35
3
votes
1 answer

FParsec failing on optional parser

I am currently learning the FParsec library, but I have come across an issue. When I want to parse an optional string and continue parsing as normal afterwards, FParsec will return a fatal error on the optional parser, rather than returning None as…
Chris Altig
  • 680
  • 3
  • 8
  • 22
3
votes
1 answer

Generating errors in FParsec's OperatorPrecedenceParser

I have the need to generate errors while parsing operators using FParsec's OperatorPrecedenceParsers, specifically during the mapping phase. Suppose I have the following code: let pOperatorExpr : ExpressionParser = let opp = new…
3
votes
1 answer

fparsec to parse sequence of string

I have an user input text like "abc,def,ghi". I want to parse it to get list of string as ["abc", "def"]. I tried let str : Parser<_> = many1Chars (noneOf ",") let listParser : Parser<_> = many (str);; but it always give me the first item only…
abhishek
  • 373
  • 1
  • 9
3
votes
1 answer

fparsec parsing alternatives with discriminated unions for DSL

I am trying to achieve below with fparsec and unions (1 + (2 * 3)) //DSL sample input(recursive) type AirthmeticExpression = | Constant of float | AddNumber of AirthmeticExpression * AirthmeticExpression | Mul of…
abhishek
  • 373
  • 1
  • 9
3
votes
0 answers

fparsec get index while parsing

Learning f# using fparsec to parse some delimited data. I am using sepBy to get a list of results and filtering out the empty results. I don't want items that are empty but I do want to know what position the items were in. Is there a better way…
3
votes
1 answer

Making the OperatorPrecedenceParser parse an Optional (opt) expression

I'm implementing a parser that implements a specific domain specific language for a project of mine. One aspect that I'm having difficulty is with making an expression (which is implemented using the OperatorPrecedenceParser from FParsec) such that…
Nathan
  • 35
  • 5
3
votes
1 answer

FParsec only parses expr between parentheses

I am coding a parser (for learning pourpuses). I want it to parse constructions like let myVar be 40 plus 2 and let myVar be (40 plus 2) With no problems... but my parser does not "understand" the former. It sees the 40 and thinks "well, it's a…
Gabriel
  • 1,922
  • 2
  • 19
  • 37