Questions tagged [sprache]

Sprache is a lightweight library for constructing parsers directly in C# code with capabilities generally in the range between regular expressions and tools like ANTLR.

Sprache is a lightweight library for constructing parsers directly in C# code.
It doesn't compete with "industrial strength" language workbenches — it fits somewhere in between regular expressions and a full-featured toolset like ANTLR.

There's a tutorial.

(Information drawn with permission from the Sprache website.)

39 questions
2
votes
1 answer

Sprache DelimitBy new line

I have these parsers as part of my grammar: public static readonly Parser SpaceOrTab = Parse.Char(' ').Or(Parse.Char('\t')).Many().Text().Named("SpaceOrTab"); public static readonly Parser NewLine = Parse.LineEnd; public…
Roger Johansson
  • 22,764
  • 18
  • 97
  • 193
1
vote
1 answer

Recursive Expression Tree Parsing With Sprache

so i have a parser that uses use sprache to create an expression from a string. something like PhysicalAddress.State == "GA" has PhysicalAddress.State parsed as the left, == as the operator, and "GA" as the right expression. the parts can then be…
Paul DeVito
  • 1,542
  • 3
  • 15
  • 38
1
vote
1 answer

sprache parsing of text using a delimiter

I am trying to use sprache to parse the string accept-version:V1.2 so that I extract there 2 strings out of it: accept-version and V1.2 But I get a parsing failure error: Parsing failure: Unexpected end of input reached; expected : (Line 1, Column…
umbersar
  • 1,821
  • 3
  • 24
  • 34
1
vote
1 answer

How the Sprache LINQ query example works?

I came across the following piece of code in the Sprache repository : Parser identifier = from leading in Parse.WhiteSpace.Many() from first in Parse.Letter.Once().Text() from rest in Parse.LetterOrDigit.Many().Text() from…
Eugene F.
  • 25
  • 4
1
vote
1 answer

How can I parse until a separator is found or the end of the input is reached with Sprache?

I'm trying to parse a string that contains text interspersed with stars: var input = "*This is the first part*This is the second part"; I want to extract any text between stars and the text after the last star. The string doesn't end in a star, or…
Paul
  • 1,897
  • 1
  • 14
  • 28
1
vote
1 answer

Parsing a phrase with Sprache(Words seperated by spaces)

I'm attempting to write a parser in Sprache that will parse a phrase The basic rule is that it should include words seperated by a single space, with both the first and last character of the string being a space. I would expect to call something…
Heinrich Walkenshaw
  • 327
  • 1
  • 4
  • 11
1
vote
2 answers

Sprache -- Cannot recognise this sequence

I want to match strings where the first character is a letter, then it is followed by multiple characters which are either digits or letters, then finally ends with a letter. For example a11a11a is correct but a11aa11 is incorrect because it ends…
Tahir Hassan
  • 5,715
  • 6
  • 45
  • 65
1
vote
2 answers

Parsing a list of values with option to empty list

I'm trying to parse an array of items, using Sprache library for C# I have a working code that goes like this. public static Parser Array = from open in OpenBrackets.Named("open bracket") from items in…
xDGameStudios
  • 321
  • 1
  • 13
1
vote
3 answers

Discard rows of a LINQ "from" statement

I'm using the Sprache library, which allows parsers to be built using LINQ. However, sometimes I need to parse something and then discard the result. For example: from key in Identifier from __ws1 in OptionalWhitespace from __setter in…
Aaron Christiansen
  • 11,584
  • 5
  • 52
  • 78
1
vote
0 answers

Sprache as a round-trip tool

Can Sprache be used as a round-trip tool? I understand that with it I can build a parser that can extract information from a given text. But I can reuse the same (simple*) pattern I came up for parsing also to generate text from Information? Let me…
David
  • 2,426
  • 3
  • 24
  • 36
1
vote
1 answer

Sprache - combination of parsers

Using Sprache I have parsers, A,B,C,D which matches with different input parts, and selects (returns) different class instances. In my input there are a lot of parts in a random order, eq. "abaabccbdbabddba". I need to select all 'a'-s and 'b'-s and…
Zoltan Hernyak
  • 989
  • 1
  • 14
  • 35
1
vote
0 answers

How to build a (XAML) pull parser with Sprache?

I’ve created a pull parser as part of my OmniXaml project. It reads an XML file and transforms it into an enumerable of XAML Nodes. But I'm not happy with the result, so I decided to try to build another in a more elegant way. This is why I tried…
SuperJMN
  • 13,110
  • 16
  • 86
  • 185
1
vote
4 answers

Regex for ignoring consecutive quotation marks in string

I have built a parser in Sprache and C# for files using a format I don't control. Using it I can correctly convert: a = "my string"; into my string The parser (for the quoted text only) currently looks like this: public static readonly…
will-hart
  • 3,742
  • 2
  • 38
  • 48
1
vote
1 answer

Sprache: How to exclude letters from numeric matches?

Using the monadic parser Sprache, looking to match numeric characters (0..9), excluding non-numeric characters, but leading or trailing whitespace is ok. I thought this should work: public static readonly Parser Number =…
si618
  • 16,580
  • 12
  • 67
  • 84
0
votes
2 answers

parsing lines of text ending with '\n' using sprache

I have a sample text line, "FunTest\n", that I am trying to parse with sprache. I have written some sample code, see below, but it fails with an exception: Parsing failure: Unexpected end of input reached; expected (Line 2, Column 1); recently…
umbersar
  • 1,821
  • 3
  • 24
  • 34