diff options
author | Björn Gustavsson <bjorn@erlang.org> | 2021-11-02 07:08:54 +0100 |
---|---|---|
committer | Björn Gustavsson <bjorn@erlang.org> | 2022-02-11 13:35:04 +0100 |
commit | e025971d73273476e88e4bff385275b7f14ddc39 (patch) | |
tree | ff0922e6e919671504c61206110fd8b8bc5b6a5e /lib/compiler | |
parent | 2e4c52d00f9d6ba3e44280e6f62fae61168974f4 (diff) | |
download | erlang-e025971d73273476e88e4bff385275b7f14ddc39.tar.gz |
Add a poor man's implementation of `{enable_feature,Feature}`
There is ongoing work, which will result in an EEP and a pull request,
for a way to conditionally enable new or experimental features in
the compiler and runtime system.
This commit implements this feature in a crude way, to allow us to
selectively make `maybe` and `else` keywords instead of atoms. That
will allow us to compile source code that use `maybe` and `else`
as atoms. (They are quite a lot of code in OTP that uses `maybe` as
an atom.)
Note that as implemented in this commit, for the
`{enable_feature,maybe_expr}` to have any effect, it must be given as an
option to the compiler, **not** in the source code for the module.
Diffstat (limited to 'lib/compiler')
-rw-r--r-- | lib/compiler/src/compile.erl | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/compiler/src/compile.erl b/lib/compiler/src/compile.erl index ec0414cdda..847ea484ba 100644 --- a/lib/compiler/src/compile.erl +++ b/lib/compiler/src/compile.erl @@ -1018,12 +1018,25 @@ do_parse_module(DefEncoding, #compile{ifile=File,options=Opts,dir=Dir}=St) -> false -> 1 end, + + %% FIXME: Rewrite this when the enable feature EEP has been implemented. + ResWordFun = case proplists:get_value(enable_feature, Opts, []) of + maybe_expr -> + fun('maybe') -> true; + ('else') -> true; + (Other) -> erl_scan:reserved_word(Other) + end; + _ -> + fun erl_scan:reserved_word/1 + end, + R = epp:parse_file(File, [{includes,[".",Dir|inc_paths(Opts)]}, {source_name, SourceName}, {macros,pre_defs(Opts)}, {default_encoding,DefEncoding}, {location,StartLocation}, + {reserved_word_fun,ResWordFun}, extra]), case R of {ok,Forms0,Extra} -> |