Snippets in category Parsing

  • Functional style Regex engine

    Functional style Regex engine

    19 people like this
    Posted: 3 years ago by Nick Palladinos

  • Regex Match Index

    A function for interpreting the zero-based index property of a successful regular expression match in terms of line and column numbers.

    21 people like this
    Posted: 3 years ago by Taha Hachana

  • Parsing string expressions, the lazy way

    Sometimes you'd be surprised at what functionality you can find inside the .Net framework. Apparently the DataTable object can compute string expressions. Nice for testing your own parser implementation, and/or for lazy coders like me. Note that the DataTable is created only once and reused with each function call.

    32 people like this
    Posted: 3 years ago by Arjen Kopinga

  • URL Canonicalization

    This function produces safe URLs for Web requests or URI construction. It forces the pattern: http:// + www. OR subdomain. + domain + absolute path. When used in an application that takes URLs as input, the user would be able to type "example.com" instead of "http://example.com" or "http://www.example.com". It also supports domains like google.co.uk or google.com.au.

    8 people like this
    Posted: 3 years ago by Taha Hachana

  • Hex encode / decode

    Performs conversions to and from hexadecimal values.

    26 people like this
    Posted: 3 years ago by Daniel Robinson

  • Quote SQL Server identifiers

    Quotes SQL Server identifiers. Handles embedded quotes.

    2 people like this
    Posted: 3 years ago by Daniel Robinson

  • Lazily split string

    Splits strings lazily, instead of splitting entire string into an array like System.String.Split. Especially useful for very large strings.

    7 people like this
    Posted: 3 years ago by Daniel Robinson

  • Regular expression active pattern

    Active pattern returning list of captured groups.

    11 people like this
    Posted: 3 years ago by Daniel Robinson

  • Uri Parser

    A Uri parser using the Cashel library [1]. This implementation is using ArraySegment<byte> as the underlying state, as I'm using it within a server, but it would be trivial to switch it to using a list. Also, note that I am not parsing the Uri into any specific structure, though that, too, would be trivial. For my current purposes, I just needed to validate the Uri. [1] https://github.com/panesofglass/cashel

    25 people like this
    Posted: 3 years ago by Ryan Riley

  • Int32.tryParse

    Converts the string representation of a number in-place to an Int32. A return value of None indicates the conversion failed.

    21 people like this
    Posted: 3 years ago by Phillip Trelford

  • Functional wrappers for TryParse APIs

    Exemplary convenience wrappers for some of the System.<Typename>.TryParse APIs, using the combined power of F#' return value deconstruction mechanism via pattern matching, active patterns and option types instead of "out/ref" parameters

    19 people like this
    Posted: 3 years ago by Novox

  • Top-Down-Operator-Precedence Parser

    F# implementation of a generic Top-Down-Operator-Precedence Parser as described in this paper http://portal.acm.org/citation.cfm?id=512931 Example starts at line ~300

    80 people like this
    Posted: 3 years ago by fholm

  • Perl Style "Regex Matches?" operator

    Perl Style "Regex Matches?" operator

    46 people like this
    Posted: 3 years ago by fholm

  • Lexer

    Hand-written efficient JavaScript lexer from the IronJS project https://github.com/fholm/IronJS

    24 people like this
    Posted: 3 years ago by fholm

  • Web Crawler

    This snippet features an F# Web crawler that i'm already using in 2 applications (slightly modified). It's based on a scalable network of communicating agents that follow URLs extracted from HTML pages until reaching the specified limit.

    21 people like this
    Posted: 3 years ago by Taha Hachana

  • Spreadsheet

    Spreadsheet script runnable inside http://tryfsharp.org includes a custom DataGrid and a parser for simple formulas e.g.: =1+1 =SUM(A1,A2) Add your own functions to the evaluate function. For a more comprehensive implementation check out http://cellz.codeplex.com

    5 people like this
    Posted: 3 years ago by Phillip Trelford

  • sscanf - parsing with format strings

    A more complete version of sscanf, as proposed on stackoverflow by kvb: http://stackoverflow.com/questions/2415705/read-from-console-in-f Fixed bug in previous version to work with visual studio '13

    11 people like this
    Posted: 3 years ago by Wolfgang Meyer

  • Type based Regex Active Patterns

    Regex match via Active Patterns with Type based value extraction.

    3 people like this
    Posted: 3 years ago by Nick Palladinos

  • Active pattern to define default values

    This active pattern allows you to specify default values for option arguments in the signature of your function, so you can remove unnecessary calls to defaultArg. It also save you having to define a new name for the defaulted value.

    9 people like this
    Posted: 3 years ago by Kurt Schelfthout

  • Functions not so first class in active patterns

    It seems that you can't pass anonymous functions as parameters to active patterns.

    3 people like this
    Posted: 3 years ago by Kurt Schelfthout

  • Yet another command-line parser

    The snippet shows a parser for command-line arguments supporting value lists for single commands. Calling with the following arguments: "Arg 1" "Arg 2" -test "Case 1" "Case 2" -show -skip "tag" produces the following map: map [("", seq ["Arg 1"; "Arg 2"]); ("show", seq []); ("skip", seq ["tag"]);("test", seq ["Case 1"; "Case 2"])] which can be used to find what data have been sent along with different commands. Calling with the following: "Arg 1" "Arg 2" /test="Case 1" "Case 2" --show /skip:tag produces the same result.

    3 people like this
    Posted: 3 years ago by Gennady Loskutov

  • Loading .fs files

    This script facilitates to load all the .fs files in the specified F# project in correct compilation order.

    4 people like this
    Posted: 2 years ago by nagat01

  • Factoring out FSharpChart

    Using FSharpChart control. Just call Charting.Plot() to chart series or collections of series. No need to create forms, etc.

    2 people like this
    Posted: 2 years ago by Boris Kogan

  • JSON parsing with monads

    JSON parsing with monads. See also "Expression parsing with monads" (http://fssnip.net/bi). Author URL: http://www.zbray.com

    7 people like this
    Posted: 2 years ago by Zach Bray

  • Recursive descent parser using active patterns

    Parsing without external dependencies. Uses recursive active patterns and regular expressions.

    4 people like this
    Posted: 2 years ago by

  • Speech Stackoverflow article automatically

    This snippet automatically speeches text of question,answers and comments in a Stackoverflow article. It requires HtmlAgilityPack(available from Nuget package manager).(Attention: You need reset F# interactive to stop the speech)

    5 people like this
    Posted: 2 years ago by nagat01

  • Translating quotations to LINQ

    A sample that translates simple F# quotations (method calls, property getters) to stnadard C# LINQ expression trees.

    7 people like this
    Posted: 2 years ago by Tomas Petricek

  • Eliminating type annotations with single case Active Patterns

    When passing objects as arguments to F# functions, it is almost certain that a type annotation will be required. This may generate long and noisy code at times, but thankfully we can use active patterns to mitigate this annoyance.

    9 people like this
    Posted: 2 years ago by Eirik Tsarpalis

  • Count noise-lines in C# code

    This is the code I used to generate this pie chart: http://pic.twitter.com/PgPEFByg56 Enough said?

    8 people like this
    Posted: 1 years ago by Kit Eason

  • An active pattern combinator for list inputs

    A few active pattern combinators useful when pattern matching on lists is necessary.

    0 people like this
    Posted: 1 years ago by Eirik Tsarpalis

  • Parse locale files

    This uses fparsec to parse locale files of hte form Id = text {arg:type} = newline = newlne For use with localization.

    1 people like this
    Posted: 1 years ago by devshorts

  • Simple AST parser

    Parsers a minimal expression tree allowing for functions of the form "func(arg1,arg2,...)->{body}"

    2 people like this
    Posted: 1 years ago by devshorts

  • Extract script blocks from html page

    This module extracts all the <script src="blah.js"></script> blocks out of an html page's header. This can be useful if you are writing tools to merge all the js for future minifaction, or for otherwise manipulating the files.

    4 people like this
    Posted: 1 years ago by devshorts

  • Extract script blocks from html page (FP)

    A bit more functional version of this: http://fssnip.net/iR

    2 people like this
    Posted: 1 years ago by @kot_2010

  • Log file parsing

    File parsing, based on multiple lines, using recursive pattern matching with many :: (cons) operator

    2 people like this
    Posted: 1 years ago by Tuomas Hietanen

  • Toml parser

    Parser for Tom's Obvious, Minimal Language (https://github.com/mojombo/toml).

    1 people like this
    Posted: 1 years ago by nagat01

  • Toml parser (untyped)

    Untyped version of toml parser. The lines of code was reduced 173 to 45. It's based on some implementations in other languages (https://github.com/mojombo/toml#implementations). I was surprised that even a parser written in Objctive-c was simpler than mine (http://fssnip.net/jd). Then I read some others code and found that removing types which describes toml values simplifies the implementation. The code may seem little crazy, but I'm fine :)

    0 people like this
    Posted: 1 years ago by nagat01

  • A minimalist XML Parser

    A minimalist XML Parser

    8 people like this
    Posted: 1 years ago by Fabio Galuppo

  • Log file parser for log4Net files

    Log file parser for log4Net files

    2 people like this
    Posted: 1 years ago by Tuomas Hietanen

  • KataBankOCR

    See: http://codingdojo.org/cgi-bin/wiki.pl?KataBankOCR Prog. F# 2013 - London

    2 people like this
    Posted: 1 years ago by Zach Bray

  • Small Basic Parser

    Small Basic abstract syntax tree, parser and interpreter. Supports Small Basic's keywords and arithmetic, logical and comparison operators.

    5 people like this
    Posted: 10 months ago by Phillip Trelford

  • Simple C# Parser

    Simple prototype C# AST and parser using the FParsec parser combinator library. Parses a subset of C# 1.1 constructs.

    11 people like this
    Posted: 10 months ago by Phillip Trelford

  • Array tail match

    Match the first elements of an array an returns tail.

    2 people like this
    Posted: 9 months ago by thinkbeforecoding

  • Using the Regex type provider

    There are some nuances to using the regular expression type provider that are easy to miss. This snippet addresses them.

    1 people like this
    Posted: 3 months ago by musicologyman

  • A Simple Parser

    This is a basic parser that I wrote which takes heavily from the examples in Dom Syme's Expert F# book and http://fsharpforfunandprofit.com/posts/pattern-matching-command-line/

    3 people like this
    Posted: 1 months ago by Joe C