DirtyFriends

Top  Previous  Next

Example projects > Plain text parsers > DirtyFriends

 

The project DirtyFriends.ttp permits special friends to express dirty fantasies, if they sign the mail by name.

In the result this project is quite similar to the SpamAndNotSpam project. Instead of the NonSpam production there is a Friends production. The main rule is built in such manner, that the parser immediately skips to the end as soon as the result is certain. It is the disadvantage, though, that the rule looks confused.

 

{{

int iResult = 0;

}}

(

  SKIP?

  (

      Friends[iResult] SKIP?

    | Spam  

      ( 

        SKIP

        (   

            Friends[iResult] SKIP?

          | {{ iResult = -1; }}

        )  

      )

  )?    

)

{{

out << iResult;

}}  

 

The Friends production contains a list of the friends:

 

 

(

    "Peter"

  | "Paul"

  | "Mary"   

)

{{

xiResult = 1;

}}  

 

It is new that the Friends production is called with iResult as a parameter:

 

Friends[iResult]

.

The parameter must be declared in the TextTransformer in the Friends production:

 

 

TTParameter_ge

 

With the parameter the value is "fetched" from the Friends production: "xiResult = 1;"

 

Notice the extensive use of '?' in the start rule. That's necessary to make sure that every text can be parsed. Parser errors cannot appear then, even if e.g. the whole mail only consists of a spam word.