1 |
|
%% Copyright (c) 2023 Peter Morgan <peter.james.morgan@gmail.com> |
2 |
|
%% |
3 |
|
%% Licensed under the Apache License, Version 2.0 (the "License"); |
4 |
|
%% you may not use this file except in compliance with the License. |
5 |
|
%% You may obtain a copy of the License at |
6 |
|
%% |
7 |
|
%% http://www.apache.org/licenses/LICENSE-2.0 |
8 |
|
%% |
9 |
|
%% Unless required by applicable law or agreed to in writing, software |
10 |
|
%% distributed under the License is distributed on an "AS IS" BASIS, |
11 |
|
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 |
|
%% See the License for the specific language governing permissions and |
13 |
|
%% limitations under the License. |
14 |
|
|
15 |
|
|
16 |
|
-module(pgsqlp_keyword). |
17 |
|
|
18 |
|
|
19 |
|
-export([by_category/1]). |
20 |
|
-export([cache/0]). |
21 |
|
-import(scran_branch, [alt/1]). |
22 |
|
-import(scran_character_complete, [re_no_case/1]). |
23 |
|
-on_load(on_load/0). |
24 |
|
|
25 |
|
|
26 |
|
-type keyword() :: unicode:chardata(). |
27 |
|
|
28 |
|
-type category() :: col_name_keyword |
29 |
|
| reserved_keyword |
30 |
|
| type_func_name_keyword |
31 |
|
| unreserved_keyword. |
32 |
|
|
33 |
|
|
34 |
|
-type is_bare_label() :: bare_label |
35 |
|
| as_label. |
36 |
|
|
37 |
|
|
38 |
|
-spec cache() -> [{keyword(), atom(), category(), is_bare_label()}]. |
39 |
|
|
40 |
|
cache() -> |
41 |
1376 |
persistent_term:get(?MODULE). |
42 |
|
|
43 |
|
|
44 |
|
-spec by_category(category()) -> scran:parser(). |
45 |
|
|
46 |
|
by_category(Desired) -> |
47 |
1368 |
fun |
48 |
|
(Input) -> |
49 |
1376 |
(alt( |
50 |
107328 |
[re_no_case(Keyword ++ "\\b") || |
51 |
1376 |
{Keyword, _, Category, _} <- cache(), |
52 |
648096 |
Desired == Category]))(Input) |
53 |
|
end. |
54 |
|
|
55 |
|
|
56 |
|
on_load() -> |
57 |
1 |
persistent_term:put( |
58 |
|
?MODULE, |
59 |
|
pgsqlp:priv_consult("keyword.terms")). |