compiler library

This file allows you to generate Dart source code files for PackMe data protocol using JSON manifest files.

Usage: dart compiler.dart

JSON manifest file represents a set of nodes representing different entities declarations: enumerations, objects, messages and requests. In your server code you mostly listen for requests from client and reply with responses. However, it totally depends on your architecture: server may as well send messages to inform clint of some data changes or send requests and expect clients to send back responses with corresponding data.

Enumeration declaration is represented with an array of strings. Object declaration is just an object. Message or request declarations consist of array of 1 or 2 objects respectively. In case of request the second object represents response declaration. Here's an example of JSON manifest file:

[ "some_enum": "one", "two", "three" , "some_object": { "name": "string", "volume": "double", "type": "@some_enum" }, "some_message": [ { "update_timestamp": "uint64", "update_coordinates": "double" } ], "some_request": [ { "search_query": "string", "type_filter": "@some_enum" }, { "search_results": "@some_object" } ] ]

Nested object in command request or response will be represented with new class named like SomeCommandResponse<object_name>. For example compiling next manifest:

"get_posts": [
	{
		"from": "datetime",
		"amount": "uint16"
	},
	{
		"posts": [{
			"id": "binary12",
			"author": "string",
				"created: "datetime",
				"title": "string",
				"contents": "string"
		}],
		"stats": {
			"loaded": "uint16",
			"remaining": "uint32",
			"total": "uint32",
		},
		"?error": "string"
	}
]

will result, for instance, in creating class GetPostsResponsePost (note that it has a singular form "Post", not "Posts" - that is because "posts" is an array of nested object) which will contain four fields: Uint8List

Here's the short list of supported features (see more details in README.md): - prefix "?" in field declaration means it is optional (null by default); - enumeration declaration: "color": "black", "white", "yellow"; - object declaration: "person": { "name": "string", "age": "uint8" }; - enumeration/object reference (filed of type enum/object declared earlier): "persons": "@person"; - referencing to entity from another file: "persons": "@protocol_types:person"; - object inheritance in object declaration: "animal": { "legs": "uint8" }, "cat@animal": { "fur": "bool" }.

Constants

GREEN → const String
RED → const String
RESET → const String
YELLOW → const String

Functions

formatCode(List<String> lines) List<String>
Auto indents.
isReserved(String name) bool
Check if name is reserved by Dart language.
main(List<String> args) → void
process(String srcPath, String outPath, List<String> filenames, bool isTest) → void
toSingular(String plural) String
Return singular form of plural.
validName(String input, {bool firstCapital = false}) String
Converts lower case names with underscore to UpperCamelCase (for classes) or lowerCamelCase (for class fields).