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

FParsec parse unordered clauses

I want to parse some grammar like the following OUTPUT data GROUPBY key TO location USING object the order of the GROUPBY TO USING clauses is allowed to vary, but each clause can occur at most once. Is there a convenient or built-in way to parse…
KFL
  • 17,162
  • 17
  • 65
  • 89
5
votes
1 answer

Parsing "x y z" with the precedence of multiply

I'm trying to write a parser for the Mathematica language in F# using FParsec. I have written one for a MiniML that supports the syntax f x y = (f(x))(y) with high precedence for function application. Now I need to use the same syntax to mean f*x*y…
J D
  • 48,105
  • 13
  • 171
  • 274
5
votes
1 answer

F#, FParsec, and Updating UserState

Okay, since my last question elicited no responses, I'm forging ahead in a different direction. Lol! I can't find any examples beyond the official documentation on managing user state, or accessing the results of a prior parser. N.b. This code does…
Jeff Maner
  • 1,179
  • 9
  • 23
5
votes
1 answer

FParsec failing on many

I have this test program: open FParsec let test p str = match run p str with | Success(result, _, _) -> printfn "Success: %A" result | Failure(errorMsg, _, _) -> printfn "Failure: %s" errorMsg let str s = pstring s let sepPart =…
JonnyBoats
  • 5,177
  • 1
  • 36
  • 60
5
votes
2 answers

Parser identifiers and free format text. Can this be done with FParsec?

As a follow-on to: How do I test for exactly 2 characters with fparsec? I need to parse a string that consists of pairs of identifiers followed by freeform text. I can easily construct a parser that finds the identifiers which are of the form of…
JonnyBoats
  • 5,177
  • 1
  • 36
  • 60
5
votes
3 answers

Parsing date and time with FParsec

Within a simple query language I'd like to recognize date and time literals, preferably without using delimiters. For example, CreationDate = 2013-05-13 5:30 PM I could use a combinator to detect the basic syntax (e.g., yyyy-MM-dd hh:mm tt), but…
Daniel
  • 47,404
  • 11
  • 101
  • 179
5
votes
3 answers

Advice on FParsec for handling whitespace

I have the following subexpression to parse 'quotes' which have the following format "5.75 @ 5.95" I therefore have this parsec expression to parse it let pquote x = (sepBy (pfloat) ((spaces .>> (pchar '/' <|> pchar '@' )>>. spaces))) x It works…
nicolas
  • 9,549
  • 3
  • 39
  • 83
4
votes
0 answers

How to handle left recursion in FParsec

My languages uses s-expressions with one additional feature - a dot operator for accessing elements from an array or struct. Currently, my parser works on this code using the access operator - ; Parition a sequence into a pair of sequences. ; NOTE:…
Bryan Edds
  • 1,696
  • 12
  • 28
4
votes
1 answer

Parsing an optionally-multi-line expression with FParsec

I'm writing an FParsec parser for strings in this form: do[ n times]([ action] | \n([action]\n)*endDo) in other words this is a "do" statement with an optional time quantifier, and either a single "action" statement or a list of "action"s (each on…
Francesco De Vittori
  • 9,100
  • 6
  • 33
  • 43
4
votes
1 answer

Parsing method arguments with FParsec

I am trying to implement a method arguments parser with FParsec. I was wondering if there is some already implemented feature in FParsec itself that'd aid me on this purpose? I ask this as FParsec provides tooling when dealing with operator…
devoured elysium
  • 101,373
  • 131
  • 340
  • 557
4
votes
3 answers

What to choose fsyacc/fslex or FParsec?

I need to parse simple DSL language like the following: import "library.txt" def main(int param1, bool param2) { var a = f4(param1); // or var d = f1(f2(f3(f4(param1)))); var b = f3(a); var c = f2(b); var d =…
Evgeny Gavrin
  • 7,627
  • 1
  • 22
  • 27
4
votes
1 answer

parsing if / else / if statements

I'm trying to replicate the structure of a simple if statement: if (paren) { block } [else ({ block } | rec if (paren)) ] for if (paren) block, I create a IfBlock AST node. Otherwise, it recursively fills a IfElseBlock node. I've tried quite a few…
hammett
  • 705
  • 4
  • 13
4
votes
1 answer

Why doesn't manyCharsTill combinator work if the "till" parser starts with spaces?

I try to parse xml-like tags (but not a correct xml document..): the goal is to get back just "Flange width" without the beginning or trailing whitespaces, but with the internal ones. open FParsec let testParser = pstring "" .>>. spaces …
Balinth
  • 548
  • 4
  • 10
4
votes
1 answer

FParsec: Keeping line and column numbers

What is the best way to extract the line and column numbers from a given parser so they can be added to an AST, for example? Thanks!
falkmar
  • 53
  • 3
4
votes
1 answer

Parsing custom infix operators + implementation with FParsec

I'm a little stuck on the way "real parsers", such as F# or Haskell, do to parse custom operators. For a "normal" language, we would simply define an AST node at which there would be predefined operator possibilities, for example: +, -, *, ==, >=,…
Foxy
  • 980
  • 8
  • 17
1 2
3
12 13