asdlGen Reference Manual : Input Syntax : Type Definitions : Attributes
Previous: Type Qualifiers
Next: View Syntax

3.3.6. Attributes

All sum types may optionally be followed by a set of attributes. Attributes provide notation for fields common to all the constructors in the sum type.

module M {
  pos = (string file, int linenum, int charpos)
  sexpr = Int(int)
	| String(string)
	| Symbol(identifier)
	| Cons(sexpr, sexpr)
	| Nil
        attribute(pos p)
}
adds a field of type pos with label p to all the constructors in sexpr. Attribute fields are treated specially when translated. For example in C code the attribute field is hoisted out of the union and placed in the outer struct. Object oriented languages find attribute fields declared in the abstract base class.


asdlGen Reference Manual : Input Syntax : Type Definitions : Attributes
Previous: Type Qualifiers
Next: View Syntax