package parser;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.StreamTokenizer;
import java.util.Collection;

/**
 * @author Alexis Giraudet
 */
public class Parser {

    public static void parseLines(String fileName, Collection<String> c) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new FileReader(fileName));
        String line;
        while ((line = bufferedReader.readLine()) != null) {
            c.add(line.toLowerCase());
        }
    }

    public static void parseTokens(String fileName, Collection<String> c) throws IOException {
        StreamTokenizer streamTokenizer = new StreamTokenizer(new BufferedReader(new FileReader(fileName)));
        streamTokenizer.quoteChar('.');
        streamTokenizer.quoteChar(',');
        streamTokenizer.quoteChar(';');
        streamTokenizer.quoteChar(':');
        streamTokenizer.quoteChar('!');
        streamTokenizer.quoteChar(',');
        streamTokenizer.quoteChar('"');
        streamTokenizer.quoteChar('(');
        streamTokenizer.quoteChar(')');
        streamTokenizer.quoteChar('[');
        streamTokenizer.quoteChar(']');
        streamTokenizer.quoteChar('{');
        streamTokenizer.quoteChar('}');
        streamTokenizer.quoteChar('«');
        streamTokenizer.quoteChar('»');
        while(streamTokenizer.nextToken() != StreamTokenizer.TT_EOF) {
            if(streamTokenizer.ttype == StreamTokenizer.TT_WORD) {
                c.add(streamTokenizer.sval.toLowerCase());
            }
        }
    }
}

@@ -10,16 +10,80 @@
 arser;%0A%0A
+import bazar.Page;%0Aimport tree.RedBlackTree;%0Aimport tree.Tree;%0A%0A
 import j
@@ -195,37 +195,8 @@
 zer;
-%0Aimport java.util.Collection;
 %0A%0A/*
@@ -250,17 +250,16 @@
 arser %7B%0A
-%0A
     publ
@@ -272,23 +272,30 @@
 tic 
-void
+Tree%3CString%3E
  parse
-Lines
+Dico
 (Str
@@ -306,38 +306,16 @@
 fileName
-, Collection%3CString%3E c
 ) throws
@@ -341,40 +341,115 @@
     
-BufferedReader bufferedReader = 
+Tree%3CString%3E t = new RedBlackTree%3CString%3E();%0A        StreamTokenizer streamTokenizer = new StreamTokenizer(
 new 
@@ -488,16 +488,17 @@
 leName))
+)
 ;%0A      
@@ -503,130 +503,844 @@
     
-String line;%0A        while ((line = bufferedReader.readLine()) != null) %7B%0A            c.add(line.toLowerCase());%0A        %7D
+/*streamTokenizer.quoteChar('.');%0A        streamTokenizer.quoteChar(',');%0A        streamTokenizer.quoteChar(';');%0A        streamTokenizer.quoteChar(':');%0A        streamTokenizer.quoteChar('!');%0A        streamTokenizer.quoteChar('?');%0A        streamTokenizer.quoteChar('%22');%0A        streamTokenizer.quoteChar('(');%0A        streamTokenizer.quoteChar(')');%0A        streamTokenizer.quoteChar('%5B');%0A        streamTokenizer.quoteChar('%5D');%0A        streamTokenizer.quoteChar('%7B');%0A        streamTokenizer.quoteChar('%7D');%0A        streamTokenizer.quoteChar('%C2%AB');%0A        streamTokenizer.quoteChar('%C2%BB');*/%0A        while (streamTokenizer.nextToken() != StreamTokenizer.TT_EOF) %7B%0A            if (streamTokenizer.ttype == StreamTokenizer.TT_WORD) %7B%0A                t.add(streamTokenizer.sval.toLowerCase());%0A            %7D%0A        %7D%0A        return t;
 %0A   
@@ -1365,24 +1365,22 @@
 tic 
-void
+Page
  parse
-Tokens
+Page
 (Str
@@ -1395,30 +1395,8 @@
 Name
-, Collection%3CString%3E c
 ) th
@@ -1405,32 +1405,76 @@
 ws IOException %7B
+%0A        Page p;%0A        Tree%3CString%3E words;
 %0A        StreamT
@@ -1794,33 +1794,33 @@
 izer.quoteChar('
-,
+?
 ');%0A        stre
@@ -1807,32 +1807,34 @@
 r('?');%0A        
+/*
 streamTokenizer.
@@ -2168,16 +2168,217 @@
 ar('%C2%BB');
+*/%0A        if (streamTokenizer.nextToken() != StreamTokenizer.TT_NUMBER) %7B%0A            throw new IOException();%0A        %7D%0A        p = new Page((int) streamTokenizer.nval);%0A        words = p.getWords();
 %0A       
@@ -2383,16 +2383,17 @@
    while
+ 
 (streamT
@@ -2456,16 +2456,17 @@
       if
+ 
 (streamT
@@ -2526,17 +2526,21 @@
         
-c
+words
 .add(str
@@ -2593,20 +2593,38 @@
 %7D%0A        %7D%0A
+        return p;%0A
     %7D%0A%7D%0A

update parser