Skip to content

Instantly share code, notes, and snippets.

@rosado
Created May 8, 2011 18:23
Show Gist options
  • Save rosado/961566 to your computer and use it in GitHub Desktop.
Save rosado/961566 to your computer and use it in GitHub Desktop.
JavaRagelTemplate.rl
%%{
machine hello;
main := ( 'hello' | 'ahoy' );
}%%
public class FSM{
%% write data;
public FSM(){
}
public static int execFSM(String s, int cs){
char[] data = s.toCharArray();
int p = 0;
int pe = data.length;
int eof = pe;
%% write exec;
return cs;
}
public static int newInitialState(){
int cs;
%% write init;
return cs;
}
public static int execFSM(String s){
return execFSM(s, newInitialState());
}
public static void main(String[] args){
int state = execFSM(args[0]);
System.out.println(state >= %%{ write first_final; }%%);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment