Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6359933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:35:02+00:00 2026-05-24T23:35:02+00:00

I am trying to implement a method arguments parser with FParsec. I was wondering

  • 0

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 precedence, so there might be something for this too.


Parsing the opening and closing braces is pretty straight-forward. The headache lies in dealing with the following 3 cases that can happen:

Method arguments can consist of:

  • no arguments,
  • one argument,
  • several arguments (all comma separated). keep in mind the last argument cannot be preceded by a comma!

I already have some clues on how to implement this by myself in case there is not any built-in feature, namely with the <|> operator and stream copying, but I’d like to stay away from that kind of low level stuff if possible.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T23:35:03+00:00Added an answer on May 24, 2026 at 11:35 pm

    I believe you want to use sepBy.

    type AST =
    | Arguments of AST list
    | Argument of string * string
    
    let parseArguments =
        spaces 
        >>. pchar '(' 
        >>. spaces 
        >>. sepBy parseArgument (pchar ',') 
        .>> spaces 
        .>> pchar ')' 
        |>> Arguments
    

    Edited by devoured_elysium:

    The above code is correct although it doesn’t compile. I’ll post here my compiling version, so that if anyone just wants to try out the code without further ado, they can do it.

    type AST =
    | Arguments of AST list
    | Argument of string
    
    let parseArguments =
        spaces 
        >>. pchar '(' 
        >>. spaces 
        >>. sepBy (many1Satisfy isLetter |>> Argument) (pchar ',')
        .>> spaces 
        .>> pchar ')'
        |>> Arguments
    
    test parseArguments "(a,b,c)" //succeed
    test parseArguments "(a,b,c,)" //fail
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement method Find that searches the database. I forgot to mention
I'm trying to implement a class in C# with a method that intercepts the
I'm trying to implement a C# method that can log a message with a
I'm trying to implement a LINQ-to-SQL extension method that will simply get a random
I am trying to implement my own authentication method for AuthKit and am trying
I would like to implement the method User.calculate_hashed_password . I'm trying to use the
I'm trying to implement a function that generates dynamic queries for MNesia. For example,
I am trying to implement slice functionality for a class I am making that
I'm trying to implement an XSLT extension function with variable number of arguments. If
I am currently trying to implement a serial port reader class using Windows (already

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.