Skip to content

Instantly share code, notes, and snippets.

@02JanDal
Last active August 29, 2015 14:26
Show Gist options
  • Save 02JanDal/5919455c2d48f2415b16 to your computer and use it in GitHub Desktop.
Save 02JanDal/5919455c2d48f2415b16 to your computer and use it in GitHub Desktop.
Project Argonauts - Format

Project Argonauts - Format

This file contains thoughts, ideas and hopefully a format for Project Argonauts.

  • It should wrap around existing data as much as possible

Contents

  • Strictly declarative; nothing that "runs"
  • Type system with simple templates
    • Instantiation is done by the argonauts compiler before generating code
  • Comments
  • C-like syntax
    • // ... and /* ... */ for comments
    • Statements end with ;
    • Blocks with { and }
  • Built-in types
    • Need to be supported by all languages
    • 8/16/32/64bit signed/unsigned integers
    • Double, String, Boolean, List<Type>, Map<Key, Value>, Binary?
    • Value: can be anything
  • Custom definable types
    • Enum: Contains a set of entries
    • Struct: Contains a set of members (name -> type)
    • Variant: Can be different things
    • Aliases
  • Some way to describe extra data (for both structs, enums, members, aliases, enum entries etc. etc.)
    • Examples:
      • Documentation data (human readable name, description, examples)
      • Validation data (constraints)
      • Extra layout information (indexes, other information that allows optimizations)
    • Java-style annotations? (@Annotation(...args...)
    • Doxygen-style comments for documentation stuff?
    • Something else?

Enum

// unless overriden, places using the OrganizationType type will have Commercial as the default
@Default(OrganizationType::Commercial)
enum OrganizationType<UInt8> {
	// the numbers are for tighter packing
	@Doc(title="Commercial Organization", description="Says that this is a **commercial** organization")
	Commercial = 0;
	Voluntary = 1;
	Governmental = 3;
}

Struct

struct Person {
	@Validate.MinLength(3)
	/* attribute name comes before type (easier to read) */
	name String;
	salary UInt32;
	@Validate.Pattern(/((Senior|Junior) .*)|(Chief [^ ]* Officer)/)
	title String;
}
struct HelicopterOwner {
	model String;
}
// a Manager is BOTH a person and a helicopter owner
struct Manager : Person, HelicopterOwner {
	/* each string needs to be at least 3 characters */
	@Validate.Value.MinLength(3)
	subordinates List<String>;
}

Variant

// an Employee is EITHER a person or a manager
@TypeColumn("type")
variant Employee : Person, Manager;

Alias

alias Department : Map<String, List<Employee>>;

Binding it together

@Doc(description="Describes an organization")
struct Organization {
	type OrganizationType;
	@Validate.Value.MinSize(1)
	departments Map<String, List<Employee>>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment