Xtext is a framework for development of textual domain specific languages (DSLs). You need to describe the DSL using Xtext's simple grammar and Xtext generates a parser, an editor and other goodies. You are on the way to create your own IDE for the DSL.
Xtext, out of the box, does not support using white spaces for creating block structure. With a small hack, you can make Xtext understand block structure defined using white space.
The basic idea is to replace Xtext's lexer with a custom lexer that adds the INDENT and DEDENT tokens into the parser.
My original answer in to a post on Xtext news group gives the generic procedure. However some points need to be modified.
Overriding bindLexer() does not really work. Xtext creates a concrete Lexer object in the parser. So for providing a CharStream, we need to bindIAntlrParser() and the in the parser class create the lexer that creates the CharStream.
You can access a sample project that implements this from google code. Use svn to checkout org.xtext.example.mydsl and org.xtext.example.mydsl.ui projects from http://eclipse-snippets.googlecode.com/svn/trunk/xtext-indenting.
1 comment:
Hey! Could you send me an e-mail to: kimi_anwen [at] yahoo [dot] com ? I have to do a similar thing in xtext and I would need your help. Thanks.
Post a Comment