aboutsummaryrefslogtreecommitdiffstats
path: root/lib/stdlib/src/erl_parse.yrl
AgeCommit message (Collapse)Author
2016-03-01Generalize bit string comprehensionsBjörn Gustavsson
The expression in a bit string comprehension is limited to a literal bit string expression. That is, the following code is legal: << <<X>> || X <- List >> but not this code: << foo(X) || X <- List >> The limitation is annoying. For one thing, tools that transform the abstract format must be careful not to produce code such as: << begin %% Some instrumentation code. <<X>> end || X <- List >> One reason for the limitation could be that we'll get reduce/reduce conflicts if we try to allow an arbitrary expression in a bit string comprehension: binary_comprehension -> '<<' expr '||' lc_exprs '>>' : {bc,?anno('$1'),'$2','$4'}. Unfortunately, there does not seem to be an easy way to work around that problem. The best we can do is to allow 'expr_max' expressions (as in the binary syntax): binary_comprehension -> '<<' expr_max '||' lc_exprs '>>' : {bc,?anno('$1'),'$2','$4'}. That will work, but functions calls must be enclosed in parentheses: << (foo(X)) || X <- List >>
2016-01-20stdlib: Update erl_parse(3)Hans Bolinder
Calls to map_anno(), fold_anno(), and mapfold_anno() with lists of erl_parse trees have been replaced. Those functions accept lists of erl_parse trees, but it was not the intention when the functions were introduced, and it is not documented.
2016-01-20stdlib: Refine the types of the abstract formatHans Bolinder
2015-12-15stdlib: Remove undocumented function specification syntaxHans Bolinder
The syntax -spec/callback F/A :: FunctionType; has been removed. No deprecation was deemed necessary.
2015-10-08Take out automatic insertion of 'undefined' from typed record fieldsKostis Sagonas
Background ----------- In record fields with a type declaration but without an initializer, the Erlang parser inserted automatically the singleton type 'undefined' to the list of declared types, if that value was not present there. I.e. the record declaration: -record(rec, {f1 :: float(), f2 = 42 :: integer(), f3 :: some_mod:some_typ()}). was translated by the parser to: -record(rec, {f1 :: float() | 'undefined', f2 = 42 :: integer(), f3 :: some_mod:some_typ() | 'undefined'}). The rationale for this was that creation of a "dummy" #rec{} record should not result in a warning from dialyzer that e.g. the implicit initialization of the #rec.f1 field violates its type declaration. Problems --------- This seemingly innocent action has some unforeseen consequences. For starters, there is no way for programmers to declare that e.g. only floats make sense for the f1 field of #rec{} records when there is no `obvious' default initializer for this field. (This also affects tools like PropEr that use these declarations produced by the Erlang parser to generate random instances of records for testing purposes.) It also means that dialyzer does not warn if e.g. an is_atom/1 test or something more exotic like an atom_to_list/1 call is performed on the value of the f1 field. Similarly, there is no way to extend dialyzer to warn if it finds record constructions where f1 is not initialized to some float. Last but not least, it is semantically problematic when the type of the field is an opaque type: creating a union of an opaque and a structured type is very problematic for analysis because it fundamentally breaks the opacity of the term at that point. Change ------- To solve these problems the parser will not automatically insert the 'undefined' value anymore; instead the user has the option to choose the places where this value makes sense (for the field) and where it does not and insert the | 'undefined' there manually. Consequences of this change ---------------------------- This change means that dialyzer will issue a warning for all places where records with uninitialized fields are created and those fields have a declared type that is incompatible with 'undefined' (e.g. float()). This warning can be suppressed easily by adding | 'undefined' to the type of this field. This also adds documentation that the user really intends to create records where this field is uninitialized.
2015-09-15stdlib: Remove deprecated functions in erl_parse and erl_scanHans Bolinder
The recently added module erl_anno can no longer handle negative line numbers.
2015-06-18Change license text to APLv2Bruce Yinhe
2015-06-12stdlib: Introduce precedence for operators in typesHans Bolinder
Add new functions erl_parse:type_inop_prec() and erl_parse:type_preop_prec(). Get rid of paren_type used for parentheses in types.
2015-04-30stdlib: Use module erl_annoHans Bolinder
2015-04-30stdlib: Add module erl_annoHans Bolinder
Introduce erl_anno, an abstraction of the second element of tokens and tuples in the abstract format. The convention that negative line numbers can be used for silencing compiler warnings will no longer work in OTP 19; instead the annotation 'generated' is to be used.
2014-11-20stdlib: remove the last traces of Mnemosyne RulesHans Bolinder
Robert has OK'ed the removal of the token ':-'.
2014-10-01Merge branch 'maint'Björn-Egil Dahlberg
2014-09-30stdlib: erl_parse abstract MapsBjörn-Egil Dahlberg
2014-09-30stdlib: Refactor Maps farity attributesBjörn-Egil Dahlberg
2014-08-04Allow Name/Arity syntax in maps inside attributesAndrey Tsirulev
Currently Name/Arity syntax is supported in list and tuple terms. This change makes it possible to use this syntax in map terms for consistency and convenience. Example: -custom(#{test1 => init/2, test2 => [val/1, val/2]}).
2014-05-14Merge branch 'maint'Marcus Arendt
2014-05-14Merge branch 'fenollp/remove-erl_parse-legacy-map' into maintMarcus Arendt
* fenollp/remove-erl_parse-legacy-map: Replace local mapl/2 (Erlang < 5.0) unique call by a LC
2014-04-29Modify representation of the map typeHans Bolinder
Types are represented by quadruples {type, LINE, Name, Args}, but maps were represented by five-tuples {type, LINE, map_field_assoc, Dom, Range}. Note: this is *not* about the quadruples used for representing expressions, {map_field_assoc,L,K,V}.
2014-04-29Disallow '_' as type variableHans Bolinder
"... when _ :: ..." used to compile, but Dialyzer crashed.
2014-04-29Allow more type namesHans Bolinder
product/_, union/_, range/2 as well as tuple/N (N > 0), map/N (N > 0), atom/1, integer/1, binary/2, record/_, and 'fun'/_ can now be used as type names.
2014-03-25stdlib: Generalize erl_parse:abstract/2Hans Bolinder
The 'encoding' option of erl_parse:abstract/2 has been extended to include 'none' and a callback function (a predicate). The rationale is that a more general means of determining what integer lists are to be represented as strings may help readability when generating Erlang code given input in some other encoding than Latin-1 or UTF-8.
2014-03-11Replace local mapl/2 (Erlang < 5.0) unique call by a LCPierre Fenoll
2014-01-28erts,stdlib: Change map module name to mapsBjörn-Egil Dahlberg
Name conforms to EEP.
2014-01-28dialyzer,hipe,stdlib: Add Maps understanding to DialyzerBjörn-Egil Dahlberg
2014-01-28stdlib: Deny variables as keys and disallow ':=' in map constructionBjörn-Egil Dahlberg
In the current iteration of Maps we should deny *any* variables in Map keys.
2014-01-28stdlib: Fix erl_parse:parse_term/1Björn-Egil Dahlberg
Did not handle Maps.
2014-01-28Extend erl_parse with two Op Map syntaxBjörn-Egil Dahlberg
Example how to construct: #{ K1 => V1, K2 => V2 } How to update: M#{ K1 => V1, K2 := V2 } How to match: #{ K1 := V1, K2 := V2 } = M
2014-01-28Extend erl_parse with the new map syntaxBjörn-Egil Dahlberg
Example how to match or construct: #{ K1 => V1, K2 => V2 } How to update: M#{ K => V }
2013-12-12EEP 37: Funs with namesAnthony Ramine
This adds optional names to fun expressions. A named fun expression is parsed as a tuple `{named_fun,Loc,Name,Clauses}` in erl_parse. If a fun expression has a name, it must be present and be the same in every of its clauses. The function name shadows the environment of the expression shadowing the environment and it is shadowed by the environment of the clauses' arguments. An unused function name triggers a warning unless it is prefixed by _, just as every variable. Variable _ is allowed as a function name. It is not an error to put a named function in a record field default value. When transforming to Core Erlang, the named fun Fun is changed into the following expression: letrec 'Fun'/Arity = fun (Args) -> let <Fun> = 'Fun'/Arity in Case in 'Fun'/Arity where Args is the list of arguments of 'Fun'/Arity and Case the Core Erlang expression corresponding to the clauses of Fun. This transformation allows us to entirely skip any k_var to k_local transformation in the fun's clauses bodies.
2013-03-29Document erl_parse:abstract/2Hans Bolinder
A bug has been fixed: when given the option {encoding,utf8} a list of floating point numbers (in the correct interval) was mistakenly returned as a string.
2013-01-25Export the type erl_scan:token()Hans Bolinder
The type erl_parse:token() used to be a two-tuple, but it can also be a three-tuple.
2013-01-16Remove support for the query keyword and query expressionsLoïc Hoguin
2013-01-09erl_parse: Remove support for packagesBjörn Gustavsson
2013-01-02[stdlib, kernel] Introduce Unicode support for Erlang source filesHans Bolinder
Expect modifications, additions and corrections. There is a kludge in file_io_server and erl_scan:continuation_location() that's not so pleasing.
2011-11-07EEP-23: Allow variables in fun M:F/ABjörn Gustavsson
Currently, the external fun syntax "fun M:F/A" only supports literals. That is, "fun lists:reverse/1" is allowed but not "fun M:F/A". In many real-life situations, some or all of M, F, A are not known until run-time, and one is forced to either use the undocumented erlang:make_fun/3 BIF or to use a "tuple fun" (which is deprecated). EEP-23 suggests that the parser (erl_parse) should immediately transform "fun M:F/A" to "erlang:make_fun(M, F, A)". We have not followed that approach in this implementation, because we want the abstract code to mirror the source code as closely as possible, and we also consider erlang:make_fun/3 to be an implementation detail that we might want to remove in the future. Instead, we will change the abstract format for "fun M:F/A" (in a way that is not backwards compatible), and while we are at it, we will move the translation from "fun M:F/A" to "erlang:make_fun(M, F, A)" from sys_pre_expand down to the v3_core pass. We will also update the debugger and xref to use the new format. We did consider making the abstract format backward compatible if no variables were used in the fun, but decided against it. Keeping it backward compatible would mean that there would be different abstract formats for the no-variable and variable case, and tools would have to handle both formats, probably forever. Reference: http://www.erlang.org/eeps/eep-0023.html
2011-10-07Add '-callback' attribute to language syntaxStavros Aronis
Behaviours may define specs for their callbacks using the familiar spec syntax, replacing the '-spec' keyword with '-callback'. Simple lint checks are performed to ensure that no callbacks are defined twice and all types referred are declared. These attributes can be then used by tools to provide documentation to the behaviour or find discrepancies in the callback definitions in the callback module.
2011-05-12Types and specifications have been modified and addedHans Bolinder
2011-03-22Fix a bug concerning record field typesHans Bolinder
The default value 'undefined' was added to records field types in such a way that the result was not always a well-formed type. This bug has been fixed. --- erl_pp has since OTP-8150 formatted types so that 'undefined' was removed from union types assigned to record fields. Since one cannot distinguish between 'undefined' added by the parser or supplied by the user, a side effect was that user supplied 'undefined's were also removed. Now the pretty printer shows 'undefined' even if added by the parser. This is a minor issue.
2010-06-02OTP-8664 Erlang parser augmented with operators for integer typesHans Bolinder
Expressions evaluating to integers can now be used in types and function specifications where hitherto only integers were allowed ("Erlang_Integer").
2010-05-31OTP-8657 New Erlang scanner tokens: '..' and '...'Hans Bolinder
The Erlang scanner has been augmented with two new tokens: .. and ....
2010-05-12OTP-8629 stdlib: prepare erl_parse.yrl for future extensionHans Bolinder
2010-04-20Support nested record field access without parenthesesTuncer Ayaz
Original patch from YAMASHINA Hio posted to erlang-patches@ on Tue Jun 12 11:27:53 CEST 2007: http://www.erlang.org/pipermail/erlang-patches/2007-June/000182.html http://fleur.hio.jp/pub/erlang/record2.patch Only had to do minor changes to port the patch to the current R14A development tree. Also added compiler/record_SUITE:nested_access/2 to test nested record access with or without parentheses. With this change the following will work. -record(nrec0, {name = <<"nested0">>}). -record(nrec1, {name = <<"nested1">>, nrec0=#nrec0{}}). -record(nrec2, {name = <<"nested2">>, nrec1=#nrec1{}}). nested_access() -> N0 = #nrec0{}, N1 = #nrec1{}, N2 = #nrec2{}, <<"nested0">> = N0#nrec0.name, <<"nested1">> = N1#nrec1.name, <<"nested2">> = N2#nrec2.name, <<"nested0">> = N1#nrec1.nrec0#nrec0.name, <<"nested0">> = N2#nrec2.nrec1#nrec1.nrec0#nrec0.name, <<"nested1">> = N2#nrec2.nrec1#nrec1.name, <<"nested0">> = ((N2#nrec2.nrec1)#nrec1.nrec0)#nrec0.name, N1a = N2#nrec2.nrec1#nrec1{name = <<"nested1a">>}, <<"nested1a">> = N1a#nrec1.name, N2a = N2#nrec2.nrec1#nrec1.nrec0#nrec0{name = <<"nested0a">>}, N2b = ((N2#nrec2.nrec1)#nrec1.nrec0)#nrec0{name = <<"nested0a">>}, <<"nested0a">> = N2a#nrec0.name, N2a = N2b, ok. Signed-off-by: Tuncer Ayaz <[email protected]>
2010-04-19OTP-8567 The word 'spec' is no longer reserved.Hans Bolinder
The function erl_scan:reserved_word/1 no longer returns true when given the word spec. This bug was introduced in STDLIB-1.15.3 (R12B-3).
2010-04-13erl_parse.yrl: Add missing operator in type declarationKostis Sagonas
2010-03-30erl_parse: Remove more stray 'cond' supportBjörn Gustavsson
Unfortunately, commit 1e2ecf8c492b6d499880b8676e3c1fe0c5793103 removed all cond support except for two lines.
2010-03-17OTP-8522 Avoid duplicated 'undefined' in record field typesHans Bolinder
The Erlang parser no longer duplicates the singleton type undefined in the type of record fields without initial value.
2010-03-16Remove stray code supporting 'cond'Björn Gustavsson
'cond' is an experimental feature that was never completed.
2009-11-20The R13B03 release.OTP_R13B03Erlang/OTP