|
| 1 | +{ |
| 2 | +(* Yoann Padioleau |
| 3 | + * |
| 4 | + * Copyright (C) 2010 Facebook |
| 5 | + * |
| 6 | + * This library is free software; you can redistribute it and/or |
| 7 | + * modify it under the terms of the GNU Lesser General Public License |
| 8 | + * version 2.1 as published by the Free Software Foundation, with the |
| 9 | + * special exception on linking described in file license.txt. |
| 10 | + * |
| 11 | + * This library is distributed in the hope that it will be useful, but |
| 12 | + * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the file |
| 14 | + * license.txt for more details. |
| 15 | + *) |
| 16 | + |
| 17 | +open Common |
| 18 | + |
| 19 | +module Flag = Flag_parsing_lisp |
| 20 | + |
| 21 | +open Parser_lisp |
| 22 | + |
| 23 | +(*****************************************************************************) |
| 24 | +(* Prelude *) |
| 25 | +(*****************************************************************************) |
| 26 | + |
| 27 | +(*****************************************************************************) |
| 28 | +(* Wrappers *) |
| 29 | +(*****************************************************************************) |
| 30 | +let pr2, pr2_once = Common.mk_pr2_wrappers Flag.verbose_lexing |
| 31 | + |
| 32 | +(*****************************************************************************) |
| 33 | +(* Helpers *) |
| 34 | +(*****************************************************************************) |
| 35 | +exception Lexical of string |
| 36 | + |
| 37 | +(* ---------------------------------------------------------------------- *) |
| 38 | +let tok lexbuf = |
| 39 | + Lexing.lexeme lexbuf |
| 40 | +let tokinfo lexbuf = |
| 41 | + Parse_info.tokinfo_str_pos (Lexing.lexeme lexbuf) (Lexing.lexeme_start lexbuf) |
| 42 | + |
| 43 | +} |
| 44 | + |
| 45 | +(*****************************************************************************) |
| 46 | + |
| 47 | +let letter = ['a'-'z''A'-'Z'] |
| 48 | +let digit = ['0'-'9'] |
| 49 | + |
| 50 | +(*****************************************************************************) |
| 51 | +rule sexp = parse |
| 52 | + |
| 53 | + (* ----------------------------------------------------------------------- *) |
| 54 | + (* spacing/comments *) |
| 55 | + (* ----------------------------------------------------------------------- *) |
| 56 | + | ";" [^'\n' '\r']* { |
| 57 | + TComment(tokinfo lexbuf) |
| 58 | + } |
| 59 | + | [' ''\t'] { TCommentSpace (tokinfo lexbuf) } |
| 60 | + | "\n" { TCommentNewline (tokinfo lexbuf) } |
| 61 | + |
| 62 | + (* ----------------------------------------------------------------------- *) |
| 63 | + (* Symbols *) |
| 64 | + (* ----------------------------------------------------------------------- *) |
| 65 | + |
| 66 | + | '(' { TOParen (tokinfo lexbuf) } |
| 67 | + | ')' { TCParen (tokinfo lexbuf) } |
| 68 | + |
| 69 | + (* ----------------------------------------------------------------------- *) |
| 70 | + (* Keywords and ident *) |
| 71 | + (* ----------------------------------------------------------------------- *) |
| 72 | + |
| 73 | + (* ----------------------------------------------------------------------- *) |
| 74 | + (* Constant *) |
| 75 | + (* ----------------------------------------------------------------------- *) |
| 76 | + |
| 77 | + | digit+ { |
| 78 | + TNumber(tok lexbuf, tokinfo lexbuf) |
| 79 | + } |
| 80 | + |
| 81 | + (* ----------------------------------------------------------------------- *) |
| 82 | + | eof { EOF (tokinfo lexbuf +> Parse_info.rewrap_str "") } |
| 83 | + | _ { |
| 84 | + if !Flag.verbose_lexing |
| 85 | + then pr2_once ("LEXER:unrecognised symbol, in token rule:"^tok lexbuf); |
| 86 | + TUnknown (tokinfo lexbuf) |
| 87 | + } |
0 commit comments