← Documentation Home

Source Files, Continuations, and Comments

LunarBasic combines continued physical lines into logical source lines before parsing. Blank lines and comments are ignored so the parser can focus on real code.

Back to Language Reference


How Source Files Are Read

  • Source is read one physical line at a time.
  • Physical lines joined with _ are parsed as one logical source line.
  • Blank lines and comments are ignored.
  • Error messages include the file name, line number, and column number.

Whitespace

  • Whitespace between tokens is ignored.
  • Blank lines are ignored.

This means you can space code out for readability without changing how it is parsed.

Line Continuation

Place a standalone underscore at the end of a physical line to continue the statement on the next line. At least one whitespace character must appear immediately before the underscore.

total = firstValue + _
    secondValue + _
    thirdValue

DrawText font, _
    x, y, _
    "Hello"
  • Only whitespace may follow the continuation underscore.
  • Multiple consecutive lines can be continued.
  • Indentation on continuation lines is optional.
  • Continuation works in declarations, parameter and argument lists, grouped expressions, array dimensions and indexes, and control-flow conditions.
  • Underscores inside identifiers, strings, or comments do not continue a line.
  • A continuation underscore at the end of the file is a syntax error.
Function AddValues( _
    left As Integer, _
    right As Integer _
) As Integer
    Return ( _
        left + right _
    )
End Function

Apostrophe Comments

An apostrophe starts either a full-line comment or an inline comment.

' full line comment counter = counter + 1 ' inline comment

Anything after the apostrophe on the same line is ignored.

Block Comments

Block comments start with Rem and end with End Rem.

  • The match is case-insensitive.
  • Leading and trailing whitespace are ignored when checking for Rem and End Rem.
  • A line containing only Rem starts the block comment.
  • A line containing only End Rem ends the block comment.
  • Everything inside the block is ignored.
  • If the file ends before End Rem appears, it is a syntax error.
Rem this text is ignored End Rem