Lua.Parser.Comments (Lua v1.0.0-rc.2)

View Source

Helper 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

comment()

@type comment() :: Lua.AST.Meta.comment()

token()

@type token() :: Lua.Lexer.token()

Functions

attach_comments(meta, leading_comments, trailing_comment)

@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.

check_trailing_comment(tokens, statement_pos)

@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.

collect_leading_comments(tokens)

@spec collect_leading_comments([token()]) :: {[comment()], [token()]}

Collects leading comments from a token stream.

Returns {collected_comments, remaining_tokens}. Stops collecting when it encounters a non-comment token.

skip_insignificant(tokens)

@spec skip_insignificant([token()]) :: [token()]

Skips any whitespace-like tokens (currently just EOF checks). Comments are not skipped here as they need to be processed.