|
|
|
Re: Regex to compare string [message #1369268 is a reply to message #1351338] |
Tue, 20 May 2014 13:59 |
|
I see. It's best to parse your string to an EMF model before feeding it into ATL. You can use xText, EMFText, or TCS for this.
If this is not feasible, you can still create native Java objects by switching to ATL/EMFTVM (https://wiki.eclipse.org/ATL/EMFTVM).
You can then write a recursive helper (while loops do not exist in ATL) to process your string:
helper context "#native"!"java::util::regex::Matcher" def : varNames() : Sequence(String) =
if self.find() then
Sequence{
if self.group(4).oclIsUndefined() then
'value' + self.regionStart().toString()
else
self.group(4)
endif
}->union(self.varNames())
else
Sequence{}
endif;
rule VarParent {
from s : MMIN!VarParent
to t : MMOUT!NewVarParent (
...
children <-
let regexType : "#native"!"java::util::regex::Pattern" = "#native"!"java::util::regex::Pattern".refInvokeStaticOperation('compile', Sequence{'pattern'}) in
let matcherType : "#native"!"java::util::regex::Matcher" = regexType.matcher('string') in
matcherType.varNames()->collect(n | thisModule.CreateVariable(n))
)
}
lazy rule CreateVariable {
from s : String
to t : MMOUT!Variable (
name <- s
)
Cheers,
Dennis
|
|
|
Powered by
FUDForum. Page generated in 0.04265 seconds