package pfff

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file parser_lisp.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
(* Yoann Padioleau
 *
 * Copyright (C) 2010 Facebook
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * version 2.1 as published by the Free Software Foundation, with the
 * special exception on linking described in file license.txt.
 * 
 * This library 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 file
 * license.txt for more details.
 *)
module PI = Parse_info

(*****************************************************************************)
(* Types *)
(*****************************************************************************)

type token =
  | TComment of (Ast_lisp.info)
  | TCommentSpace of (Ast_lisp.info)
  | TCommentNewline of (Ast_lisp.info)

  | TNumber of (string * Ast_lisp.info)
  | TIdent of (string * Ast_lisp.info)
  | TString of (string * Ast_lisp.info)

  | TOParen of (Ast_lisp.info)
  | TCParen of (Ast_lisp.info)
  | TOBracket of (Ast_lisp.info)
  | TCBracket of (Ast_lisp.info)

  | TQuote of (Ast_lisp.info)
  (* anti-quote expressions tokens, as in `(foo ,v ,@xs) *)
  | TBackQuote of (Ast_lisp.info)
  | TComma  of (Ast_lisp.info)
  | TAt  of (Ast_lisp.info)

  | TUnknown of (Ast_lisp.info)
  | EOF of (Ast_lisp.info)

(*****************************************************************************)
(* Token Helpers *)
(*****************************************************************************)

let is_eof = function
  | EOF _ -> true
  | _ -> false

let is_comment = function
  | TComment _ | TCommentSpace _ | TCommentNewline _ -> true
  | _ -> false 

let is_just_comment = function
  | TComment _ -> true
  | _ -> false 

(*****************************************************************************)
(* Visitors *)
(*****************************************************************************)
let visitor_info_of_tok f = function
  | TComment ii -> TComment (f ii)
  | TCommentSpace ii -> TCommentSpace (f ii)
  | TCommentNewline ii -> TCommentNewline (f ii)

  | TNumber (s, ii) -> TNumber (s, f ii)
  | TIdent (s, ii) -> TIdent (s, f ii)
  | TString (s, ii) -> TString (s, f ii)

  | TOParen ii -> TOParen (f ii)
  | TCParen ii -> TCParen (f ii)
  | TOBracket ii -> TOBracket (f ii)
  | TCBracket ii -> TCBracket (f ii)

  | TQuote ii -> TQuote (f ii)
  | TBackQuote ii -> TBackQuote (f ii)
  | TComma ii -> TComma (f ii)
  | TAt ii -> TAt (f ii)

  | TUnknown ii -> TUnknown (f ii)
  | EOF ii -> EOF (f ii)

let info_of_tok tok = 
  let res = ref None in
  visitor_info_of_tok (fun ii -> res := Some ii; ii) tok |> ignore;
  Common2.some !res


let str_of_tok  x = PI.str_of_info  (info_of_tok x)
OCaml

Innovation. Community. Security.