Lua.Parser.Comments (Lua v1.0.0-rc.1)
View SourceHelper functions for collecting and attaching comments to AST nodes.
Summary
Functions
Attaches collected comments to an AST node's meta.
Checks if there's a trailing comment on the same line as the given position.
Collects leading comments from a token stream.
Skips any whitespace-like tokens (currently just EOF checks). Comments are not skipped here as they need to be processed.
Types
@type comment() :: Lua.AST.Meta.comment()
@type token() :: Lua.Lexer.token()
Functions
@spec attach_comments(Lua.AST.Meta.t() | nil, [comment()], comment() | nil) :: Lua.AST.Meta.t()
Attaches collected comments to an AST node's meta.
Adds leading comments and optionally a trailing comment.
@spec check_trailing_comment([token()], Lua.AST.Meta.position() | nil) :: {comment() | nil, [token()]}
Checks if there's a trailing comment on the same line as the given position.
Returns {maybe_comment, remaining_tokens}.
Only captures a comment if it's on the same line as the statement.
Collects leading comments from a token stream.
Returns {collected_comments, remaining_tokens}.
Stops collecting when it encounters a non-comment token.
Skips any whitespace-like tokens (currently just EOF checks). Comments are not skipped here as they need to be processed.