Hi all, First of all thanks for the amazing work and aswers to all. Having said that, the problem: I need to parse a log, a model that represents the lo is the following:AAA BBB AAA CCC BBB Line I don't care which can contain anything that is not AAA BBB or CCC ' Is there a better solution? |
Hi,
I am not sure what you mean when you say an object that knows how to add to the result. Basically, you would need to build for each production the object and collect the meaningful ones in the outer scope. Here is something that would work for your example: a := 'AAA' asParser ==> [:token | #a]. b := 'BBB' asParser ==> [:token | #b]. c := 'CCC' asParser ==> [:token | #c]. meaningful := a / b / c. other := (meaningful / #newline asParser) negate star flatten. log := (meaningful / other) delimitedBy: #newline asParser. result := log end parse: 'AAA AAA BBB CCC AAA other text CCC BBB other text'. result select: #isSymbol I am CC-ing the moose mailing list because these questions tend to find better answers there. Cheers, Doru On May 27, 2013, at 11:07 PM, Juan Ignacio Vaccarezza <[hidden email]> wrote: > Hi all, > > First of all thanks for the amazing work and aswers to all. Having said that, the problem: > > I need to parse a log, a model that represents the lo is the following: > > ' > AAA > AAA > BBB > Line I don't care which can contain anything that is not AAA BBB or CCC > CCC > AAA > CCC > BBB > Line I don't care which can contain anything that is not AAA BBB or CCC > ' > > I manage to write the grammar which parses this, but then I would lilke to have all the log info digested on a result object which behaves something like this: > > resutlObject as size --> 3 > resultObject bs size --> 2 > restulIbject cs size -->2 > > The option that im using now is that individual parsers (meaning the parser for AAA,BBB,CCC,etc) actually retunrs an object that knows how to add themselves to the result and then, I iterate over the parser's array result asking to each object to add itself to the result. > > Is there a better solution? > > Thanks to all, > Juan. -- www.tudorgirba.com "It's not how it is, it is how we see it." |
Doru, thanks for the answer. I'm doing it in the way you suggest. What I ment by know how to add to the result is the following: (Modifing a bit the example you gave me) b := 'BBB' asParser flatten ==> [:token | ResultSelfAdder new objectToAdd: token; selector:#addB ]. c := 'CCC' asParser flatten ==> [:token | ResultSelfAdder new objectToAdd: token; selector:#addC ]. meaningful := a / b / c. other := (meaningful / #newline asParser) negate star flatten. log := (meaningful / other) delimitedBy: #newline asParser. result := log end parse: 'AAA AAA BBB CCC AAA other text CCC BBB other text'. niceObject := ParseResult new. result do: [:eachResult | eachResult addYourselfTo: niceObject] ResutlSelfAdder>>addYourselfTo: aParseResult aParseResult perform: self selector with: self objectToAdd. I hope is clear now, Im pretty new at asking on mailists, and sometimes I forget to add crucial information Thanks again for your time! Juan
On Tue, May 28, 2013 at 2:08 AM, Tudor Girba <[hidden email]> wrote: Hi, |
Hi, I would more do it the other way around (from large to small): niceObject := ParseResult new. result do: [:eachResult | niceObject add: eachResult ] Cheers, Doru On Tue, May 28, 2013 at 2:23 PM, Juan Ignacio Vaccarezza <[hidden email]> wrote:
"Every thing has its own flow"
|
In reply to this post by Juan Ignacio Vaccarezza
Juan Ignacio Vaccarezza wrote:
> Im pretty new at asking on mailists, and sometimes I > forget to add crucial information > Hi Juan, I like to refer people to "How To Ask Questions The Smart Way" [1]. However it is friendlier here than the tone of the article so I wouldn't worry too much about making any mistake. ...and welcome btw. cheers -ben [1] http://www.catb.org/esr/faqs/smart-questions.html |
Nice article indeed! thanks ben.On Tue, May 28, 2013 at 1:46 PM, <[hidden email]> wrote:
|
In reply to this post by Tudor Girba-2
Hi Doru,
I did it the other way to avoid the "if" inside the ParseResult>>add: . Regards,
Juan On Tue, May 28, 2013 at 11:55 AM, Tudor Girba <[hidden email]> wrote:
|
Free forum by Nabble | Edit this page |