Skip to content
This repository has been archived by the owner on Jun 14, 2023. It is now read-only.
/ alakirql Public archive

Domain Specific Programming Language for Astrology

Notifications You must be signed in to change notification settings

prenaissance/alakirql

Repository files navigation

Alakirql - DSL for Astrology

ci workflow publish workflow codecov conventional commits

npm npm

This is a monorepo managed by Turborepo, having the following published packages:

  • @alakir/core
  • @alakir/cli
  • probably other tools to come (bullshit topic is not motivating)

Installing the cli

Install the package globally with npm i -g @alakir/cli or pnpm add -g @alakir/cli and then run alakir --help to see the list of commands.

Running locally

  • Have Node.js 16+ installed.
  • Install pnpm with npm i -g pnpm
  • Install dependencies with pnpm i --frozen-lockfile
  • Run pnpm run build to build all the packages

Running tests

  • pnpm run test or pnpm run test:coverage for coverage

Grammar (Almost BNF)

. - any symbol

Keywords

  • if, else, while, print, define, const

Symbols

  • (, ), {, }, [, ], ;, ,, =, ==, !=, >, <, >=, <=, +, -, *, /, %, :, ., !, &&, ||

Literals

<digit> ::= [0-9]

<alpha> ::= [a-z] | [A-Z]

<alphanumeric> ::= <alpha> | <digit>

  • <BooleanLiteral> ::= true | false
  • <StringLiteral> ::= " (.|[^"])* " | ' (.|[^'])* '
  • <NumberLiteral> ::= (0|([1-9][0-9]*))(.[0-9]+)?
  • <DateLiteral> ::= D <digit>4 - <digit>2 - <digit>2
  • <Identifier> ::= (<alpha>|_|$) (<alphanumeric>|_|$)*
  • <Literal> ::= <BooleanLiteral> | <StringLiteral> | <NumberLiteral> | <DateLiteral> | <Identifier>

Expressions

<binaryOperator> ::= + | - | * | / | % | == | != | > | < | >= | <= | && | ||

  • <ArrayExpression> ::= [ <Expression> (, <Expression>)* ]
  • <ObjectExpression> ::= { <Identifier> : <Expression> (, <Identifier> : <Expression>)* }
  • <CallExpression> ::= <Identifier> ( <Expression> (, <Expression>)* )
  • <AssignmentExpression> ::= <Expression> = <Expression>
  • <BinaryExpression> ::= <Expression> <binaryOperator> <Expression> | <AssignmentExpression>
  • <IndexingExpression> ::= <Expression> [ <Expression> ]
  • <MemberAccessExpression> ::= <Expression> . <Identifier>
  • <Expression> ::= <Literal> | <ArrayExpression> | <ObjectExpression> | <CallExpression> | <BinaryExpression> | <IndexingExpression> | <MemberAccessExpression>

Statements

<declarator> ::= <Identifier> (= <Expression>)?

  • <ExpressionStatement> ::= <Expression> ;
  • <BlockStatement> ::= { <Statement>* }
  • <IfStatement> ::= if ( <Expression> ) <Statement> (else <Statement>)?
  • <WhileStatement> ::= while ( <Expression> ) <Statement>
  • <PrintStatement> ::= print ( <Expression> ) ;
  • <VariableDeclaration> ::= const | declare <declarator> (, <declarator>)* ;
  • <Statement> ::= <ExpressionStatement> | <BlockStatement> | <IfStatement> | <WhileStatement> | <PrintStatement> | <VariableDeclaration>

Program

  • <Program> ::= <Statement>*

Road map

Completed

  • Lexer (Add more keywords and symbols if you want)

  • Parser

    • Basic keywords
    • Declarations & assignments
    • Binary expressions
    • Expressions
    • Function calls
    • Array/Object element accessing
    • Control flow
    • Ast generation
    • Function definitions Ignored for simplicity
  • Cli (some demo scripts are in the parser 'demo' folder)

    • Read from file
    • Repl
    • Lex
    • Parse
    • Interpret
    • Error handling for incomplete parsing
  • Interpreter

    • Assignments and declarations
    • Block scoped variables
    • IO
    • Function calls
    • Predefined functions support
    • Predefined functions
      • lucky(string) gets someone's name's lucky number
      • len(array) used with arrays
      • str(number) converts number to string
      • now() returns current date
      • getMoonPhase(date)
      • getZodiacSign(date)
      • getZodiacEmoji(string)
      • areZodiacSignsCompatible(string, string)
    • Global constants
      • PI number
      • ZODIAC_COLORS object
    • Control flow
    • Loops
    • Array and objects
    • Indexing & property access