package pfff

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

Source file token_helpers_nw.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
(* 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.
 *)
open Common

open Lexer_nw

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
  | TOBracket _ -> PI.LBracket
  | TCBracket _ -> PI.RBracket
  | 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
  | TComment ii -> TComment (f ii)
  | TCommentSpace ii -> TCommentSpace (f ii)
  | TCommentNewline ii -> TCommentNewline (f ii)

  | TCommand (s, ii) -> TCommand (s, f ii)
  | TFootnote (c, ii) -> TFootnote (c, f ii)

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

  | TWord (s, ii) -> TWord (s, f ii)
  | TSymbol (s, ii) -> TSymbol (s, f ii)
  | TNumber (s, ii) -> TNumber (s, f ii)
  | TUnit (s, ii) -> TUnit (s, f ii)

  | TBeginVerbatim ii -> TBeginVerbatim (f ii)
  | TEndVerbatim ii -> TEndVerbatim (f ii)
  | TVerbatimLine (s, ii) -> TVerbatimLine (s, f ii)

  | TBeginNowebChunk ii -> TBeginNowebChunk (f ii)
  | TEndNowebChunk ii -> TEndNowebChunk (f ii)
  | TNowebChunkStr (s, ii) -> TNowebChunkStr (s, f ii)

  | TNowebChunkName (s, ii) -> TNowebChunkName (s, f ii)
  | TNowebCode (s, ii) -> TNowebCode (s, f ii)
  | TNowebCodeLink (s, ii) -> TNowebCodeLink (s, 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


OCaml

Innovation. Community. Security.