Parsing single line commands [message #1408886] |
Sat, 16 August 2014 07:09  |
Eclipse User |
|
|
|
I have an existing file format (not CSV), for which I want to create an editor. In this format every command is on its own line. The first character on each line is used to discriminate between commands. Is there a way to stop Xtext from parsing a line once a command has been found? Or are there other ways to deal with parsing to the end of a line?
|
|
|
|
|
|
|
Re: Parsing single line commands [message #1409983 is a reply to message #1408886] |
Tue, 19 August 2014 09:36   |
Eclipse User |
|
|
|
Here is the grammar:
###################################
grammar oneliner.oncsv.Onecsv
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
generate onecsv "http://www.oncsv.oneliner/Onecsv"
Csv: rows+=Row (NL+ rows+=Row)* NL*;
Row: rowline=ENTRY;
terminal ENTRY: (!('\r'|'\n'))*;
terminal NL: ('\r')?'\n';
#################################
and the generator looks like:
############################################
package oneliner.oncsv.generator
import oneliner.oncsv.onecsv.Csv
import oneliner.oncsv.onecsv.Row
import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.xtext.generator.IFileSystemAccess
import org.eclipse.xtext.generator.IGenerator
class OnecsvGenerator implements IGenerator {
override void doGenerate(Resource resource, IFileSystemAccess fsa) {
fsa.generateFile('Onecsv.0.CODE', makeTheCode(resource.contents.head as Csv))
}
def makeTheCode(Csv sm) '''
«FOR Row modul : sm.rows»
«modul.rowline»
«ENDFOR»
'''
}
########################################
The example Input
###################
ab test or so tt
testline
1;5 6 ,7 ,8,9,10
Aber, mal; Test 12;
####################
will be generated to (empty lines are suppressed):
#####################
ab test or so tt
testline
1;5 6 ,7 ,8,9,10
Aber, mal; Test 12;
#####################
[Updated on: Tue, 19 August 2014 09:39] by Moderator
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05339 seconds