{"id":13430274,"url":"https://github.com/sprache/Sprache","last_synced_at":"2025-03-16T05:30:39.127Z","repository":{"id":41142880,"uuid":"5097384","full_name":"sprache/Sprache","owner":"sprache","description":"A tiny, friendly, C# parser construction library","archived":false,"fork":false,"pushed_at":"2024-04-18T18:14:30.000Z","size":1780,"stargazers_count":2395,"open_issues_count":20,"forks_count":215,"subscribers_count":109,"default_branch":"develop","last_synced_at":"2025-03-15T11:00:40.870Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sprache.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-07-18T14:40:28.000Z","updated_at":"2025-03-13T10:53:10.000Z","dependencies_parsed_at":"2024-06-18T23:10:09.444Z","dependency_job_id":null,"html_url":"https://github.com/sprache/Sprache","commit_stats":{"total_commits":160,"total_committers":41,"mean_commits":3.902439024390244,"dds":0.75,"last_synced_commit":"9d1721bb0dea638e35b9bbb2334fea6f99bf778e"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sprache%2FSprache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sprache%2FSprache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sprache%2FSprache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sprache%2FSprache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sprache","download_url":"https://codeload.github.com/sprache/Sprache/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243830912,"owners_count":20354848,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T02:00:51.708Z","updated_at":"2025-03-16T05:30:39.106Z","avatar_url":"https://github.com/sprache.png","language":"C#","readme":"# Sprache [![Sprache tag on Stack Overflow](https://img.shields.io/badge/stackoverflow-sprache-orange.svg)](http://stackoverflow.com/questions/tagged/sprache) [![Join the chat at https://gitter.im/sprache/Sprache](https://badges.gitter.im/sprache/Sprache.svg)](https://gitter.im/sprache/Sprache?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge) [![NuGet](https://img.shields.io/nuget/v/Sprache.svg)](https://nuget.org/packages/Sprache) [![Build status](https://ci.appveyor.com/api/projects/status/xrn2d7b9crqj8l4a?svg=true)](https://ci.appveyor.com/project/Sprache/sprache)\n\nSprache is a simple, lightweight library for constructing parsers directly in C# code.\n\nIt doesn't compete with \"industrial strength\" language workbenches - it fits somewhere in between regular expressions and a full-featured toolset like [ANTLR](http://antlr.org).\n\n![Sprache](https://avatars1.githubusercontent.com/u/1999078?v=3\u0026s=200)\n\n### Usage\n\nUnlike most parser-building frameworks, you use Sprache directly from your program code, and don't need to set up any build-time code generation tasks. Sprache itself is a single tiny assembly.\n\nA simple parser might parse a sequence of characters:\n\n```csharp\n// Parse any number of capital 'A's in a row\nvar parseA = Parse.Char('A').AtLeastOnce();\n```\n\nSprache provides a number of built-in functions that can make bigger parsers from smaller ones, often callable via Linq query comprehensions:\n\n```csharp\nParser\u003cstring\u003e identifier =\n    from leading in Parse.WhiteSpace.Many()\n    from first in Parse.Letter.Once().Text()\n    from rest in Parse.LetterOrDigit.Many().Text()\n    from trailing in Parse.WhiteSpace.Many()\n    select first + rest;\n\nvar id = identifier.Parse(\" abc123  \");\n\nAssert.AreEqual(\"abc123\", id);\n```\n\n### Examples and Tutorials\n\nThe best place to start is [this introductory article](http://nblumhardt.com/2010/01/building-an-external-dsl-in-c/).\n\n**Examples** included with the source demonstrate:\n\n* [Parsing XML directly to a Document object](https://github.com/sprache/Sprache/blob/master/samples/XmlExample/Program.cs)\n* [Parsing numeric expressions to `System.Linq.Expression` objects](https://github.com/sprache/Sprache/blob/master/samples/LinqyCalculator/ExpressionParser.cs)\n* [Parsing comma-separated values (CSV) into lists of strings](https://github.com/sprache/Sprache/blob/master/test/Sprache.Tests/Scenarios/CsvTests.cs)\n\n**Tutorials** explaining Sprache:\n * Overview of Sprache methods, [long guide by Justing Pealing](https://justinpealing.me.uk/post/2020-03-11-sprache1-chars/)\n * A great [CodeProject article by Alexey Yakovlev ](http://www.codeproject.com/Articles/795056/Sprache-Calc-building-yet-another-expression-evalu) (and [in Russian](http://habrahabr.ru/post/228037/))\n * Mike Hadlow's example of [parsing connection strings](http://mikehadlow.blogspot.com.au/2012/09/parsing-connection-string-with-sprache.html)\n * Alexey Golub's article on [monadic parser combinators](https://tyrrrz.me/blog/monadic-parser-combinators) that shows how to build a JSON parser using Sprache\n\n**Real-world** parsers built with Sprache:\n\n * The [template parser](https://github.com/OctopusDeploy/Octostache/blob/master/source/Octostache/Templates/TemplateParser.cs) in [Octostache](https://github.com/OctopusDeploy/Octostache), the variable substitution language of [Octopus Deploy](https://octopus.com)\n * The [XAML binding expression parser](https://github.com/OmniGUI/OmniXAML/blob/master/OmniXaml/InlineParsers/Extensions/MarkupExtensionParser.cs) in [OmniXaml](https://github.com/OmniGUI/OmniXAML), the cross-platform XAML implementation\n * Parts of the filter expression parser in [Seq](https://datalust.co/seq), a structured log server for .NET\n * The [connection string parser](https://github.com/EasyNetQ/EasyNetQ/blob/master/Source/EasyNetQ/ConnectionString/ConnectionStringGrammar.cs) in [EasyNetQ](http://easynetq.com/), a .NET API for RabbitMQ\n * [ApexSharp parser](https://github.com/apexsharp/apexparser/blob/master/ApexSharp.ApexParser/Parser/ApexGrammar.cs), a two-way [Apex to C# transpiler](https://github.com/apexsharp/apexparser) (Salesforce programming language)\n * Sprache appears in the [credits for JetBrains ReSharper](https://confluence.jetbrains.com/display/ReSharper/Third-Party+Software+Shipped+With+ReSharper#Third-PartySoftwareShippedWithReSharper-Sprache)\n\n### Background\n\nParser combinators are covered extensively on the web. The original paper describing the monadic implementation by [Graham Hutton and Eric Meijer](http://www.cs.nott.ac.uk/~gmh/monparsing.pdf) is very readable. Sprache was originally written by [Nicholas Blumhardt](http://nblumhardt.com) and grew out of some exercises in [Hutton's Haskell book](http://www.amazon.com/Programming-Haskell-Graham-Hutton/dp/0521692695).\n\nThe implementation of Sprache draws on ideas from:\n\n* [Luke Hoban's Blog](http://blogs.msdn.com/b/lukeh/archive/2007/08/19/monadic-parser-combinators-using-c-3-0.aspx)\n* [Brian McNamara's Blog](http://lorgonblog.wordpress.com/2007/12/02/c-3-0-lambda-and-the-first-post-of-a-series-about-monadic-parser-combinators/)\n","funding_links":[],"categories":["Frameworks, Libraries and Tools","C#","others","C# #","C\\#","Parser Library","框架, 库和工具","解析器库","Compilers, Transpilers and Languages"],"sub_categories":["Compilers, Transpilers and Languages","编译器"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsprache%2FSprache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsprache%2FSprache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsprache%2FSprache/lists"}