package pfff

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

Source file token_helpers_skip.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
(* Yoann Padioleau
 *
 * Copyright (C) 2019 Yoann Padioleau
 *
 * 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.
 *)

open Parser_skip
module PI = Parse_info

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

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

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

let token_kind_of_tok t =
  match t with
  | TOBrace _ -> PI.LBrace
  | TCBrace _ -> PI.RBrace
  | TOParen _ -> PI.LPar
  | TCParen _ -> PI.RPar
  (* less: also TOBracket? (and TOBracketAt...) *)

  | TComment _ -> PI.Esthet PI.Comment
  | TCommentSpace _ -> PI.Esthet PI.Space
  | TCommentNewline _ -> PI.Esthet PI.Newline

  | _ -> PI.Other

(*****************************************************************************)
(* Visitors *)
(*****************************************************************************)

let visitor_info_of_tok f = function
  | TCommentSpace ii -> TCommentSpace (f ii)
  | TCommentNewline ii -> TCommentNewline (f ii)
  | TComment ii -> TComment (f ii)
  | TUnknown ii -> TUnknown (f ii)
  | EOF (ii) -> EOF (f ii)

  | TQuestion ii -> TQuestion (f ii)
  | TAt ii -> TAt (f ii)
  | TSharp ii -> TSharp (f ii)
  | TDollar ii -> TDollar (f ii)
  | TBackquote ii -> TBackquote (f ii)
  | Tfor ii -> Tfor (f ii)
  | Tin ii -> Tin (f ii)
  | Textension ii -> Textension (f ii)
  | Tyield ii -> Tyield (f ii)
  | Tbreak ii -> Tbreak (f ii)
  | Tcontinue ii -> Tcontinue (f ii)
  | Tmemoized ii -> Tmemoized (f ii)
  | Tfrozen ii -> Tfrozen (f ii)
  | Tdo ii -> Tdo (f ii)
  | Twhile ii -> Twhile (f ii)
  | Tloop ii -> Tloop (f ii)

  | TEqDot ii -> TEqDot (f ii)
  | TTildeArrow ii -> TTildeArrow (f ii) 
  | TEqualArrow ii -> TEqualArrow (f ii)
  | TDiv ii -> TDiv (f ii)
  | TMod ii -> TMod (f ii)
  | TEqEq ii -> TEqEq (f ii)
  | TLessEq ii -> TLessEq (f ii)
  | TGreaterEq ii -> TGreaterEq (f ii)
  | THat ii -> THat (f ii)
  | TPipePipe ii -> TPipePipe (f ii)


  | TInt (s, ii) -> TInt (s, f ii)
  | TFloat (s, ii) -> TFloat (s, f ii)
  | TChar (s, ii) -> TChar (s, f ii)
  | TString (s, ii) -> TString (s, f ii)
  | TLowerIdent (s, ii) -> TLowerIdent (s, f ii)
  | TUpperIdent (s, ii) -> TUpperIdent (s, f ii)

  | Toverridable ii -> Toverridable (f ii)   
  | Treadonly ii -> Treadonly (f ii)   
  | Tmacro ii -> Tmacro (f ii)   

  | Talias ii -> Talias (f ii)   
  | Tas ii -> Tas (f ii)   
  | Tasync ii -> Tasync (f ii)   
  | Tawait ii -> Tawait (f ii)   
  | Tcatch ii -> Tcatch (f ii)   
  | Tchildren ii -> Tchildren (f ii)   
  | Tclass ii -> Tclass (f ii)   
  | Tconst ii -> Tconst (f ii)   
  | Telse ii -> Telse (f ii)   
  | Textends ii -> Textends (f ii) 
  | Tfinal ii -> Tfinal (f ii)   
  | Tfrom ii -> Tfrom (f ii)   
  | Tfun ii -> Tfun (f ii)   
  | Tif ii -> Tif (f ii)   
  | Tmatch ii -> Tmatch (f ii)   
  | Tmodule ii -> Tmodule (f ii)   
  | Tmutable ii -> Tmutable (f ii)   
  | Tnative ii -> Tnative (f ii)   
  | Tprivate ii -> Tprivate (f ii) 
  | Tprotected ii -> Tprotected (f ii)   
  | Tuses ii -> Tuses (f ii) 
  | Tstatic ii -> Tstatic (f ii) 
  | Tthis ii -> Tthis (f ii) 
  | Tthrow ii -> Tthrow (f ii) 
  | Ttrait ii -> Ttrait (f ii) 
  | Ttry ii -> Ttry (f ii) 
  | Ttype ii -> Ttype (f ii) 
  | Tvoid ii -> Tvoid (f ii) 
  | Twatch ii -> Twatch (f ii) 
  | Twhen ii -> Twhen (f ii) 
  | Twith ii -> Twith (f ii) 
  | Tbase ii -> Tbase (f ii) 
  | Tcapture ii -> Tcapture (f ii) 
  | Tdefault ii -> Tdefault (f ii) 
  | Tdeferred ii -> Tdeferred (f ii) 
  | Tinst ii -> Tinst (f ii) 
  | TnonNullable ii -> TnonNullable (f ii) 
  | Tuntracked ii -> Tuntracked (f ii) 
  | Tvalue ii -> Tvalue (f ii) 
  | Ttrue ii -> Ttrue (f ii) 
  | Tfalse ii -> Tfalse (f ii) 


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

  | TLess (ii) -> TLess (f ii)
  | TGreater (ii) -> TGreater (f ii)
  | TDot (ii) -> TDot (f ii)

  | TComma (ii) -> TComma (f ii)
  | TEq (ii) -> TEq (f ii)

  | TColon (ii) -> TColon (f ii)
  | TColonColon (ii) -> TColonColon (f ii)
  | TBang (ii) -> TBang (f ii)
  | TBangEq (ii) -> TBangEq (f ii)

  | TPipe (ii) -> TPipe (f ii)
  | TSemiColon (ii) -> TSemiColon (f ii)
  | TSemiColonSemiColon (ii) -> TSemiColonSemiColon (f ii)

  | TStar (ii) -> TStar (f ii)
  | TArrow (ii) -> TArrow (f ii)

  | TAnd (ii) -> TAnd (f ii)
  | TAndAnd (ii) -> TAndAnd (f ii)

  | TPlus (ii) -> TPlus (f ii)
  | TMinus (ii) -> TMinus (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

OCaml

Innovation. Community. Security.