Fields like lineno would be really beneficial to have in the AST so the compiler can report better error messages. Doing this in rust is a little more complicated since we can't pattern match structs and there isn't really a way to extend a class like one would in Java. We could apply traits to structs/enums but this only allows us to create similar functions not fields. The best way to achieve this is use a combination of enums and structs. An encapsulating struct can provide common fields with a variant field that represents the AST enum that is currently used.
Fields like
lineno
would be really beneficial to have in the AST so the compiler can report better error messages. Doing this in rust is a little more complicated since we can't pattern match structs and there isn't really a way to extend a class like one would in Java. We could apply traits to structs/enums but this only allows us to create similar functions not fields. The best way to achieve this is use a combination of enums and structs. An encapsulating struct can provide common fields with avariant
field that represents the AST enum that is currently used.This is just a simple example that allows us to avoid adding common fields to each enum arm.