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

How to ignore all but matches?

I have some source code files where I would like to extract all the comments (C-style) and search them for a specific construct that I can then use in my source generator to make some additional code... Example: ... var v = something();//comment I…
Cine
  • 4,255
  • 26
  • 46
0
votes
1 answer

Sprache how to handle multiple line continuation values

I am using Sprache to parse a legacy file. The file has the following structure very similar to a key and value dictionary: Entity { propertyA simple propertyB 10-1 propertyC "first" propertyD "I am a line that spawns to another line" …
0
votes
0 answers

Modeling chained expressions into AST

Preface I am trying to write an interpreter/compiler for the first time. Tokenization and parsing are already a thing, that I seem to have figured out. I still find myself struggling because there are some language constructs that are hard to model.…
0
votes
0 answers

How to extend a sprache parser to cope with leading and trailing free text

I have a sprache parser that successfully recognizes a variety of complex strings. I now have to find these strings if they are embedded in free text. Is this possible? For example, "FJ21 [7-20]" and "7.2x1.2 FULL" are examples of strings that my…
Lobert
  • 467
  • 1
  • 4
  • 10
0
votes
1 answer

How do I use Token() method in Sprache parser

I'm using 'Token()' method to discard leading and trailing whitespaces but it won't, this test fails with message Expected string to be "token", but it has unexpected whitespace at the end. I tried to call method Token() before method Text() but it…
Ed Pavlov
  • 2,353
  • 2
  • 19
  • 25
0
votes
1 answer

Parsing a text with "xxx = { .. }" in C# with Sprache

As you may already guess, I need some help. I'm currently working on a WPF with a friend, but we have a problem: We need to parse a certain type of text but we have just no idea how to do it. We found Sprache and it seems like a great parser, but we…
stuffi3000
  • 11
  • 1
  • 2
0
votes
2 answers

Aggregate List into Dictionary

I'm trying to create a Sprache parser where a part of the input should be parsed into a dictionary input=some/fixed/stuff;and=a;list=of;arbitrary=key;value=pairs The and=a;list=of;arbitrary=key;value=pairs part is supposed to end up in a…
0
votes
1 answer

how to translate linq query to method calls

I'm trying to make a parser using Sprache I'm using F#. All the examples I've ever seen for the library use the Linq query syntax. I tried to translate the linq to f# using the "query" computation expression, but I got lost there. Here is a sample…
phil
  • 1,416
  • 2
  • 13
  • 22
0
votes
1 answer

Sprache: parse signed integer

I wonder if there is a better way to parse signed integer using Sprache parser framework. There is well known parser definition for integers without sign Parse.Number.Select(int.Parse) But I want to parse integers with - prefix as well. What I have…
Tadas Šukys
  • 4,140
  • 4
  • 27
  • 32
1 2
3