Lua.AST.Meta (Lua v1.0.0-rc.1)
View SourcePosition tracking metadata for AST nodes.
Every AST node includes a meta field containing position information
for error reporting, source maps, and debugging.
Comments can be attached to AST nodes via the metadata field:
:leading_comments- Comments before the node:trailing_comment- Inline comment after the node on the same line
Summary
Functions
Adds a leading comment to a Meta struct.
Adds metadata to an existing Meta struct.
Gets leading comments from a Meta struct.
Gets trailing comment from a Meta struct.
Merges two Meta structs, taking the earliest start and latest end.
Creates a new Meta struct with start and end positions.
Sets the trailing comment for a Meta struct.
Types
Functions
Adds a leading comment to a Meta struct.
Leading comments appear before the AST node.
Adds metadata to an existing Meta struct.
Gets leading comments from a Meta struct.
Gets trailing comment from a Meta struct.
Merges two Meta structs, taking the earliest start and latest end.
Useful when combining multiple nodes into a single parent node.
Examples
iex> meta1 = Lua.AST.Meta.new(%{line: 1, column: 1, byte_offset: 0}, %{line: 1, column: 5, byte_offset: 4})
iex> meta2 = Lua.AST.Meta.new(%{line: 1, column: 7, byte_offset: 6}, %{line: 1, column: 10, byte_offset: 9})
iex> Lua.AST.Meta.merge(meta1, meta2)
%Lua.AST.Meta{
start: %{line: 1, column: 1, byte_offset: 0},
end: %{line: 1, column: 10, byte_offset: 9},
metadata: %{}
}
Creates a new Meta struct with start and end positions.
Examples
iex> Lua.AST.Meta.new(
...> %{line: 1, column: 1, byte_offset: 0},
...> %{line: 1, column: 5, byte_offset: 4}
...> )
%Lua.AST.Meta{
start: %{line: 1, column: 1, byte_offset: 0},
end: %{line: 1, column: 5, byte_offset: 4},
metadata: %{}
}
Sets the trailing comment for a Meta struct.
A trailing comment appears on the same line as the AST node. Only one trailing comment is allowed per node.