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
1
vote
1 answer

FParsec combinator to turn Parser until Parser?

I'm certain there's a really simple answer to this, but I've been staring at this all day and I can't figure it out. As per the tutorial, I'm implementing a JSON parser. To challenge myself, I'm implementing the number parser myself. This is what I…
Rei Miyasaka
  • 7,007
  • 6
  • 42
  • 69
1
vote
1 answer

String and CharStream<'a> in FParsec

I would like to parse a big sentence, which can contain names in fsharp. I posit that names is in the form first name + last name. In the absence of a first name list (can't find, will do later), I say that a first name is a string of length 4 or…
nicolas
  • 9,549
  • 3
  • 39
  • 83
0
votes
1 answer

How to make identifier parser stop on operators of OperationPrecedenceParser in FParsec?

I am implementing a parser for identifier names that would consume unicode symbols. The problem I am facing is what I have some operators that are also written with unicode symbols and these might be placed directly after the identifier, for…
Alexander Galkin
  • 12,086
  • 12
  • 63
  • 115
0
votes
1 answer

Problems with Forward References in FParsec

I'm trying to write a Parser with FParsec to parse nested boolean expressions, for instance: false true and(false,true,true,true,true) or(true,true) and(or(false,true),and(true,true,true,true)) Because my grammar involves mutually recursive…
apio
  • 154
  • 11
0
votes
1 answer

How to parse a fixed string with FParsec

I'm trying to parse fixed strings with FParsec. For example parsing null from the documentation: open FParsec type Json = JNull let jnull : Parser<_> = stringReturn "null" JNull then running jnull on "null" gives the expected result > run jnull…
Roald
  • 2,459
  • 16
  • 43
0
votes
1 answer

FParsec failing at the end of a spaces separated list, expecting another element of the list

I am trying to use FParsec to parse a list of zero or more elements of the form [string] where the string in the middle can be anything (except ] as to disambiguate from the end of the string). Here is my code as is: let parseArgumentList :…
ajax2112
  • 228
  • 1
  • 6
0
votes
2 answers

Using FParsec to parse possibly malformed input

I'm writing a parser for a specific file format using FParsec as a firstish foaray into learning fsharp. Part of the file has the following format { 123 456 789 333 } Where the numbers in the brackets are pairs of values and there can be an…
Emil L
  • 20,219
  • 3
  • 44
  • 65
0
votes
1 answer

Create a sepBy parser combinator sensitive to the indentation of the first parser

Via FParsec and using this lib (whose code, which is quite short, has been copied to the end of the question), I'm trying to design a sepBy-like parser that is sensitive to the indentation of the first parser passed in argument. Typically, if I give…
Foxy
  • 980
  • 8
  • 17
0
votes
2 answers

F# list of discriminated union sub-types

I want to present the user with a list of 'FParsec parsers'-plus-'test data' from which they can interactively select and see the results of the parser run on the supplied text. Specifically, am trying to collect my parser tests in a list of records…
rfreytag
  • 955
  • 1
  • 8
  • 24
0
votes
2 answers

How can I express a type in F# that optionally recurses on itself (infinitely)

As a learning exercise I am trying to implment a parser for the graphviz dot language (The DOT language) using the functional parser library fparsec (FParsec). The language describes graphs. Looking at the language definition I was compelled to…
Silas Davis
  • 712
  • 1
  • 9
  • 15
0
votes
1 answer

FParsec - how to escape a separator

I'm working on an EDI file parser, and I'm having considerable difficulty implementing an escape for the 'segment terminator'. For anyone fortunate enough to not work with EDI, the segment terminator (usually an apostrophe) is the deliter between…
ddek
  • 111
  • 1
  • 4
0
votes
0 answers

Left-recursive grammars in operator precedence parsing

I have a left recursive grammar. My AST looks something like: ... and Expr = BinaryExpr of BinaryExpr and BinaryExpr = Expr * BinaryOperator * Expr and BinaryOperator = Plus ... I was planning on using the operator precedence parser for this, for…
falkmar
  • 53
  • 3
0
votes
1 answer

failwith causes an error when used in a calculation expression - FParsec

I use a function: let identifier kind = (many1Satisfy2L isLetter (fun c -> isLetter c || isDigit c) "identifier" >>= fun s -> preturn s) >>= fun s -> identifierKind s kind The kind argument is of this type: type KindOfIdentifier = …
Foxy
  • 980
  • 8
  • 17
0
votes
1 answer

Parsing the arrow type with FParsec

I'm trying to parse the arrow type with FParsec. That is, this: Int -> Int -> Int -> Float -> Char For example. I tried with this code, but it only works for one type of arrow (Int -> Int) and no more. I also want to avoid parentheses, because I…
Foxy
  • 980
  • 8
  • 17
0
votes
0 answers

Get the last error message thrown for an instruction

I noticed that the error messages sent by FParsec were quite "ambiguous", except for the last message sent for an instruction. Here is an example: Code to parse: if (2 + 2 == 4) Here, normally, there should be an instruction block (so in…
Foxy
  • 980
  • 8
  • 17
1 2 3
12
13