google / google/emboss

No way to place long boolean expressions on separate lines

Open
#140 1 comment 3 reactions 0 assignees View on GitHub
enhancement language feature
Dominant language
Python
Stars
92
Forks
30
PR merge metrics
No merged PRs in 30d

Description

Suppose I have the following emboss definitions, along with a very long boolean expression:
```
enum PacketType:
FOO = 0
BAR = 1
BAZ = 2
ABC = 3
DEF = 4
GHI = 5

struct MyStruct:
0 [+1] PacketType packet_type

if packet_type == PacketType.FOO || packet_type == PacketType.BAR || packet_type == PacketType.BAZ || packet_type == PacketType.ABC|| packet_type == PacketType.DEF || packet_type == PacketType.GHI:
# ...
```

For readability's sake, I'd like to be able to break up the boolean expression into multiple lines, like this:
```
struct MyStruct:
0 [+1] PacketType packet_type

if packet_type == PacketType.FOO ||
packet_type == PacketType.BAR ||
packet_type == PacketType.BAZ ||
packet_type == PacketType.ABC||
packet_type == PacketType.DEF ||
packet_type == PacketType.GHI:
# ...
```

Doing so results in the following error:
```
error: Syntax error
note: Found '\n' ("\n"), expected "$max", CamelWord, "(", SnakeWord, "$max_size_in_bits", "$upper_bound", "$is_statically_sized", "-", ShoutyWord, "$size_in_bytes", "$max_size_in_bytes", BooleanConstant, "$min_size_in_bytes", "$static_size_in_bits", "$present", "+", Number, "$lower_bound", "$next", "$size_in_bits", "$min_size_in_bits".
if packet_type == PacketType.FOO ||
^
```

Placing the `||` as a line prefix doesn't work either:
```
struct MyStruct:
0 [+1] PacketType packet_type
if packet_type == PacketType.FOO
|| packet_type == PacketType.BAR
|| packet_type == PacketType.BAZ
|| packet_type == PacketType.ABC
|| packet_type == PacketType.DEF:
# ...
```

Doing so results in the following error:
```
error: Syntax error
note: Found '\n' ("\n"), expected "-", "?", "&&", "==", "<", "+", ">", "<=", ":", ">=", "*", "||".
if packet_type == PacketType.FOO
^
```

Using a backslash to indicate a continuation of the line on the next also doesn't work:
```
struct MyStruct:
0 [+1] PacketType packet_type
if packet_type == PacketType.FOO || \
packet_type == PacketType.BAR || \
packet_type == PacketType.BAZ || \
packet_type == PacketType.ABC || \
packet_type == PacketType.DEF:
$next [+1] UInt data
```

Doing so results in the following error:
```
error: Unrecognized token
if packet_type == PacketType.FOO || \
^
```

Using a backslash to indicate a continuation of the line along with using the `||` as a line prefix also doesn't work:
```
struct MyStruct:
0 [+1] PacketType packet_type
if packet_type == PacketType.FOO \
|| packet_type == PacketType.BAR \
|| packet_type == PacketType.BAZ \
|| packet_type == PacketType.ABC \
|| packet_type == PacketType.DEF:
$next [+1] UInt data
```

Doing so results in the following error:
```
error: Unrecognized token
if packet_type == PacketType.FOO \
^
```

It seems like there is no way to have multi-line boolean expressions at the moment.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.