这是indexloc提供的服务,不要输入任何密码
Skip to content

parses_to! macro: ‘expected item after attributes’ and semicolon error #1107

@Ranrar

Description

@Ranrar

Describe the bug
The pest::parses_to! macro produces a compiler error when used in test files. Specifically, using the macro at module scope triggers error: expected item after attributes, and adding a trailing semicolon after the macro invocation produces error: expected item, found ';'. The macro fails to compile in both forms when used in integration tests, despite being

used according to documentation examples.

To Reproduce
Steps to reproduce the behavior:

  1. Create a Rust test file (e.g., tests/no_semicolon.rs) with the following contents:
use macro_parser::MarcoParser;
use macro_parser::Rule;
use pest::parses_to;

pest::parses_to! {
    parser: MarcoParser,
    input: "[Bookmark: X](./f.md=1)\n",
    rule: Rule::bookmark,
    tokens: [
        bookmark(0, 21, [
            text(11, 12)
        ])
    ]
}
  1. Run cargo test -q --test no_semicolon.

  2. Observe the error:

error: expected item after attributes
  --> tests/no_semicolon.rs:10:1
  1. Alternatively, add a trailing semicolon to the macro invocation:
pest::parses_to! {
    parser: MarcoParser,
    input: "[Bookmark: X](./f.md=1)\n",
    rule: Rule::bookmark,
    tokens: [
        bookmark(0, 21, [
            text(11, 12)
        ])
    ]
};
  1. Run cargo test -q --test with_semicolon.

  2. Observe the errors:

error: expected item, found `;`
error: expected item after attributes

Expected behavior
The pest::parses_to! macro should compile successfully at module scope and generate the expected test items. No compiler errors should occur whether a trailing semicolon is present (the macro should handle both cases gracefully or clearly document that semicolons are forbidden).

Additional context

  • Rust version:
    • rustc 1.89.0 (29483883e 2025-08-04)
    • cargo 1.89.0 (c24e10642 2025-06-23)
    • stable-x86_64-unknown-linux-gnu (default)
  • pest version: [2.8.1]
  • Issue occurs in integration test files (tests/*.rs).
  • Warnings for unused imports are present but unrelated to the compilation error.
  • Removing the trailing semicolon fixes the error, indicating the macro cannot tolerate a semicolon after the invocation.

tests.zip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions