2

I'm trying to model a YAML-like DSL in Xtext. In this DSL, I need some Multiline String as in YAML.

description: | Line 1 line 2 ... My first try was this:

terminal BEGIN: 'synthetic:BEGIN'; // increase indentation terminal END: 'synthetic:END'; // decrease indentation terminal MULTI_LINE_STRING: "|" BEGIN ANY_OTHER END;

and my second try was terminal MULTI_LINE_STRING: "|" BEGIN ((!('\n'))+ '\n')+ END; but both of them did not succeed. Is there any way to do this in Xtext?

UPDATE 1:

I've tried this alternative as well.

terminal MULTI_LINE_STRING: "|" BEGIN ->END

When I triggered the "Generate Xtext Artifacts" process, I got this error:

3492 [main] INFO nerator.ecore.EMFGeneratorFragment2 - Generating EMF model code 3523 [main] INFO clipse.emf.mwe.utils.GenModelHelper - Registered GenModel 'http://...' from 'platform:/resource/.../model/generated/....genmodel' error(201): ../.../src-gen/.../parser/antlr/lexer/Internal..Lexer.g:236:71: The following alternatives can never be matched: 1 error(3): cannot find tokens file ../.../src-gen/.../parser/antlr/internal/Internal...Lexer.tokens error(201): ../....idea/src-gen/.../idea/parser/antlr/internal/PsiInternal....g:4521:71: The following alternatives can never be matched: 1

2 Answers2

1

This slide deck shows how we implemented a whitespace block scoping in an Xtext DSL.

We used synthetic tokens called BEGIN corresponding to an indent, and END corresponding to an outdent.

(Note: the language was subsequently renamed to RAPID-ML, included as a feature of RepreZen API Studio.)

Ted Epstein
  • 2,639
  • 20
  • 19
0

I think your main problem is, that you have not defined when your multiline token is ending. Before you come to a solution you have to make clear in your mind how an algorithm should determine the end of the token. No tool can take this mental burdon from you.

Issue: There is no end marking character. Either you have to define such a character (unlike YAML) or define the end of the token in anather way. For example through some sort of semantic whitespace (I think YAML does it like that).

The first approach would make the thing very easy. Just read content until you find the closing character. The sescond approach would probably be manageable using a custom lexer. Basically you replace the generated lexer with your own implemented solution that is able to cound blanks or similar.

Here are some starting points about how this could be done (different approaches thinkable):

Arne Deutsch
  • 14,629
  • 5
  • 53
  • 72