Pregunta

So I have a function on javacc:

void parseDSL() throws SemanticException #void :
{}
{
    <ALL> "/*@mat" dslStatements() "*/" <ALL> <EOF>
}

My objective is to ignore everything until the "/*@mat" matches and after the parsing ignores everythings until EOF. I'm really struggling to find a regular expressions that works here. One example of a file that should pass is:

public class blabla {
    int i=1;/*@mat
    in float B[100];
    in float C[100];
    in int A[9];
    in int Z[9];
    out float D[];
    D=A*(B+C-Z)+A*Z;
    */boolean a;
}

Thank You.

¿Fue útil?

Solución

This is what lexical states are for. See the documentation and FAQ for more information. Roughly what you want is

<DEFAULT> SKIP: { < ~[] > }  // Skip everything up to "/*@mat"
<DEFAULT> TOKEN: { < STARTMAT: "/*@mat" > : GO } 
<GO> TOKEN: { <IN : "in" >
            | <OUT : "out" >
            | .... other rules go here ....
            | <ENDMAT : "*/" > : DEFAULT // On a "*/" go back to skipping. 
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top