FreeTextLiteral without Stop Character

Aug 4, 2010 at 4:36 PM

Is it possible to use a FreeTextLiteral without a stop character? Or is there some other way of achieving what I want to do?

Here's a sample of my DSL...


Questionnaire: Q
  Question: Q1
    Text: What is your name?
  Question: Q2
    Text: What is your quest?

and part of my grammar...

var questionnaire = new NonTerminal("questionnaire");
var questions = new NonTerminal("questions");
var question = new NonTerminal("question");
var text = new NonTerminal("text");
var id = new IdentifierTerminal("id", " ", "0123456789");
var value = new FreeTextLiteral("value", FreeTextOptions.AllowEof, "\t");

id.Priority = Terminal.LowestPriority;
value.Priority = Terminal.LowestPriority;

questionnaire.Rule = "Questionnaire:" + id + text + questions;
questions.Rule = MakeStarRule(questions, (question | section));			
question.Rule = "Question:" + id + text + type + validation;

text.Rule = ("Text:" + value) | Empty;

 value can be multi-line and can include any character. I'd like it to be terminated by any keyword but the only way I can make it work is by using a tab as a stop character. I'd rather not have white-space be significant at all.

I'm hoping that I am missing something really obvious.

Thanks in advance,


Aug 5, 2010 at 1:04 PM

I don't think you can. The FreeTextLiteral would simply consume everything until EOF. You need a stop condition, and given your requirement, it has to be a pretty clever one.

How about using two newlines?

Or, if you don't mind indenting the text, maybe take a look at that. I have never played with it, but I know Irony has some features to handle this.

Good luck!


Aug 5, 2010 at 4:50 PM
I agree with Mich-PM, it's too much to ask from FreeTextLiteral - to recognize that certain specific text is in fact a beginning of the new terminal. I suggest to come up with more reasonable grammar rules Roman
Aug 5, 2010 at 5:21 PM
MichelangeloPM wrote:
How about using two newlines?

I tried two newlines but it hangs when the input document doesn't have two newlines. The tab is working for me at the moment, but I'd welcome suggestions for a better idea.

Here's what I am trying to achieve:

I want the DSL to be editable by totally non-technical users, so I am avoiding explicit delimiters where ever possible.

There are a number of fields where the value will almost always be a single line of plain text but the value can also use markdown syntax that will span multiple lines.

So it will usually be something like:

Text: What is your quest?

but it could be:

Text: If its not a *personal* question?

**Are you a virgin?**

The tab works in my demo but there is no way a real person will be able to deal with invisible white-space. The best I can come up with is to use delimiters around multi-line statements like this:

Text: [If its not a *personal* question?

**Are you a virgin?**]

But still allow single line values without delimiters which is the most common case by far.

This is a demo app to evangelize the idea of DSLs in my company, so it's too critical but I'll need to come up with a better solution eventually (if I succeed in persuading my colleagues that this is worth doing).

I'd welcome suggestions if you have any ideas.


Aug 5, 2010 at 5:27 PM
Edited Aug 5, 2010 at 5:29 PM
Then just create two terminals - one for one-liners, without any quoting chars, another for mulitline with surrounding brackets, and put both into the rule for "value", smth like Value.Rule = OneLineValue | QuotedValue One important thing - make priority of QuotedValue higher than priority of OneLineVAlue, so parser always checks for opening bracket first.
Aug 5, 2010 at 7:14 PM
rivantsov wrote:
 Value.Rule = OneLineValue | QuotedValue

That worked out great. Thanks again for your help.