pio-rs
pio-rs copied to clipboard
Unexpected token '\n' when using global define directives
According to the rp2040 datasheet, .define
directives should be allowed before the first program, and if they occur there are global to all programs in the file. There seems to be a bug when using pio_file!
, where if you have a global define such as:
.define foo 0
.program bar
...
.program baz
...
And try to do
let program = pio_file!("barbaz.pio", select_program("bar"));
It errors with "unexpected token \n" at the end of the first line. However, if you instead place .define foo 0
and .program bar
on one line, it works, and the define is global. PIOASM has the opposite behavior, where having both on one line results in "unexpected .program", and having them on different lines works as expected.
if anyone wants to fix this before i find the motivation to get around to it, the problem is here: https://github.com/rp-rs/pio-rs/blob/0a6d22f083633b0ee8cd520714d917bb68e0c359/pio-parser/src/pio.lalrpop#L35
each DefineDirective
should have a NEWLINE+
after it.