RFC: Indentation based grammar [message #556885] |
Thu, 02 September 2010 23:27  |
Eclipse User |
|
|
|
I just tried to tackle the "parse indentation" issue separate from my
markup language, starting with a grammar for simple hierarchical todo
lists like:
----
Buy milk
walk to the store
find milk
put milk in cart
pay for milk
walk to pay desk
hand over money
Drink milk
Enjoy reduced risk of heart disease
----
The code is here:
http://code.google.com/a/eclipselabs.org/p/todotext/
http://github.com/ralfebert/org.eclipselabs.todotext
This can be parsed by this grammar:
----
grammar org.eclipselabs.todotext.Todos
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
generate todos "http://www.eclipselabs.org/todotext/Todos"
TodoList: {TodoList}
(todos += Todo (NL todos += Todo)*)?;
Todo:
name=String (NL INDENT subtasks = TodoList DEDENT)?;
String returns ecore::EString:
CHAR+;
terminal NL: ('\r'|'\n')+ '\t'*;
terminal INDENT : '{';
terminal DEDENT : '}';
terminal CHAR: .;
----
All that's needed seems to be a custom TokenSource that yields the
INDENT and DEDENT tokens before and after NL.
AbstractSplittingTokenSource seems perfect for this, see:
http://github.com/ralfebert/org.eclipselabs.todotext/commit/ 8cf8bc
This makes the folding work for such a simplified grammar. Seems to be
too easy to be true :)
Is there something that I missed and that will not work or get
inconvenient about this approach?
(@Sebastian, you mentioned you had support for indentation-sensitive
grammars working already, I guess you meant AbstractSplittingTokenSource?)
Ralf
|
|
|
|
Stale marker problem [message #557109 is a reply to message #556885] |
Sat, 04 September 2010 10:17   |
Eclipse User |
|
|
|
I'm seeing stale markers for the todotext language, I guess something
trips over the fake indent/dedent tokens. I will change the grammar to
remove the rule which causes the markers anyway, so I don't particularly
care about this; I thought I'd report it anyway because it's easy to
reproduce. If I shall file a bugzilla for this, just tell me ;)
Steps to reproduce:
git clone http://github.com/ralfebert/org.eclipselabs.todotext.git
git checkout 78a70c7
Generate language, run, create a .todos document like this:
1
1a
2
(1\n\t1a\n2). Go with the cursor behind "1a", press enter. It will
complain about:
required (...)+ loop did not match anything at input ''
This marker is correct, the language does not allow empty todos. Now
type a character. The Problem will go away, but the red error marker in
the document stays, even after saving:
http://www.ralfebert.de/dump/xtext_todos_stale_marker.png
If the document is reopened, it goes away.
Reproducable on Eclipse SDK 3.6.1 M20100902-1717 + Xtext SDK
1.0.1.v201008311940.
Ralf
|
|
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05501 seconds