Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Simplified CQL Syntax #168

Description

@RaoulFoaleng

CQL current language syntax is generally not common to other popular languages used for mobile development: Swift, Kotlin, TypeScript, etc
We’d like to integrate into the CQL language a set of common syntax features that people are familiar with. In the goal of making the language more common and easy for people to understand it quickly and use it efficiently.

Style: Stop using SHOUT CASE

CREATE PROCEDURE <name>(

This is a minor stylistic issue but something we could lint for.

create procedure <name>(

Change “create procedure” to “function”

CREATE PROCEDURE <name>(

Use a more modern style

function <name>(

Allow “private” keyword on functions

@attribute(cql:private)
CREATE PROCEDURE <name>

Use language primitives more similar to class-based languages.

private function <name>

Updated type annotations

CREATE PROCEDURE tester(
  thread_pk_ LONG INT NOT NULL,
  contact_pk_ LONG INT
)

Use more modern style annotations that match an existing popular language.

CREATE PROCEDURE test_function(
  thread_pk_: long,
  contact_pk_: long?

Begin/End → {}

CREATE PROCEDURE tester()
BEGIN
  ...
END;

Use curly braces brackets.

CREATE PROCEDURE tester() {
  ...
}
function tester()
{
  ...
}

Allow Trailing Commas

CREATE PROCEDURE tester(
  thread_pk_ LONG INT NOT NULL,
  contact_pk_ LONG INT
)

Allowing trailing commas is a small change but it allows for more consistency in typing and produces cleaner diffs because adding a parameter does not require editing the comma above.

CREATE PROCEDURE tester(
  thread_pk_ LONG INT NOT NULL,
  contact_pk_ LONG INT,
)

Remove “Call”

CALL subfunction(a, b, c);

Using CALL is non-standard compared to other languages. Instead just allow functions to be called directly.

subfunction(a, b, c);

Get rid of “SET” and “:=”

LET count := 5;
SET count := count + 1;

These are also not similar to how modern languages work.

let count = 5;
count += 1;

Support Interpolation Syntax

SELECT a
FROM foo
WHERE bar = bar_;

The fact that we insert variables directly into SQL does not require underscores, but it necessitates it to make the code readable. We should consider some other way of denoting variables inside of SQL, perhaps something that matches how modern languages do string interpolation.

SELECT a
FROM foo
WHERE bar = ${bar};

Example:

CQL:

@attribute(cql:private)
CREATE PROCEDURE tester (
 thread_pk_ LONG INT NOT NULL @sensitive,
 contact_pk_ LONG INT
)
BEGIN
 LET count := 5;
 SET count := count + 1;

 CALL subfunction(count);

 SELECT a
   FROM foo
   WHERE bar = bar_;
END;

Simplified CQL:

private function tester(
  thread_pk_: long @sensitive,
  contact_pk_: long?,
) 
{
  let count = 5;
  count += 1;
  
  subfunction(count);

  SELECT a
    FROM foo
    WHERE bar = ${bar_};
}

Both codes are semantically the same and produce the exact same output except that the latter is using commonly known syntax features (=, ?, +=, etc) that are already used in a bunch of languages which make it easy for developers to understand CQL language.
To support Simplified CQL syntax we don’t really need to make deeper changes in the CQL compiler. Just adding new grammar rules and a new AST transform step before semantic analysis step (to transform the AST of the simplified CQL code to existing CQL code) are enough to achieve this.

cc @ricomariani , @toddkrabach

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions