package pfff

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

Source file metavars_generic.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
(* Yoann Padioleau
 *
 * Copyright (C) 2019 r2c
 *
 * 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

(*****************************************************************************)
(* Prelude *)
(*****************************************************************************)

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

(* mostly a copy-paste of metavars_fuzzy.ml and metavars_js.ml *)

(* less: could want to remember the position in the pattern of the metavar
 * for error reporting on pattern itself? so use a 'string Ast_generic.wrap'?
 *)
type mvar = string 

type metavars_binding = (mvar, Ast_generic.any) Common.assoc

(* ex: $X *)
let metavar_regexp_string = 
  "^\\(\\$[A-Z]\\)$"

(* ex: $x *)
let metavar_variable_regexp_string = 
  "^\\(\\$[a-z]\\)$"

(* 
 * Hacks abusing existing constructs to encode extra constructions.
 * One day we will have a pattern_ast.ml that mimics mostly
 * ast.ml and extends it with special sgrep constructs.
 *)
let is_metavar_name s = 
  s =~ metavar_regexp_string

let is_metavar_variable_name s = 
  s =~ metavar_variable_regexp_string
OCaml

Innovation. Community. Security.