*
* PropertiesLexer shredder = new PropertiesLexer(System.in);
* PropertiesToken t;
* while ((t = shredder.getNextToken()) != null){
* System.out.println(t);
* }
*
*
*
* @see PropertiesToken
* @author Stephen Ostermiller http://ostermiller.org/contact.pl?regarding=Java+Utilities
* @since ostermillerutils 1.00.00
*/
%%
%class PropertiesLexer
%apiprivate
%function getToken
%type PropertiesToken
%unicode
%{
private int lastToken;
private int nextState=YYINITIAL;
/**
* Prints out tokens from a file or System.in.
* If no arguments are given, System.in will be used for input.
* If more arguments are given, the first argument will be used as
* the name of the file to use as input
*
* @param args program arguments, of which the first is a filename
*
* @since ostermillerutils 1.00.00
*/
public static void main(String[] args) {
InputStream in;
try {
if (args.length > 0){
File f = new File(args[0]);
if (f.exists()){
if (f.canRead()){
in = new FileInputStream(f);
} else {
throw new IOException("Could not open " + args[0]);
}
} else {
throw new IOException("Could not find " + args[0]);
}
} else {
in = System.in;
}
PropertiesLexer shredder = new PropertiesLexer(in);
PropertiesToken t;
while ((t = shredder.getNextToken()) != null) {
if (true || t.getID() != PropertiesToken.WHITE_SPACE){
System.out.println(t);
}
}
} catch (IOException e){
System.err.println(e.getMessage());
}
}
/**
* Return the next token from the properties.
*
* @return the next token
* @throws IOException if an error occurs while reading the properties.
*/
public PropertiesToken getNextToken() throws IOException {
return getToken();
}
%}
%full
%state LINE_END
%state WHITE_SPACE
%state NAME
%state NAME_SPACE
%state MID_NAME
%state MID_NAME_NEW_LINE
%state SEPARATOR
%state VALUE
%state MID_VALUE
%state DONE
HexDigit=([0-9a-fA-F])
BLANK=([ ])
TAB=([\t])
FF=([\f])
EscChar=([\\])
CR=([\r])
LF=([\n])
EOL=({CR}|{LF}|{CR}{LF})
WhiteSpace=({BLANK}|{TAB}|{FF})
LineEndingWhiteSpace=({EOL})
fourHex=({HexDigit}{4})
UnicodeEscape=({EscChar}[u]({fourHex}*))
Escape=(({EscChar}[^\r\n])|{UnicodeEscape})
LineEscape=({EscChar}{EOL})
NameText=([^\=\:\t\f\r\n\\ ]|{Escape})
NameTextWSeparators=([^\t\f\r\n\\ ]|{Escape})
ValueText=([^\r\n\\]|{Escape})
Comment=({WhiteSpace}*[\!\#][^\r\n]*)
Name=({NameText}*)
Value=((({NameText}+){ValueText}*)?)
FullValue=((({NameTextWSeparators}+){ValueText}*)?)
%%