檢視原始碼 erl_parse (stdlib v6.2)

此模組是基本的 Erlang 解析器,可將詞法單元轉換為 forms(即頂層結構)、表達式或項的抽象形式。

抽象格式在 ERTS 使用者指南中有說明。請注意,詞法單元列表必須以點詞法單元結尾,才能被解析函數接受(請參閱 erl_scan)模組。

錯誤資訊

ErrorInfo 是所有 I/O 模組返回的標準 ErrorInfo 結構。格式如下:

{ErrorLine, Module, ErrorDescriptor}

可使用以下呼叫取得描述錯誤的字串:

Module:format_error(ErrorDescriptor)

另請參閱

erl_annoerl_scanio,以及 ERTS 使用者指南中的 抽象格式 一節。

摘要

類型

Erlang 子句的抽象形式。

Erlang 表達式的抽象形式。

Erlang form 的抽象形式。

Erlang 類型的抽象形式。

位元字串元素的抽象表示。

記錄欄位的抽象表示。

產生器或位元字串產生器的抽象表示。

遠端函數呼叫的抽象表示。

元組 {error, error_info()}{warning, error_info()},表示語法不正確的 form 和警告,以及 {eof, line()},表示在解析完整 form 之前遇到串流結尾。

函式

將 Erlang 資料結構 Data 轉換為 AbsTerm 類型的抽象形式。此函式是 normalise/1 的反函數。

將 Erlang 資料結構 Data 轉換為 AbsTerm 類型的抽象形式。

假設 Term 是一個與 erl_parse 樹具有相同結構的項,但其項(例如 T)是 erl_parse 樹具有註釋集合的地方。

返回一個項,其中 erl_parseAbstr 的節點的每個註釋集合 Anno 都被 erl_anno:to_term(Anno) 返回的項取代。erl_parse 樹是以深度優先、從左到右的方式遍歷。

透過在 erl_parseAbstr 的每個註釋集合上套用 Fun 來更新累加器。

使用 ErrorDescriptor 並返回描述錯誤的字串。

透過在 erl_parse 樹的節點的每個註釋集合上套用 Fun 來修改 erl_parseAbstrerl_parse 樹是以深度優先、從左到右的方式遍歷。

透過在 erl_parse 樹的節點的每個註釋集合上套用 Fun 來修改 erl_parseAbstr,同時更新累加器。

假設 Term 是一個與 erl_parse 樹具有相同結構的項,但在 erl_parse 樹具有註釋集合的地方,具有位置

將項的抽象形式 AbsTerm 轉換為傳統的 Erlang 資料結構(即項本身)。此函式是 abstract/1 的反函數。

解析 Tokens,就好像它是一個表達式列表一樣。

解析 Tokens,就好像它是一個 form 一樣。

解析 Tokens,就好像它是一個項一樣。

產生一個表示表達式抽象形式 AbsTerm 的詞法單元列表。您可以選擇性地附加 MoreTokens

類型

-type abstract_clause() :: af_clause().

Erlang 子句的抽象形式。

Erlang 表達式的抽象形式。

Erlang form 的抽象形式。

Erlang 類型的抽象形式。

-type af_anno() :: af_variable().
此類型的連結

af_annotated_type()

檢視原始碼 (未匯出)
-type af_annotated_type() :: {ann_type, anno(), [af_anno() | abstract_type()]}.
-type af_args() :: [abstract_expr()].
-type af_assoc(T) :: {map_field_assoc, anno(), T, T} | af_assoc_exact(T).
此類型的連結

af_assoc_exact(T)

檢視原始碼 (未匯出)
-type af_assoc_exact(T) :: {map_field_exact, anno(), T, T}.
此類型的連結

af_assoc_type()

檢視原始碼 (未匯出)
-type af_assoc_type() ::
          {type, anno(), map_field_assoc, [abstract_type()]} |
          {type, anno(), map_field_exact, [abstract_type()]}.
-type af_atom() :: af_lit_atom(atom()).
此類型的連結

af_behavior()

檢視原始碼 (未匯出)
-type af_behavior() :: {attribute, anno(), behavior, behaviour()}.
此類型的連結

af_behaviour()

檢視原始碼 (未匯出)
-type af_behaviour() :: {attribute, anno(), behaviour, behaviour()}.
-type af_bin(T) :: {bin, anno(), [af_binelement(T)]}.
此類型的連結

af_binary_comprehension()

檢視原始碼 (未匯出)
-type af_binary_comprehension() :: {bc, anno(), af_template(), af_qualifier_seq()}.
此類型的連結

af_binary_op(T)

檢視原始碼 (未匯出)
-type af_binary_op(T) :: {op, anno(), binary_op(), T, T}.
-type af_binelement(T) :: {bin_element, anno(), T, af_binelement_size(), type_specifier_list()}.

位元字串元素的抽象表示。

此類型的連結

af_binelement_size()

檢視原始碼 (未匯出)
-type af_binelement_size() :: default | abstract_expr().
此類型的連結

af_bitstring_type()

檢視原始碼 (未匯出)
-type af_bitstring_type() :: {type, anno(), binary, [af_singleton_integer_type()]}.
-type af_block() :: {block, anno(), af_body()}.
-type af_body() :: [abstract_expr(), ...].
-type af_case() :: {'case', anno(), abstract_expr(), af_clause_seq()}.
-type af_catch() :: {'catch', anno(), abstract_expr()}.
此類型的連結

af_character()

檢視原始碼 (未匯出)
-type af_character() :: {char, anno(), char()}.
-type af_clause() :: {clause, anno(), [af_pattern()], af_guard_seq(), af_body()}.
此類型的連結

af_clause_seq()

檢視原始碼 (未匯出)
-type af_clause_seq() :: [af_clause(), ...].
此類型的連結

af_compile()

檢視原始碼 (未匯出)
-type af_compile() :: {attribute, anno(), compile, any()}.
-type af_cons(T) :: {cons, anno(), T, T}.
此類型的連結

af_constrained_function_type()

檢視原始碼 (未匯出)
-type af_constrained_function_type() ::
          {type, anno(), bounded_fun, [af_function_type() | af_function_constraint()]}.
此類型的連結

af_constraint()

檢視原始碼 (未匯出)
-type af_constraint() ::
          {type, anno(), constraint, [af_lit_atom(is_subtype) | [af_type_variable() | abstract_type()]]}.
此類型的連結

af_empty_list_type()

檢視原始碼 (未匯出)
-type af_empty_list_type() :: {type, anno(), nil, []}.
-type af_export() :: {attribute, anno(), export, af_fa_list()}.
此類型的連結

af_export_type()

檢視原始碼 (未匯出)
-type af_export_type() :: {attribute, anno(), export_type, af_ta_list()}.
此類型的連結

af_fa_list()

檢視原始碼 (未匯出)
-type af_fa_list() :: [{function_name(), arity()}].
-type af_field() ::
          {record_field, anno(), af_field_name()} |
          {record_field, anno(), af_field_name(), abstract_expr()}.
-type af_field_decl() :: af_typed_field() | af_field().

記錄欄位的抽象表示。

此類型的連結

af_field_name()

檢視原始碼 (未匯出)
-type af_field_name() :: af_atom().
-type af_file() :: {attribute, anno(), file, {string(), anno()}}.
-type af_filter() :: abstract_expr().
-type af_float() :: {float, anno(), float()}.
-type af_fun() :: {'fun', anno(), {clauses, af_clause_seq()}}.
此類型的連結

af_fun_type()

檢視原始碼 (未匯出)
-type af_fun_type() ::
          {type, anno(), 'fun', []} |
          {type, anno(), 'fun', [{type, anno(), any} | abstract_type()]} |
          af_function_type().
此類型的連結

af_function_constraint()

檢視原始碼 (未匯出)
-type af_function_constraint() :: [af_constraint(), ...].
此類型的連結

af_function_decl()

檢視原始碼 (未匯出)
-type af_function_decl() :: {function, anno(), function_name(), arity(), af_clause_seq()}.
此類型的連結

af_function_spec()

檢視原始碼 (未匯出)
-type af_function_spec() ::
          {attribute, anno(), spec_attr(), {{function_name(), arity()}, af_function_type_list()}} |
          {attribute, anno(), spec, {{module(), function_name(), arity()}, af_function_type_list()}}.
此類型的連結

af_function_type()

檢視原始碼 (未匯出)
-type af_function_type() ::
          {type, anno(), 'fun', [{type, anno(), product, [abstract_type()]} | abstract_type()]}.
此類型的連結

af_function_type_list()

檢視原始碼 (未匯出)
-type af_function_type_list() :: [af_constrained_function_type() | af_function_type(), ...].
-type af_generator() ::
          {generate, anno(), af_pattern(), abstract_expr()} |
          {m_generate, anno(), af_assoc_exact(af_pattern()), abstract_expr()} |
          {b_generate, anno(), af_pattern(), abstract_expr()}.

產生器或位元字串產生器的抽象表示。

-type af_guard() :: [af_guard_test(), ...].
此類型的連結

af_guard_call()

檢視原始碼 (未匯出)
-type af_guard_call() :: {call, anno(), af_atom(), [af_guard_test()]}.
此類型的連結

af_guard_seq()

檢視原始碼 (未匯出)
-type af_guard_seq() :: [af_guard()].
此類型的連結

af_guard_test()

檢視原始碼 (未匯出)
-type af_if() :: {'if', anno(), af_clause_seq()}.
-type af_import() :: {attribute, anno(), import, {module(), af_fa_list()}}.
此類型的連結

af_integer()

檢視原始碼 (未匯出)
-type af_integer() :: {integer, anno(), non_neg_integer()}.
此類型的連結

af_integer_range_type()

檢視原始碼 (未匯出)
-type af_integer_range_type() :: {type, anno(), range, [af_singleton_integer_type()]}.
此類型的連結

af_list_comprehension()

檢視原始碼 (未匯出)
-type af_list_comprehension() :: {lc, anno(), af_template(), af_qualifier_seq()}.
此類型的連結

af_lit_atom(A)

檢視原始碼 (未匯出)
-type af_lit_atom(A) :: {atom, anno(), A}.
此類型的連結

af_literal()

檢視原始碼 (未匯出)
-type af_literal() :: af_atom() | af_character() | af_float() | af_integer() | af_string().
此類型的連結

af_local_call()

檢視原始碼 (未匯出)
-type af_local_call() :: {call, anno(), af_local_function(), af_args()}.
此類型的連結

af_local_fun()

檢視原始碼 (未匯出)
-type af_local_fun() :: {'fun', anno(), {function, function_name(), arity()}}.
此類型的連結

af_local_function()

檢視原始碼 (未匯出)
-type af_local_function() :: abstract_expr().
此類型的連結

af_map_comprehension()

檢視原始碼 (未匯出)
-type af_map_comprehension() :: {mc, anno(), af_assoc(abstract_expr()), af_qualifier_seq()}.
此類型的連結

af_map_creation(T)

檢視原始碼 (未匯出)
-type af_map_creation(T) :: {map, anno(), [af_assoc(T)]}.
此類型的連結

af_map_pattern()

檢視原始碼 (未匯出)
-type af_map_pattern() :: {map, anno(), [af_assoc_exact(af_pattern())]}.
此類型的連結

af_map_type()

檢視原始碼 (未匯出)
-type af_map_type() :: {type, anno(), map, any} | {type, anno(), map, [af_assoc_type()]}.
此類型的連結

af_map_update(T)

檢視原始碼 (未匯出)
-type af_map_update(T) :: {map, anno(), T, [af_assoc(T)]}.
-type af_match(T) :: {match, anno(), af_pattern(), T}.
-type af_maybe() :: {'maybe', anno(), af_body()}.
此類型的連結

af_maybe_else()

檢視原始碼 (未匯出)
-type af_maybe_else() :: {'maybe', anno(), af_body(), {'else', anno(), af_clause_seq()}}.
此類型的連結

af_maybe_match()

檢視原始碼 (未匯出)
-type af_maybe_match() :: {maybe_match, anno(), af_pattern(), abstract_expr()}.
-type af_module() :: {attribute, anno(), module, module()}.
此類型的連結

af_named_fun()

檢視原始碼 (未匯出)
-type af_named_fun() :: {named_fun, anno(), fun_name(), af_clause_seq()}.
-type af_nil() :: {nil, anno()}.
此類型的連結

af_pattern()

檢視原始碼 (未匯出)
此類型的連結

af_predefined_type()

檢視原始碼 (未匯出)
-type af_predefined_type() :: {type, anno(), type_name(), [abstract_type()]}.
此類型的連結

af_qualifier()

檢視原始碼 (未匯出)
-type af_qualifier() :: af_generator() | af_filter().
此類型的連結

af_qualifier_seq()

檢視原始碼 (未匯出)
-type af_qualifier_seq() :: [af_qualifier(), ...].
此類型的連結

af_receive()

檢視原始碼 (未匯出)
-type af_receive() ::
          {'receive', anno(), af_clause_seq()} |
          {'receive', anno(), af_clause_seq(), abstract_expr(), af_body()}.
此類型的連結

af_record_creation(T)

檢視原始碼 (未匯出)
-type af_record_creation(T) :: {record, anno(), record_name(), [af_record_field(T)]}.
此類型的連結

af_record_decl()

檢視原始碼 (未匯出)
-type af_record_decl() :: {attribute, anno(), record, {record_name(), [af_field_decl()]}}.
此類型的連結

af_record_field(T)

檢視原始碼 (未匯出)
-type af_record_field(T) :: {record_field, anno(), af_field_name(), T}.
此類型的連結

af_record_field_access(T)

檢視原始碼 (未匯出)
-type af_record_field_access(T) :: {record_field, anno(), T, record_name(), af_field_name()}.
此類型的連結

af_record_field_type()

檢視原始碼 (未匯出)
-type af_record_field_type() :: {type, anno(), field_type, [(Name :: af_atom()) | abstract_type()]}.
此類型的連結

af_record_index()

檢視原始碼 (未匯出)
-type af_record_index() :: {record_index, anno(), record_name(), af_field_name()}.
此類型的連結

af_record_type()

檢視原始碼 (未匯出)
-type af_record_type() :: {type, anno(), record, [(Name :: af_atom()) | af_record_field_type()]}.
此類型的連結

af_record_update(T)

檢視原始碼 (未匯出)
-type af_record_update(T) :: {record, anno(), abstract_expr(), record_name(), [af_record_field(T)]}.
此類型的連結

af_remote_call()

檢視原始碼 (未匯出)
-type af_remote_call() :: {call, anno(), af_remote_function(), af_args()}.
此類型的連結

af_remote_fun()

檢視原始碼 (未匯出)
-type af_remote_fun() ::
          {'fun', anno(), {function, module(), function_name(), arity()}} |
          {'fun',
           anno(),
           {function,
            af_atom() | af_variable(),
            af_atom() | af_variable(),
            af_integer() | af_variable()}}.
-type af_remote_function() :: {remote, anno(), abstract_expr(), abstract_expr()}.

遠端函數呼叫的抽象表示。

此類型的連結

af_remote_guard_call()

檢視原始碼 (未匯出)
-type af_remote_guard_call() ::
          {call, anno(), {remote, anno(), af_lit_atom(erlang), af_atom()}, [af_guard_test()]}.
此類型的連結

af_remote_type()

檢視原始碼 (未匯出)
-type af_remote_type() ::
          {remote_type, anno(), [(Module :: af_atom()) | (TypeName :: af_atom()) | [abstract_type()]]}.
此類型的連結

af_singleton_integer_type()

檢視原始碼 (未匯出)
-type af_string() :: {string, anno(), string()}.
此類型的連結

af_ta_list()

檢視原始碼 (未匯出)
-type af_ta_list() :: [{type_name(), arity()}].
此類型的連結

af_template()

檢視原始碼 (未匯出)
-type af_template() :: abstract_expr().
-type af_try() :: {'try', anno(), af_body(), af_clause_seq() | [], af_clause_seq() | [], af_body() | []}.
-type af_tuple(T) :: {tuple, anno(), [T]}.
此類型的連結

af_tuple_type()

檢視原始碼 (未匯出)
-type af_tuple_type() :: {type, anno(), tuple, any} | {type, anno(), tuple, [abstract_type()]}.
此類型的連結

af_type_decl()

檢視原始碼 (未匯出)
-type af_type_decl() ::
          {attribute, anno(), type_attr(), {type_name(), abstract_type(), [af_variable()]}}.
此類型的連結

af_type_union()

檢視原始碼 (未匯出)
-type af_type_union() :: {type, anno(), union, [abstract_type(), ...]}.
此類型的連結

af_type_variable()

檢視原始碼 (未匯出)
-type af_type_variable() :: {var, anno(), atom()}.
此類型的連結

af_typed_field()

檢視原始碼 (未匯出)
-type af_typed_field() :: {typed_record_field, af_field(), abstract_type()}.
此類型的連結

af_unary_op(T)

檢視原始碼 (未匯出)
-type af_unary_op(T) :: {op, anno(), unary_op(), T}.
此類型的連結

af_user_defined_type()

檢視原始碼 (未匯出)
-type af_user_defined_type() :: {user_type, anno(), type_name(), [abstract_type()]}.
此類型的連結

af_variable()

檢視原始碼 (未匯出)
-type af_variable() :: {var, anno(), atom()}.
此類型的連結

af_wild_attribute()

檢視原始碼 (未匯出)
-type af_wild_attribute() :: {attribute, anno(), atom(), any()}.
-type anno() :: erl_anno:anno().
-type behaviour() :: atom().
-type binary_op() ::
          '/' | '*' | 'div' | 'rem' | 'band' | 'and' | '+' | '-' | 'bor' | 'bxor' | 'bsl' | 'bsr' |
          'or' | 'xor' | '++' | '--' | '==' | '/=' | '=<' | '<' | '>=' | '>' | '=:=' | '=/=' | '!'.
此類型的連結

encoding_func()

檢視原始碼 (未匯出)
-type encoding_func() :: fun((non_neg_integer()) -> boolean()).
此類型的連結

endianness()

檢視原始碼 (未匯出)
-type endianness() :: big | little | native.
此類型的連結

erl_parse_tree()

檢視原始碼 (未匯出)
-type erl_parse_tree() :: abstract_clause() | abstract_expr() | abstract_form() | abstract_type().
此類型的連結

error_description()

檢視原始碼 (未匯出)
-type error_description() :: term().
-type error_info() :: {erl_anno:location(), module(), error_description()}.
-type form_info() ::
          {eof, erl_anno:location()} |
          {error, erl_scan:error_info() | error_info()} |
          {warning, erl_scan:error_info() | error_info()}.

元組 {error, error_info()}{warning, error_info()},表示語法不正確的 form 和警告,以及 {eof, line()},表示在解析完整 form 之前遇到串流結尾。

-type fun_name() :: atom().
此類型的連結

function_name()

檢視原始碼 (未匯出)
-type function_name() :: atom().
此類型的連結

record_name()

檢視原始碼 (未匯出)
-type record_name() :: atom().
此類型的連結

signedness()

檢視原始碼 (未匯出)
-type signedness() :: signed | unsigned.
-type spec_attr() :: callback | spec.
-type token() :: erl_scan:token().
-type type() :: integer | float | binary | bytes | bitstring | bits | utf8 | utf16 | utf32.
-type type_attr() :: opaque | type.
-type type_name() :: atom().
此類型的連結

type_specifier()

檢視原始碼 (未匯出)
-type type_specifier() :: type() | signedness() | endianness() | unit().
此類型的連結

type_specifier_list()

檢視原始碼 (未匯出)
-type type_specifier_list() :: default | [type_specifier(), ...].
-type unary_op() :: '+' | '-' | 'bnot' | 'not'.
-type unit() :: {unit, 1..256}.

函式

-spec abstract(Data) -> AbsTerm when Data :: term(), AbsTerm :: abstract_expr().

將 Erlang 資料結構 Data 轉換為 AbsTerm 類型的抽象形式。此函式是 normalise/1 的反函數。

erl_parse:abstract(T) 等同於 erl_parse:abstract(T, 0)

連結到此函式

abstract(Data, Options)

檢視原始碼 (自 OTP R16B01 開始)
-spec abstract(Data, Options) -> AbsTerm
                  when
                      Data :: term(),
                      Options :: Location | [Option],
                      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().

將 Erlang 資料結構 Data 轉換為 AbsTerm 類型的抽象形式。

AbsTerm 的每個節點都被賦予一個註解,請參閱 erl_anno。註解包含選項 location 或選項 line 所給定的位置。選項 location 會覆蓋選項 line。如果既未給定選項 location 也未給定選項 line,則使用 0 作為位置。

選項 Encoding 用於選擇哪些整數列表應被視為字串。預設是使用函式 epp:default_encoding/0 回傳的編碼。值 none 表示不將任何整數列表視為字串。encoding_func() 一次使用列表中的一個整數來呼叫;如果它對每個整數都回傳 true,則該列表被視為字串。

連結到此函式

anno_from_term(Term)

檢視原始碼 (自 OTP 18.0 開始)
-spec anno_from_term(Term) -> erl_parse_tree() | form_info() when Term :: term().

假設 Term 是一個與 erl_parse 樹具有相同結構的項,但其項(例如 T)是 erl_parse 樹具有註釋集合的地方。

回傳一個 erl_parse 樹,其中每個詞彙 T 都被 erl_anno:from_term(T) 回傳的值取代。詞彙 Term 會以深度優先、由左至右的方式遍歷。

連結到此函式

anno_to_term(Abstr)

檢視原始碼 (自 OTP 18.0 開始)
-spec anno_to_term(Abstr) -> term() when Abstr :: erl_parse_tree() | form_info().

返回一個項,其中 erl_parseAbstr 的節點的每個註釋集合 Anno 都被 erl_anno:to_term(Anno) 返回的項取代。erl_parse 樹是以深度優先、從左到右的方式遍歷。

連結到此函式

fold_anno(Fun, Acc0, Abstr)

檢視原始碼 (自 OTP 18.0 開始)
-spec fold_anno(Fun, Acc0, Abstr) -> Acc1
                   when
                       Fun :: fun((Anno, AccIn) -> AccOut),
                       Anno :: erl_anno:anno(),
                       Acc0 :: term(),
                       Acc1 :: term(),
                       AccIn :: term(),
                       AccOut :: term(),
                       Abstr :: erl_parse_tree() | form_info().

透過在 erl_parseAbstr 的每個註釋集合上套用 Fun 來更新累加器。

第一次呼叫 Fun 時會以 AccIn 作為引數,回傳的累加器 AccOut 會傳遞給下一次呼叫,依此類推。回傳累加器的最終值。erl_parse 樹會以深度優先、由左至右的方式遍歷。

-spec format_error(any()) -> [char() | list()].

使用 ErrorDescriptor 並返回描述錯誤的字串。

當處理 ErrorInfo 結構時(請參閱 錯誤資訊 章節),通常會隱含地呼叫此函式。

連結到此函式

map_anno(Fun, Abstr)

檢視原始碼 (自 OTP 18.0 開始)
-spec map_anno(Fun, Abstr) -> NewAbstr
                  when
                      Fun :: fun((Anno) -> NewAnno),
                      Anno :: erl_anno:anno(),
                      NewAnno :: erl_anno:anno(),
                      Abstr :: erl_parse_tree() | form_info(),
                      NewAbstr :: erl_parse_tree() | form_info().

透過在 erl_parse 樹的節點的每個註釋集合上套用 Fun 來修改 erl_parseAbstrerl_parse 樹是以深度優先、從左到右的方式遍歷。

連結到此函式

mapfold_anno(Fun, Acc0, Abstr)

檢視原始碼 (自 OTP 18.0 開始)
-spec mapfold_anno(Fun, Acc0, Abstr) -> {NewAbstr, Acc1}
                      when
                          Fun :: fun((Anno, AccIn) -> {NewAnno, AccOut}),
                          Anno :: erl_anno:anno(),
                          NewAnno :: erl_anno:anno(),
                          Acc0 :: term(),
                          Acc1 :: term(),
                          AccIn :: term(),
                          AccOut :: term(),
                          Abstr :: erl_parse_tree() | form_info(),
                          NewAbstr :: erl_parse_tree() | form_info().

透過在 erl_parse 樹的節點的每個註釋集合上套用 Fun 來修改 erl_parseAbstr,同時更新累加器。

第一次呼叫 Fun 時會以 AccIn 作為第二個引數,回傳的累加器 AccOut 會傳遞給下一次呼叫,依此類推。回傳修改後的 erl_parse 樹和累加器的最終值。erl_parse 樹會以深度優先、由左至右的方式遍歷。

連結到此函式

new_anno(Term)

檢視原始碼 (自 OTP 18.0 開始)
-spec new_anno(Term) -> Abstr when Term :: term(), Abstr :: erl_parse_tree() | form_info().

假設 Term 是一個與 erl_parse 樹具有相同結構的項,但在 erl_parse 樹具有註釋集合的地方,具有位置

回傳一個 erl_parse 樹,其中每個位置 L 都被 erl_anno:new(L) 回傳的值取代。詞彙 Term 會以深度優先、由左至右的方式遍歷。

-spec normalise(AbsTerm) -> Data when AbsTerm :: abstract_expr(), Data :: term().

將項的抽象形式 AbsTerm 轉換為傳統的 Erlang 資料結構(即項本身)。此函式是 abstract/1 的反函數。

-spec parse_exprs(Tokens) -> {ok, ExprList} | {error, ErrorInfo}
                     when Tokens :: [token()], ExprList :: [abstract_expr()], ErrorInfo :: error_info().

解析 Tokens,就好像它是一個表達式列表一樣。

回傳以下其中一個

  • {ok, ExprList} - 解析成功。ExprList 是已解析表示式的抽象形式列表。

  • {error, ErrorInfo} - 發生錯誤。

-spec parse_form(Tokens) -> {ok, AbsForm} | {error, ErrorInfo}
                    when Tokens :: [token()], AbsForm :: abstract_form(), ErrorInfo :: error_info().

解析 Tokens,就好像它是一個 form 一樣。

回傳以下其中一個

  • {ok, AbsForm} - 解析成功。AbsForm 是已解析形式的抽象形式。

  • {error, ErrorInfo} - 發生錯誤。

-spec parse_term(Tokens) -> {ok, Term} | {error, ErrorInfo}
                    when Tokens :: [token()], Term :: term(), ErrorInfo :: error_info().

解析 Tokens,就好像它是一個項一樣。

回傳以下其中一個

  • {ok, Term} - 解析成功。Term 是對應於符記列表的 Erlang 詞彙。

  • {error, ErrorInfo} - 發生錯誤。

-spec tokens(AbsTerm) -> Tokens when AbsTerm :: abstract_expr(), Tokens :: [token()].

等同於 tokens(AbsTerm, [])

連結到此函式

tokens(AbsTerm, MoreTokens)

檢視原始碼
-spec tokens(AbsTerm, MoreTokens) -> Tokens
                when AbsTerm :: abstract_expr(), MoreTokens :: [token()], Tokens :: [token()].

產生一個表示表達式抽象形式 AbsTerm 的詞法單元列表。您可以選擇性地附加 MoreTokens