Skip to content

kool814/GLS

 
 

Repository files navigation

GLS - General Language Syntax

Build Status NPM version

A unified syntax that compiles into a number of OOP languages. Try it at aka.ms/gls-demo.

Usage

GLS can be used as a command-line app or via import/require.

CLI

To convert file.gls to file.py:

npm install gls-cli --global

gls --language Python file.gls

See gls-cli.

Code

npm install general-language-syntax

const Gls = require("general-language-syntax").Gls;

const gls = new Gls();
gls.setLanguage("CSharp");

// System.Console.WriteLine("Hello world!");
console.log(gls.convert([`print : ("Hello world!")`]));

Theory

Most object-oriented programming languages today are "pretty much" the same. Declaring variables, PEMDAS operations, calling functions, and so on rarely change; the base concept of a compiled or scripting language with managed memory is very common.

GLS provides a common syntax to describe programming functionality in these common managed languages. .gls files can be compiled into any of the supported languages, and will work approximately the same in all of them.

Syntax

Each line in GLS consists of a function, a colon, and any number of arguments, all separated by spaces.

print : "GLS!"
  • Function: print
  • Argument: "GLS!"

print : GLS will compile to System.Console.WriteLine("GLS!"); in C#, console.log("GLS!"); in TypeScript, and so on.

Parenthesis

You can keep spaces inside your arguments by wrapping characters in parenthesis. This tells the compiler to treat the space as part of the argument instead of a separator.

print : ("Hello world!")
  • Function: print
  • Argument: "Hello world!"

Recursion

To pipe the output of one command into another, wrap the inner command with {} brackets.

print : { operation : 1 plus 2 }

Tidbits

  • Each GLS command is independent - it doesn't know or care about any preceding or following commands.

Status

GLS is halfway between 0.3 and 0.4.

Deliverable Version Description
C++ Compiler 0.1 Command-line GLS prototype, written in C++.
TypeScript Compiler draft 0.2 GLS compiler as a website, written in TypeScript.
TypeScript Compiler + C# Output 0.3 GLS compiler re-written in TypeScript, with correct TypeScript and C# output.
Dogfood Feature Complete 0.4 All features expected to be required for dogfooding implemented. Java, JavaScript, Python, and Ruby support.
Dogfood 0.5 Compiler written in GLS code, working in C#, Java, JavaScript, Ruby, Python, and TypeScript.
Powershell, PHP, Objective-C, Misc. 0.6 Dogfood or reject those languages and other possibilities.
Language Specification Finalized 0.7 Finalized language spec & cleaned internals of code.
General Release 1.0 Public announcement, glory to everyone.

Intentionally Missing Items

No language is perfect. The following are some seemingly obvious omissions in GLS that are due to languages not supporting them:

Feature C# Java Python Ruby (Java|Type)Script
`async`/`await`! Missing Missing
Default Member Variable Values Missing
Do/While Loops Missing
Enums Without Values Missing
Multiline Lambdas Missing
Optional Parameters Missing
Overloaded Functions Missing Missing Missing
String.Replace Abnormal
Switch Statements Missing

This list will grow as features are requested.

Intentionally Unsupported Languages

Not all languages work similarly to the supported ones. These will likely never receive GLS support, for the following common reasons (among others):

Language Manual Pointers Unusual Classes
C
C++ ✓ (#190)
Go
Rust

This list will grow as languages are requested.

Development

GLS uses Gulp to automate building, which requires Node.js.

To build from scratch, install Node.js and run the following commands:

npm install -g gulp
npm install
gulp

To build, run gulp. You can build+lint the souce without running tests using gulp src, or just build+lint+run tests using gulp test. The full list of tasks is in gulpfile.js.

Alternately, use tsc to build source files under /src to /lib, and tsc -w to build upon file changes.

Tests

Integration and end-to-end tests are done using BDD. Folders under /test/integration and /test/end-to-end will contain a .gls file with GLS source code along with text files of the expected output in supported languages. These are verified during gulp test.

You can run specific tests using their gulp task (gulp test:integration or gulp test:end-to-end). Specify --command(s) to only run tests within groups that case-insensitive minimatch them (e.g. gulp test:end-to-end --command *array* *list*).

About

A unified syntax that compiles into your favorite OOP languages.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 91.0%
  • JavaScript 2.7%
  • Java 1.9%
  • C# 1.6%
  • Python 1.3%
  • Ruby 1.3%
  • Smalltalk 0.2%