<div><font style="background: rgb(255, 255, 255) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" color="#000000"><br>Hi, <br>
<br>I want to parse a file and match the file for several regular expressions. Based on what I match, I write more <br>rules so that based on all the rules, I can set my results. <br><br>Brute force method : Parse the entire file and add all the lines into the working memory. Write rules that 
<br>check each line for some regular expression. This works great. <br><br>I want to optimize the above, as we are checking each line, if we got we are looking for, then I want to get out. <br></font><div class="main-item">
<font color="#ff6600"><br></font></div><font style="background: rgb(255, 255, 255) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" color="#000000">
So, I wrote a function inside the rule file like the below <br><br>function String getLine(BufferedReader fileReader) {<br>&nbsp;&nbsp;&nbsp; String line;<br>&nbsp;&nbsp;&nbsp; try {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ((line = fileReader.readLine()) != null) {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return 
line.toLowerCase();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; System.out.println(&quot;This is an empty line.&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; } catch (Exception ex) {&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; return line;<br>}<br><br>Now, I need to write the rules that will use this. 
<br><br>rule &quot;Generate New Line&quot;<br><br>&nbsp;&nbsp;&nbsp; when <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; eval (getLine(fileReader) != null)<br>&nbsp;&nbsp;&nbsp; then <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; System.out.println(&quot;Generate new line&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //assert(getLine(fileReader)); // need to somehow assert the line specified in the eval condition
<br><br>end<br><br>Also, I am confused, how to specify file end. <br><br></font><font style="background: rgb(255, 255, 255) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" color="#000000">
rule &quot;File End&quot;<br>
<br>
&nbsp;&nbsp;&nbsp; when <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; eval (getLine(fileReader) == null)<br>
&nbsp;&nbsp;&nbsp; then <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; System.out.println(&quot;Reached end of file&quot;); // I am assuming this is not needed since if all rules are executed, then it will get out of fireRules() anyways ?<br><br>
end</font><br><font style="background: rgb(255, 255, 255) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" color="#000000">
<br>Any help is appreciated. <br><br>TIA, <br>Krishnan (newbie)<br><br></font></div>- <br>Sivaramakrishna Iyer Krishnan (Anand) <br><br>Never assume the obvious is true. <br>- William Safire