%filenames scanner
%class-name = "Scanner"

//%debug
//%print-tokens

%x comment 

                        // modnames A, optionally followed by .B names
IDENT                   [[:alpha:]_][[:alnum:]_]*
NAME                    {IDENT}(\.{IDENT})*

SP                      [ \t]+
OPTSP                   [ \t]*

%%

{SP}                        // ignore spaces
"//".*                      // ignore EOLN comment

"/*"                        begin(StartCondition_::comment);

<comment>{
    .|\n                    // ignore chrs inside comment

    "*/"                    begin(StartCondition_::INITIAL);
}

    // 1: define a module                           export module Name;
    //
^{OPTSP}export{SP}module{SP}{NAME};     return lastWord(MODDEF);

    // 2: make a module available                   [export] import Name;
    //
^{OPTSP}(export{SP})?import{SP}{NAME};  return lastWord(MODDECL);

    // 3: a module(-partition) component            module Name;     
    //
^{OPTSP}module{SP}{NAME};               return lastWord(MODSRC);

    // 4: define a partition module                 export module Name:Part;
    //
^{OPTSP}export{SP}module{SP}{NAME}:{NAME};  return lastWord(PARTDEF);

    // 5: declare a module partition                [export] import :Part;
    //    export needed in a module definition 
    //    accepts A:B although its incorrect:
    //    handled by declarepartition
    //    (MODDEF)
    //
^{OPTSP}(export{SP})?import{SP}{NAME}?:{NAME};  return lastWord(PARTDECL);

.|\n                                // ignore eveything else


    //     // 6: import a partition component
    // ^{OPTSP}import{SP}:{NAME};                  return lastWord(PARTSRC);

