This project has moved and is read-only. For the latest updates, please go here.

Simple FormatString language

Nov 11, 2014 at 9:59 AM
I'm trying to define a simplistic language using Irony. Some language usecases are
Dear {Name},
It is free text with therein references to fields enclosed in curly braces. a double curly brace escapes a field declaration. I came up with the following spec:
var orText = new FreeTextLiteral("Text", FreeTextOptions.AllowEof | FreeTextOptions.AllowEmpty);
var orFieldName = new FreeTextLiteral("FieldName");

var orField = new NonTerminal("Field");
var orValue = new NonTerminal("Value");

orField.Rule = "{" + orFieldName + "}";
orValue.Rule = orText | orField;

Root = orValue;
However, the Irony GrammarExplorer only parses a Value which has a Text element. A field is not recognized. What am I missing here?
Nov 12, 2014 at 7:07 PM
FreeTextLiteral is a wrong terminal for a job, and you're not configuring it properly - you should specify terminator symbol. Anyway, don't use it, it's not for situations like this.
Nov 13, 2014 at 3:03 PM
Edited Nov 13, 2014 at 3:19 PM
Thanks for your reply!

I'm kinda lost in how to do implement a simple FormatString language. My approach is to first let "free text" parse, but I haven't succeeded on this part. Woudl the terminator symbol be an opening bracket?

I tried

var text = new StringLiteral("text");
var TextTerm = new NonTerminal("textTerminal");
textTerm.Rule = text;
Root = textTerm;

However, the playground errs on the first fed character of a string.
Nov 20, 2014 at 6:49 AM
are you feeding quoted string as an input? if yes, then look at stringLiteral constructor parameters, make sure you specify proper quoting symbols (default should be double quote). Try stepping through StringLiteral.TryMatch code, see what's wrong, should be working I think
Nov 20, 2014 at 6:51 AM
is this FormatString language just an initial case to try, or for real? Simply 'language' like this better processed by specialized 'parser', not Irony or alike LALR parser for languages with regular grammars.