Have a file keywords.tx with
Commands:
keywords = 'this' & 'way'
;
StartWords:
keywords = 'bag'
;
Then a file mygram.tx with
import keywords
MyModel:
keyword*=StartWords[' ']
name+=Word[' ']
;
Word:
text=STRING
;
'''
My data file has one line with "bag hello soda this way". Would like to see result have attributes of keyword='bag' name='hello soda' and command='this way'.
Not sure how to get grammar to handle: keywords words keywords making sure that 2nd keywords are not included in the words. Another way to express is startwords words commands
If I understood your goal you can do something like this:
There are several things to note:
[' ']
as a separator rule in your repetitions as by default whitespaces are skipped,|
,!
to check if something is ahead and proceed only if it isn't. In the ruleWord
this is used to assure that commands are not consumed by theWord
repetition in theLine
rule.this way
) you can either use regex matches or e.g. specify match like:which will match a single space as a part of
this
and than arbitrary number of whitespaces beforeway
which will be thrown away.There is a comprehensive documentation with examples on the textX site so I suggest to take a look and go through some of the provided examples.