Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:23
erlang
2801-stdlib-Add-option-location-to-erl_parse-ab...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 2801-stdlib-Add-option-location-to-erl_parse-abstract-2.patch of Package erlang
From 7dbee868ab3ab82a5c1faf88cae2cf0429f91a0b Mon Sep 17 00:00:00 2001 From: Hans Bolinder <hasse@erlang.org> Date: Thu, 26 Nov 2020 07:25:40 +0100 Subject: [PATCH] stdlib: Add option 'location' to erl_parse:abstract/2 --- lib/stdlib/doc/src/erl_parse.xml | 9 +++++++-- lib/stdlib/src/erl_parse.yrl | 15 ++++++++++++--- lib/stdlib/test/erl_scan_SUITE.erl | 13 +++++++++++-- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/lib/stdlib/doc/src/erl_parse.xml b/lib/stdlib/doc/src/erl_parse.xml index 25f5d4d905..5af75433fe 100644 --- a/lib/stdlib/doc/src/erl_parse.xml +++ b/lib/stdlib/doc/src/erl_parse.xml @@ -133,8 +133,13 @@ <desc> <p>Converts the Erlang data structure <c><anno>Data</anno></c> into an abstract form of type <c><anno>AbsTerm</anno></c>.</p> - <p>Option <c><anno>Line</anno></c> is the line to be - assigned to each node of <c><anno>AbsTerm</anno></c>.</p> + <p>Each node of <c><anno>AbsTerm</anno></c> is assigned an + annotation, see <seeerl + marker="erl_anno"><c>erl_anno(3)</c></seeerl>. The annotation + contains the location given by option <c>location</c> or by + option <c>line</c>. Option <c>location</c> overrides option + <c>line</c>. If neither option <c>location</c> nor option + <c>line</c> is given, <c>0</c> is used as location.</p> <p>Option <c><anno>Encoding</anno></c> is used for selecting which integer lists to be considered as strings. The default is to use the encoding returned by diff --git a/lib/stdlib/src/erl_parse.yrl b/lib/stdlib/src/erl_parse.yrl index 5065459391..eb81e1b518 100644 --- a/lib/stdlib/src/erl_parse.yrl +++ b/lib/stdlib/src/erl_parse.yrl @@ -1376,19 +1376,28 @@ abstract(T) -> -spec abstract(Data, Options) -> AbsTerm when Data :: term(), Options :: Line | [Option], - Option :: {line, Line} | {encoding, Encoding}, + Option :: {encoding, Encoding} + | {line, Line} + | {location, Location}, Encoding :: 'latin1' | 'unicode' | 'utf8' | 'none' | encoding_func(), Line :: erl_anno:line(), + Location :: erl_anno:location(), AbsTerm :: abstract_expr(). abstract(T, Line) when is_integer(Line) -> Anno = erl_anno:new(Line), abstract(T, Anno, enc_func(epp:default_encoding())); abstract(T, Options) when is_list(Options) -> - Line = proplists:get_value(line, Options, 0), Encoding = proplists:get_value(encoding, Options,epp:default_encoding()), EncFunc = enc_func(Encoding), - Anno = erl_anno:new(Line), + Location = + case proplists:get_value(location, Options) of + undefined -> + proplists:get_value(line, Options, 0); + Loc -> + Loc + end, + Anno = erl_anno:new(Location), abstract(T, Anno, EncFunc). -define(UNICODE(C), diff --git a/lib/stdlib/test/erl_scan_SUITE.erl b/lib/stdlib/test/erl_scan_SUITE.erl index 162e2a0a3d..50e2bc1a35 100644 --- a/lib/stdlib/test/erl_scan_SUITE.erl +++ b/lib/stdlib/test/erl_scan_SUITE.erl @@ -23,7 +23,7 @@ init_per_group/2,end_per_group/2]). -export([error_1/1, error_2/1, iso88591/1, otp_7810/1, otp_10302/1, - otp_10990/1, otp_10992/1, otp_11807/1, otp_16480/1]). + otp_10990/1, otp_10992/1, otp_11807/1, otp_16480/1, otp_17024/1]). -import(lists, [nth/2,flatten/1]). -import(io_lib, [print/1]). @@ -58,7 +58,7 @@ suite() -> all() -> [{group, error}, iso88591, otp_7810, otp_10302, otp_10990, otp_10992, - otp_11807, otp_16480]. + otp_11807, otp_16480, otp_17024]. groups() -> [{error, [], [error_1, error_2]}]. @@ -1202,6 +1202,15 @@ otp_16480(Config) when is_list(Config) -> F = erl_parse:normalise(erl_parse_abstract(F)), ok. +otp_17024(Config) when is_list(Config) -> + Line = 17, + Opts1 = [{location,Line}], + {integer,Line,1} = erl_parse_abstract(1, Opts1), + Location = {17, 42}, + Opts2 = [{location,Location}], + {integer,Location,1} = erl_parse_abstract(1, Opts2), + ok. + test_string(String, ExpectedWithCol) -> {ok, ExpectedWithCol, _EndWithCol} = erl_scan_string(String, {1, 1}, []), Expected = [ begin -- 2.26.2
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor