(* $Id: pxp_lex_misc.src,v 1.6 2001/06/28 22:42:32 gerd Exp $
 * ----------------------------------------------------------------------
 *
 *)


{
  open Pxp_types
  open Pxp_lexer_types

#insert open_pxp_lex_aux_*.src
}

#insert pxp_lex_defs_*.def

(* The remaining, smaller lexers *)

rule scan_characters = parse
  character*
    { () }
| eof 
    { () }
| _
    { raise Netconversion.Malformed_code }


and scan_xml_pi = parse
    name ws*
      { let s = Lexing.lexeme lexbuf in
	let j = get_name_end s 0 in
	Pro_name (String.sub s 0 j)
      }
  | "=" ws*
      { Pro_eq }
  | "'" character_except_apos* "'" ws+
      { let s = Lexing.lexeme lexbuf in
	let j = String.index_from s 1 '\'' in
	Pro_string (String.sub s 1 (j-1))
      }
  | "'"
      { raise (WF_error ("Cannot find the second quotation mark"))
      }
  | '"' character_except_quot* '"' ws+
      { let s = Lexing.lexeme lexbuf in
	let j = String.index_from s 1 '"' in
	Pro_string (String.sub s 1 (j-1))
      }
  | '"'
      { raise (WF_error ("Cannot find the second quotation mark"))
      }
  | eof
      { Pro_eof }
  | character
      { (* prerr_endline (Lexing.lexeme lexbuf); *)
	raise (WF_error("Illegal token or character")) 
      }
  | _ 
      { raise Netconversion.Malformed_code }

and scan_only_xml_decl = parse
    "<?xml" ws+ pi_string "?>"
      { scan_pi (Lexing.lexeme lexbuf) scan_xml_pi }
  | ""
      { Eof }

and scan_for_crlf = parse
  | '\013' '\010'
      { CharData "\n" }
  | '\013'
      { CharData "\n" }
  | '\010'
      { CharData "\n" }
  | [^ '\010' '\013' ]+
      { CharData (Lexing.lexeme lexbuf) }
  | eof 
      { Eof }

and scan_content_comment = parse
    "-->"
      { Comment_end dummy_entity, Content }
  | "--"
      { raise (WF_error "Double hyphens are illegal inside comments") }
  | "-"
      { Comment_material "-", Content_comment }
  | character_except_minus+
      { Comment_material(Lexing.lexeme lexbuf), Content_comment }
  | eof
      { Eof, Content_comment }
  | _
      { raise Netconversion.Malformed_code }


(* In declarations, comments are always thrown away. *)

and scan_decl_comment = parse
    "-->"
      { Comment_end dummy_entity, Declaration }
  | "--"
      { raise (WF_error "Double hyphens are illegal inside comments") }
  | "-"
      { Comment_material "", Decl_comment }
  | character_except_minus+
      { Comment_material "", Decl_comment }
  | eof
      { Eof, Decl_comment }
  | _
      { raise Netconversion.Malformed_code }


and scan_document_comment = parse
    "-->"
      { Comment_end dummy_entity, Document }
  | "--"
      { raise (WF_error "Double hyphens are illegal inside comments") }
  | "-"
      { Comment_material "-", Document_comment }
  | character_except_minus+
      { Comment_material(Lexing.lexeme lexbuf), Document_comment }
  | eof
      { Eof, Document_comment }
  | _
      { raise Netconversion.Malformed_code }

(* ======================================================================
 * History:
 * 
 * $Log: pxp_lex_misc.src,v $
 * Revision 1.6  2001/06/28 22:42:32  gerd
 * 	Comment tokens have entity_id
 *
 * Revision 1.5  2001/06/14 14:25:56  gerd
 * 	Removed insertion of pxp_lex_aux.src
 *
 * Revision 1.4  2000/08/18 20:19:59  gerd
 * 	Comments return different comment tokens.
 *
 * Revision 1.3  2000/08/14 22:18:34  gerd
 * 	Bad_character_stream -> Netconversion.Malformed_code
 *
 * Revision 1.2  2000/05/29 23:53:12  gerd
 * 	Updated because Markup_* modules have been renamed to Pxp_*.
 *
 * Revision 1.1  2000/05/20 20:33:25  gerd
 * 	Initial revision.
 *
 * 
 *)
