Chapter 03Lesson 03110–150 min

Robot File Syntax, Sections, Tables, Whitespace, and Parsing Rules: Configuration, Design Patterns, and Trade-Offs

Turn parser knowledge into maintainable source conventions: choose formats deliberately, separate grammar from team style, control line complexity, and decide what static validation can and cannot prove.

Grammar vs styleSource formatsContinuationsStatic validationTeam conventions

Learning objectives

  • Choose space-separated or pipe-separated data based on readability and maintenance cost rather than habit.
  • Separate parser-valid formatting from team-enforced style and explain why both layers matter.
  • Decide when compact rows, aligned tables, continuations, comments, or shorter keywords improve readability.
  • Explain the boundary between parsing/static validation and runtime validation.
  • Create a team-ready source convention without depending on paid tooling or pre-release syntax.

Version scope. Decisions in this lesson target stable Robot Framework 7.4.2. The current style guide recommends four-space horizontal separation and a 120-character line length. Pre-release Robot Framework 7.5b1 exists, but no syntax unique to that release is adopted here.

1. Two policy layers: grammar and style

Grammar answers “can Robot interpret this source?” Style answers “can humans and tools maintain it consistently?” Treating style as grammar causes misleading reviews; treating grammar as the only standard allows technically valid but difficult code to accumulate.

Question Grammar layer Style/governance layer
Cell separator At least two spaces, or tab separator, in space format. Prefer four spaces for visible, consistent boundaries.
Indentation Must produce the intended first/next cells and block structure. Use consistent four-space indentation and avoid mixed tabs.
Pipe alignment Pipes define cells when pipe grammar is used. Align when it helps reading; do not optimize for decorative grids.
Line length Parser can accept long logical rows. Current guide recommends about 120 characters; break meaningfully.
Comments Parser can ignore comment rows/sections. Use comments for rationale, not as replacement for durable documentation.

2. Space-separated versus pipe-separated data

Space-separated format is the normal default because Robot files read naturally and diffs stay compact. Pipe-separated rows trade visual noise for explicit cell edges. That can help with dense tabular data or arguments containing many ordinary spaces.

Choose Benefits Costs / cautions
Space-separated Idiomatic, concise, common tooling support, small diffs. Cell boundaries can be hard to see if formatting is inconsistent.
Pipe-separated Cell boundaries are explicit; dense rows can be easier to scan. More punctuation; alignment churn can dominate diffs if treated decoratively.
Mixed in one file Parser supports it. Usually increases cognitive load; reserve for a justified local case.

A good default convention is “space-separated everywhere unless a specific table becomes materially clearer with pipes.” The exception should solve a readability problem, not demonstrate parser flexibility.

3. Compact versus aligned tables

Four spaces are a separator, not a requirement to vertically align every argument across many lines. Over-alignment can create noisy diffs: renaming one long keyword shifts dozens of unrelated cells. Under-formatting, however, makes boundaries hard to review.

*** Test Cases ***
Compact And Stable
    Log    service ready
    Should Be Equal    ${actual}    ${expected}

# Excessive decorative alignment is not required:
# Log                service ready
# Should Be Equal    ${actual}      ${expected}

Prefer consistent separation and locally readable structure. Align when it genuinely reveals a data table; do not make column position part of an unwritten contract.

4. Comments versus documentation

A comment explains source to maintainers and does not become the same kind of suite/test/keyword documentation used by Robot tooling and reports. Documentation is part of the modeled automation artifact; comments are source annotations.

Use Best for Bad substitute
Comment Why a non-obvious implementation choice exists; temporary diagnostic note that is intentionally kept. Public test intent, ownership, or operational contract that should appear in tooling/docs.
Documentation Suite/test/keyword purpose and stable behavioral context. Narrating every obvious line of implementation.
Meaningful keyword/test name Primary executable vocabulary. Long comments compensating for vague names.

5. Continuation lines versus shorter abstractions

A continuation row solves physical line length. It does not solve conceptual complexity. If one keyword call has many legitimate named arguments, continuation can improve readability. If a test contains a long procedural sequence, a better user keyword may express the business step more clearly.

*** Test Cases ***
Readable Long Call
    Validate Deployment Record    service=payments
    ...    environment=staging
    ...    expected_status=ready
    ...    expected_owner=platform-team

Contrast that with splitting one short call across multiple lines merely for symmetry; that adds vertical noise. The decision should make intent easier to inspect in review and failure logs.

6. Static validation versus execution-time validation

Parsing and dry-run provide increasingly broad confidence, but neither is a substitute for controlled execution. The layers are additive:

Confidence increases as validation moves closer to runtime
flowchart TD
A[Text/encoding] --> B[Token + model validation]
B --> C[Import + keyword resolution]
C --> D[Dry-run suite validation]
D --> E[Controlled runtime]
E --> F[External-state assertions]

The public parsing API can prove section/model structure without external side effects. Dry-run can validate imports and keyword availability but normal keyword bodies are not executed. Only a real run can prove that external state, permissions, timing, and assertions behave correctly. Therefore a CI pipeline can use static/dry-run checks for fast feedback while still running the appropriate real suite later.

7. Source-format choices should reflect ownership

The stable framework supports plain-text Robot data, reStructuredText integration, and JSON-based data. That flexibility does not mean a project should use all formats. Human-authored acceptance tests normally benefit from plain .robot and .resource files; generated tools may have different needs.

Need Recommended starting point Reason
Human-authored executable suite .robot Most direct, readable, idiomatic source.
Reusable keywords/variables .resource Makes non-executable reuse explicit.
Documentation document containing executable examples .robot.rst only if genuinely needed Adds documentation-tool complexity.
Tool-generated/interchange model .rbt when the tool ecosystem benefits JSON is not the best default authoring experience for beginners.

8. Tabs, invisible whitespace, and portability

The parser can use tab characters as separators, but mixed tabs and spaces are difficult to see in reviews and editors. A team can therefore prohibit tabs as a style rule even though the grammar accepts them. The same principle applies to trailing spaces and unusual Unicode whitespace: invisible formatting should not carry meaning when a visible convention is available.

Store Robot text as UTF-8 and configure editors to show whitespace during syntax incidents. Do not “fix” an invisible-whitespace suspicion by copying the file through an arbitrary formatter before preserving the original evidence.

9. Parser, editor, formatter, and linter are different controls

Robot Framework core owns parsing and execution. Editors such as RobotCode can provide language intelligence, and later chapters introduce Robocop for style/static-analysis governance. Those tools must not be confused with the language grammar. An editor warning can represent team policy; the parser remains the authority on source acceptance for the pinned Robot version.

This separation also improves CI portability. A repository should be runnable and validateable from the command line even when a developer uses a different editor.

10. Decision table: choose a source convention

For a normal DevOps automation repository, a defensible initial convention is:

Decision Default Exception requires
Cell format Space-separated A concrete readability benefit from pipes.
Cell spacing Four spaces No exception for new code unless generated/tool-owned.
Indentation Four-space levels; no mixed tabs A tool-generated format with documented ownership.
Resource extension .resource Legacy compatibility during a controlled migration.
Long statements Continuation when one logical call is genuinely long Refactor to a smaller keyword if conceptual complexity is the real problem.
Validation Parser/API + dry-run + targeted real execution Risk-based reduction documented explicitly, not accidental omission.

11. Worked scenario: review a “valid but hard to maintain” suite

A pull request contains two-space separators, mixed tabs, a pipe table in the middle of otherwise space-separated tests, 200-character keyword calls, and comments explaining every vague keyword name. Robot accepts the file.

The correct review is not “this syntax is invalid.” Instead: preserve working semantics, standardize visible four-space separators, remove mixed tabs, keep pipe format only where it improves a real table, break genuinely long calls with continuation or better abstractions, and improve names/documentation so comments are not carrying the behavioral contract. Grammar stays stable while maintainability improves.

12. Knowledge check

Why is “Robot parses it” insufficient as a team source standard?

When is pipe format a good choice?

What problem does a continuation line solve?

Can dry-run prove that an HTTP service will respond correctly?

Why can a team ban tabs even though Robot accepts them?

13. Summary and next step

You now have a defensible source policy: stable grammar first, consistent human style second, static/dry-run validation before runtime, and exceptions only when they improve a specific readability or tooling need.

Lesson 4 applies that policy under failure conditions, using first-failure evidence to distinguish malformed headers, wrong cells, broken blocks, continuations, hidden whitespace, imports, keyword resolution, and external-system problems.

Next lesson

Robot File Syntax, Sections, Tables, Whitespace, and Parsing Rules: Diagnostics, Failure Modes, and Production Practices

Continue with Robot File Syntax, Sections, Tables, Whitespace, and Parsing Rules: Diagnostics, Failure Modes, and Production Practices. It builds directly on the state, evidence, and operating assumptions established here, so carry those constraints forward rather than treating the next page as an isolated topic.

Further reading

Keep the academy open

Support free, practical DevOps education.

Every lesson is designed to remain readable in a browser, downloadable from GitHub, and usable without a paid learning platform. Contributions help expand and maintain the curriculum.

Ethereum / ERC-20
0x716c4Ab160C4B66F31a28AE2448BfF68fc3a2ef0 Send only Ethereum/ERC-20 compatible assets to this address.