package p4spectec

  1. Overview
  2. Docs
P4-SpecTec: A mechanization toolchain for the P4 Programming Language

Install

dune-project
 Dependency

Authors

Maintainers

Sources

v0.1.2.tar.gz
md5=1a3bc0a385fe1ecf403c019f49aa6de6
sha512=5d20b5821f33e2a3a5419b208606f27c01511994c2b3b1e1cdf4c077056dfd0aa81682af0720e1060ee2bfb0341918fcc4c53159820205a2bc32b725e5c1a714

doc/src/p4spectec.stf/transform.ml.html

Source file transform.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
module Name = struct
  let rewrite_substring ~(substrings : string list) ~(replacement : string)
      (name : Ast.name) : Ast.name =
    (match String.split_on_char '.' name with
    | [] -> failwith "Unreachable"
    | hd :: tl ->
        if
          List.exists
            (fun substring -> Core.String.Caseless.is_substring hd ~substring)
            substrings
        then replacement :: tl
        else hd :: tl)
    |> String.concat "."

  let replace_substring ~(substrings : string list) ~(replacement : string)
      (name : Ast.name) : Ast.name =
    let open Core.String.Caseless in
    List.fold_left
      (fun name substring ->
        if is_substring name ~substring then
          substr_replace_first name ~pattern:substring ~with_:replacement
        else name)
      name substrings
end

module Match = struct
  let rewrite_valid ((name, mtchkind) : Ast.mtch) : Ast.mtch =
    let name = Str.global_replace (Str.regexp "\\$valid\\$") "isValid()" name in
    (name, mtchkind)
end

module Action = struct
  let into_unqualified ((name, args) : Ast.action) : Ast.action =
    let name = String.split_on_char '.' name |> List.rev |> List.hd in
    (name, args)

  let replace_substring = Name.replace_substring
end