|
|
|
Re: Parsing single line commands [message #1409919 is a reply to message #1409879] |
Tue, 19 August 2014 09:54 |
Uli Merkel Messages: 250 Registered: June 2013 |
Senior Member |
|
|
Earnest Banbury wrote on Tue, 19 August 2014 03:57I have tried something like that, but my grammar is very ambiguous, unless it is parsed one line at a time. Xtext insists on parsing from the middle of lines and finds additional matches, that I don't want. I have looked through the forum and the internet for several days, but I couldn't find a good answer.
Parsing from the middle of the line ??
I don't think so if your grammar is something like:
Model: records+= Record;
Record : recordtype=ID (restOfRecord=TextUpToTheEOL)?;
TextUpToTheEOL: !('\n'|'\r')* ('\r'? '\n')?;
It's just a sketch, I will have a closer look at it when I have some time,
Uli
[Updated on: Tue, 19 August 2014 09:58] Report message to a moderator
|
|
|
|
Re: Parsing single line commands [message #1409983 is a reply to message #1408886] |
Tue, 19 August 2014 13:36 |
Uli Merkel Messages: 250 Registered: June 2013 |
Senior Member |
|
|
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 13:39] Report message to a moderator
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.07066 seconds