(***********************************************************************) (* *) (* Copyright 2006 Philippe Wang - mail@philippewang.info *) (* *) (* Yet Another Caml Lexer *) (* *) (* *) (* This program is free software; you can redistribute it and/or *) (* modify it under the terms of the GNU General Public *) (* License as published by the Free Software Foundation; either *) (* version 2 of the License, or (at your option) any later version. *) (* *) (* This program is distributed in the hope that it will be useful, *) (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *) (* General Public License for more details. *) (* *) (* You should have received a copy of the GNU General Public *) (* License along with this program; if not, write to the *) (* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, *) (* Boston, MA 02110-1301, USA. *) (***********************************************************************) type location = { sl : int; sc : int; el : int; ec : int } type t = { loc : location; token : token } and token = Int of int | Float of float | Upper of string | Lower of string | String of string | Char of char | Infix of string | Prefix of string | Operator of string | Comment of string | And | As | Begin | Class | Constraint | Do | Done | Downto | Else | End | Exception | External | False | For | Fun | Function | Functor | If | In | Include | Inherit | Initializer | Lazy | Let | Match | Method | Mod | Module | Mutable | New | Object | Of | Open | Private | Rec | Sig | Struct | Then | To | True | Try | Type | Val | Virtual | When | While | With | Abstract | EpEq | Sharp | Amp | AmpAmp | Quote | OpenP | CloseP | Star | Plus | Comma | Hyphen | HyphenDot | HyphenGt | Dot | DotDot | Colon | ColonColon | ColonEq | ColonGt | SemiColon | SemiColonSemiColon | Lt | LtHyphen | Eq | Gt | GtCloseSB | GtCloseCB | Im | ImIm | OpenSB | OpenSBLt | OpenSBGt | OpenSBVertLine | CloseSB | Underscore | BackQuote | OpenCB | OpenCBLt | VertLine | VertLineCloseSB | CloseCB | Tild | Lor | Lsl | Lsr | Asr | Or | Lxor | Land | Xor | Eof | VertLineVertLine let keyops = ["!=", EpEq; "#", Sharp; "&", Amp; "&&", AmpAmp; "'", Quote; "(", OpenP; ")", CloseP; "*", Star; "+", Plus; ",", Comma; "-", Hyphen; "-.", HyphenDot; "->", HyphenGt; ".", Dot; "..", DotDot; ":", Colon; "::", ColonColon; ":=", ColonEq; ":>", ColonGt; ";", SemiColon; ";;", SemiColonSemiColon; "<", Lt; "<-", LtHyphen; "=", Eq; ">", Gt; ">]", GtCloseSB; ">}", GtCloseCB; "?", Im; "??", ImIm; "[", OpenSB; "[<", OpenSBLt; "[>", OpenSBGt; "[|", OpenSBVertLine; "]", CloseSB; "_", Underscore; "`", BackQuote; "{<", OpenCBLt; "|]", VertLineCloseSB; "||", VertLineVertLine; "|", VertLine; "{", OpenCB; "}", CloseCB; "~", Tild; "land", Land; "lor", Lor; "lsl", Lsl; "lsr", Lsr; "lxor", Lxor; "asr", Asr; "or", Or; "xor", Xor; "mod", Mod] let keywords = ["and", And; "as", As; "lazy", Lazy; "EOF", Eof; "begin", Begin; "class", Class; "constraint", Constraint; "do", Do; "done", Done; "downto", Downto; "else", Else; "end", End; "exception", Exception; "external", External; "false", False; "for", For; "fun", Fun; "function", Function; "functor", Functor; "if", If; "in", In; "include", Include; "inherit", Inherit; "initializer", Initializer; "let", Let; "match", Match; "method", Method; "module", Module; "mutable", Mutable; "new", New; "object", Object; "of", Of; "open", Open; "private", Private; "abstract", Abstract; "rec", Rec; "sig", Sig; "struct", Struct; "then", Then; "to", To; "true", True; "try", Try; "type", Type; "val", Val; "virtual", Virtual; "when", When; "while", While; "with", With] type 'a buffer = { mutable buffer : char list; stream : 'a; mutable line : int; mutable column : int; pop : unit -> char; push : char -> unit; mutable widths : int list } exception Lexical_error of location type position = { name : string; mutable lin : int; mutable col : int } type lexbuf = { mutable lex_start_p : position; mutable lex_curr_p : position; lex_buf : Pervasives.in_channel buffer }