//! unit bbb
module bbb
{
/*
a test multi line comment block
*/
information /* A test comment */
{
description := "Module // bbb";
version := "1.00";
copyright := "Copyright (C) 2019";
author := "John Ryland"; // author
checksum := "_"; // perhaps compiler can update this or there is a publish step
// perhaps 2 checksums, one for with comments and one without
}
imports // depends ?
{
xml,
json
}
/*
Rust code:
struct Person {
name: String,
age: u32,
}
GraphQL code/syntax:
type User {
id: ID
name: String
}
// One of the films in the Star Wars Trilogy
enum Episode
{
NEWHOPE, // Released in 1977.
EMPIRE, // Released in 1980.
JEDI // Released in 1983.
}
// A character in the Star Wars Trilogy
interface Character
{
id: String! // The id of the character.
name: String // The name of the character.
friends: [Character] // The friends of the character, or an empty list if they have none.
appearsIn: [Episode] // Which movies they appear in.
}
// A humanoid creature in the Star Wars universe.
type Human implements Character
{
id: String! // The name of the human.
name: String
friends: [Character]
appearsIn: [Episode]
homePlanet: String // The home planet of the human, or null if unknown.
}
// A mechanical creature in the Star Wars universe.
type Droid implements Character
{
id: String! // The id of the droid.
name: String
friends: [Character]
appearsIn: [Episode]
primaryFunction: String // The primary function of the droid.
}
type Query
{
hero(episode: Episode): Character
human(id: String!): Human
droid(id: String!): Droid
}
The above defines a schema
Introspection is being able to query about the schema
It defines the structured layout of the data
Knowing the schema, one can generically query the data
functions can be seen as transformations on the data, pure functions do so without mutating the data
eg:
type Circle { float radius; }
float radius(Circle circle) { return circle.radius; }
float diameter(Circle circle) { return circle.radius * 2; }
functions might also be used to help construct a new object of a given type.
Circle new(float diameter) { return Circle{ diameter * 0.5 }; }
custom property editors
for exposing this schema to a tree view and property pages, it could be
done automatically via introspection to populate the UI.
but things like color or font etc would just be numbers and text in the
property pages. it would be good to associate together with the type
what the associated custom property UI handler should be.
*/
interface // exports ?
{
type minute := int8 ; // struct minute { int8 value; };
struct bar
{
int16 x;
}
struct foo; // forward declared
type blah := int8;
type blah2 := blah;
const flt32 pi := 3.14;
enum blah3
{
g,
gg := 1, // perhaps different types of enum, enums and flags ? flags can | together etc. enums can't. enums auto increment only. flags can be assigned values
ggg
}
// enums must be fully handled
// union ? - in rust they use enum for this and switch on the enum to only allow valid access
// nullable ?
// traits / templates / interfaces ?
// traits -> Equality, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Default, Zero, Debug
// could derived/defaults of these be done in C++ using recursive visitors down to intrinsic types?
struct blah4
{
blah a;
int8 b;
int16 d;
}
struct blah5;
function ff(int8 a, int16 b) => int8;
function makefoo ( ) => foo;
function makeFooFromString ( string input ) => foo;
}
implementation
{
type second := int8 ;
struct bar2
{
int16 x;
}
struct foo2; // forward declared
type blah6 := int8;
type blah7 := blah;
const flt32 pi2 := 3.14;
enum blah8
{
g,
gg := 1,
ggg
}
struct blah9
{
blah a;
int8 b;
int16 d;
}
struct blah10;
function ff2(int8 a, int16 b) => int8
{
int8 var1; // should this be illegal ?
int8 var2 := 1;
int8 var3 := a;
var var4 := a;
//var var5 := blah8::gg;
blah8 var6 := gg;
int8 var7 := ~1 * -2 + !3 + +var1 * 3 * 8 + 4;
}
function makefoo2 ( ) => foo;
function makeFooFromString2 ( string input ) => foo;
}
tests
}