package parser;

import bazar.Page;
import tree.RedBlackTree;
import tree.Tree;

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

/**
 * Classe implémentant le Parser
 * @author Alexis Giraudet &amp; François Hallereau
 * @version 1.0
 */
public class Parser {

    /**
     * Méthode qui parse un fichier pour en faire un dictionnaire
     * @param fileName le fichier servant de dictionnaire
     * @return un arbre représentant un dictionnaire
     * @throws IOException erreur d'entrée/sortie
     */
    public static Tree<String> parseDico(String fileName) throws IOException {
        Tree<String> t = new RedBlackTree<String>();
        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) {
                t.add(streamTokenizer.sval.toLowerCase());
            }
        }
        return t;
    }

    /**
     * Méthode qui parse un fichier pour en faire une page
     * @param fileName le fichier servant de page
     * @return une page
     * @throws IOException erreur d'entrée/sortie
     */
    public static Page parsePage(String fileName) throws IOException {
        Page p;
        Tree<String> words;
        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('»');*/
        if (streamTokenizer.nextToken() != StreamTokenizer.TT_NUMBER) {
            throw new IOException();
        }
        p = new Page((int) streamTokenizer.nval);
        words = p.getWords();
        while (streamTokenizer.nextToken() != StreamTokenizer.TT_EOF) {
            if (streamTokenizer.ttype == StreamTokenizer.TT_WORD) {
                words.add(streamTokenizer.sval.toLowerCase());
            }
        }
        return p;
    }
}

@@ -801,32 +801,83 @@
 er(fileName)));%0A
+        streamTokenizer.whitespaceChars(' ', '/');%0A
         /*stream
@@ -2135,32 +2135,85 @@
 ame)));%0A        
+streamTokenizer.whitespaceChars(' ', '/');%0A        /*
 streamTokenizer.
@@ -2428,34 +2428,32 @@
 r('?');%0A        
-/*
 streamTokenizer.
@@ -2985,24 +2985,75 @@
 getWords();%0A
+        streamTokenizer.whitespaceChars(' ', '@');%0A
         whil

fix parser