erl_scan(3erl) | Erlang Module Definition | erl_scan(3erl) |
erl_scan - The Erlang token scanner.
This module contains functions for tokenizing (scanning) characters into Erlang tokens.
category() = atom()
error_description() = term()
error_info() =
{erl_anno:location(), module(), error_description()}
option() =
return | return_white_spaces | return_comments | text |
{reserved_word_fun, resword_fun()}
options() = option() | [option()]
symbol() = atom() | float() | integer() | string()
resword_fun() = fun((atom()) -> boolean())
token() =
{category(), Anno :: erl_anno:anno(), symbol()} |
{category(), Anno :: erl_anno:anno()}
tokens() = [token()]
tokens_result() =
{ok, Tokens :: tokens(), EndLocation :: erl_anno:location()} |
{eof, EndLocation :: erl_anno:location()} |
{error,
ErrorInfo :: error_info(),
EndLocation :: erl_anno:location()}
category(Token) -> category()
Types:
Returns the category of Token.
column(Token) -> erl_anno:column() | undefined
Types:
Returns the column of Token's collection of annotations.
end_location(Token) -> erl_anno:location() | undefined
Types:
Returns the end location of the text of Token's collection of annotations. If there is no text, undefined is returned.
format_error(ErrorDescriptor) -> string()
Types:
Uses an ErrorDescriptor and returns a string that describes the error or warning. This function is usually called implicitly when an ErrorInfo structure is processed (see section Error Information).
line(Token) -> erl_anno:line()
Types:
Returns the line of Token's collection of annotations.
location(Token) -> erl_anno:location()
Types:
Returns the location of Token's collection of annotations.
reserved_word(Atom :: atom()) -> boolean()
Returns true if Atom is an Erlang reserved word, otherwise false.
string(String) -> Return
string(String, StartLocation) -> Return
string(String, StartLocation, Options) -> Return
Types:
Takes the list of characters String and tries to scan (tokenize) them. Returns one of the following:
string(String) is equivalent to string(String, 1), and string(String, StartLocation) is equivalent to string(String, StartLocation, []).
StartLocation indicates the initial location when scanning starts. If StartLocation is a line, Anno, EndLocation, and ErrorLocation are lines. If StartLocation is a pair of a line and a column, Anno takes the form of an opaque compound data type, and EndLocation and ErrorLocation are pairs of a line and a column. The token annotations contain information about the column and the line where the token begins, as well as the text of the token (if option text is specified), all of which can be accessed by calling column/1, line/1, location/1, and text/1.
A token is a tuple containing information about syntactic category, the token annotations, and the terminal symbol. For punctuation characters (such as ; and |) and reserved words, the category and the symbol coincide, and the token is represented by a two-tuple. Three-tuples have one of the following forms:
Valid options:
symbol(Token) -> symbol()
Types:
Returns the symbol of Token.
text(Token) -> erl_anno:text() | undefined
Types:
Returns the text of Token's collection of annotations. If there is no text, undefined is returned.
tokens(Continuation, CharSpec, StartLocation) -> Return
tokens(Continuation, CharSpec, StartLocation, Options) -> Return
Types:
char_spec() = string() | eof
return_cont()
This is the re-entrant scanner, which scans characters until either a dot ('.' followed by a white space) or eof is reached. It returns:
The CharSpec eof signals end of file. LeftOverChars then takes the value eof as well.
tokens(Continuation, CharSpec, StartLocation) is equivalent to tokens(Continuation, CharSpec, StartLocation, []).
For a description of the options, see string/3.
ErrorInfo is the standard ErrorInfo structure that is returned from all I/O modules. The format is as follows:
{ErrorLocation, Module, ErrorDescriptor}
A string describing the error is obtained with the following call:
Module:format_error(ErrorDescriptor)
The continuation of the first call to the re-entrant input functions must be []. For a complete description of how the re-entrant input scheme works, see Armstrong, Virding and Williams: 'Concurrent Programming in Erlang', Chapter 13.
stdlib 3.14 | Ericsson AB |