// htmlTagMatcher.h  P. Conrad, CISC220 06J
// A class that matches HTML Tags


#ifndef HTMLTAGMATCHER_H
#define HTMLTAGMATCHER_H

#include <iostream>
#include <string>

using std::istream;
using std::ostream;

#include "HTMLTagStack.h"

class HTMLTagMatcher_C 
{
 public:
  HTMLTagMatcher_C(istream & theInput,
		   ostream & theOutput) :
    in(theInput), out(theOutput) // initialize
    { 
      line = 1;
      pos = 1;
      state = EXPECT_LT;

      startLine = 1; startPos = 1;
      tagSoFar = "";
    }

  void match(); // do the work.. read from input, send output to output

 private:
  
  void process(char c);
  void error(char c);

  // references to (aliases for) input stream and output stream

  istream & in;
  ostream & out;

  int startLine; int startPos;

  int line;
  int pos;
  enum State_C {EXPECT_LT, 
		EXPECT_LETTER_OR_SLASH,
		BUILD_OPEN_TAG,
		BUILD_CLOSING_TAG,
		EXPECT_GT_FOR_SELF_CLOSING_TAG,
		ERROR_STATE};
  State_C state;

  HTMLTagStack_C s;

  std::string tagSoFar;


};

#endif


