allow curly brace on next line also after subroutine and when

This commit is contained in:
Irmen de Jong 2023-06-27 01:29:25 +02:00
parent b0794cf35e
commit eab63ecc6c
3 changed files with 21 additions and 22 deletions

View File

@ -1,6 +1,9 @@
TODO
====
- also allow this?
if variable { txt.print("yes") }
else { txt.print("no") }
- is it possible to allow the curly brace to be on the next line instead of requiring it to follow on the same line?
...

View File

@ -1,28 +1,24 @@
%import textio
%option no_sysinit
%zeropage dontuse
%zeropage basicsafe
main {
uword variable=55555
sub start()
{
ubyte variable=55
when variable
{
33 -> txt.print("33")
}
sub start() {
txt.print("active rambank=")
txt.print_ub(cx16.getrambank())
txt.print("\nvar addr=")
txt.print_uwhex(&variable, true)
txt.print("\nvalue=")
txt.print_uw(variable)
txt.print("\n(rambank 10) variable=")
cx16.rambank(10)
txt.print_uw(variable)
txt.print("\n(rambank 2) variable=")
cx16.rambank(2)
txt.print_uw(variable)
txt.print("\n(rambank 1) variable=")
cx16.rambank(1)
txt.print_uw(variable)
txt.nl()
if variable
{
txt.print("yes")
}
else
{
txt.print("no")
}
}
}

View File

@ -239,7 +239,7 @@ inlineir: '%ir' INLINEASMBLOCK;
inline: 'inline';
subroutine :
'sub' identifier '(' sub_params? ')' sub_return_part? (statement_block EOL)
'sub' identifier '(' sub_params? ')' sub_return_part? EOL? (statement_block EOL)
;
sub_return_part : '->' datatype ;
@ -296,6 +296,6 @@ repeatloop: 'repeat' expression? EOL? (statement | statement_block) ;
unrollloop: 'unroll' integerliteral? EOL? (statement | statement_block) ;
whenstmt: 'when' expression '{' EOL (when_choice | EOL) * '}' EOL? ;
whenstmt: 'when' expression EOL? '{' EOL (when_choice | EOL) * '}' EOL? ;
when_choice: (expression_list | 'else' ) '->' (statement | statement_block ) ;