diff --git a/README.md b/README.md index e82a5d5..896c69e 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ -# calvin-lang +# encode Personal project to make a C/JS-like programming language diff --git a/apps/parser/deno.jsonc b/apps/parser/deno.jsonc index 5be229d..cc4a4ce 100644 --- a/apps/parser/deno.jsonc +++ b/apps/parser/deno.jsonc @@ -1,5 +1,5 @@ { - "name": "@calvin-lang/parser", + "name": "@encode/parser", "version": "0.1.0", "exports": { diff --git a/apps/parser/main.ts b/apps/parser/main.ts index 6bd10e0..89d4135 100644 --- a/apps/parser/main.ts +++ b/apps/parser/main.ts @@ -1,4 +1,4 @@ -import { CalvinLexer, CalvinParser, CalvinPrinter, Globals } from '@calvin-lang/parser/lib'; +import { EncodeLexer, EncodeParser, Globals, ParenPrinter } from '@encode/parser/lib'; import { parseArgs } from '@std/cli/parse-args'; import { join, toFileUrl } from '@std/path'; @@ -32,11 +32,11 @@ export async function main(): Promise { const inputFile = await Deno.readTextFile(toFileUrl(join(Deno.cwd(), inputFilePath))); - const parser = new CalvinParser(); + const parser = new EncodeParser(); - const printer = new CalvinPrinter(debugColors); + const printer = new ParenPrinter(debugColors); - const lexingResult = CalvinLexer.tokenize(inputFile); + const lexingResult = EncodeLexer.tokenize(inputFile); // "input" is a setter which will reset the parser's state. parser.input = lexingResult.tokens; diff --git a/apps/parser/src/lexer.ts b/apps/parser/src/lexer.ts index c35268e..c6fc219 100644 --- a/apps/parser/src/lexer.ts +++ b/apps/parser/src/lexer.ts @@ -274,4 +274,4 @@ export const allTokens: TokenType[] = [ ERROR, ]; -export const CalvinLexer: Lexer = new Lexer(allTokens); +export const EncodeLexer: Lexer = new Lexer(allTokens); diff --git a/apps/parser/src/parser.ts b/apps/parser/src/parser.ts index 787c42c..faaeec6 100644 --- a/apps/parser/src/parser.ts +++ b/apps/parser/src/parser.ts @@ -1,7 +1,7 @@ import { type CstNode, CstParser, type ParserMethod } from 'chevrotain'; import * as Tokens from './lexer.ts'; -export class CalvinParser extends CstParser { +export class EncodeParser extends CstParser { constructor() { super(Tokens.allTokens); this.performSelfAnalysis(); @@ -184,7 +184,7 @@ export class CalvinParser extends CstParser { private type = this.RULE('type', () => this.CONSUME(Tokens.BASIC_TYPE)); } -export const parser: CalvinParser = new CalvinParser(); +export const parser: EncodeParser = new EncodeParser(); export const BaseCstVisitor: ReturnType = parser.getBaseCstVisitorConstructor(); export const BaseCstVisitorWithDefaults: ReturnType< diff --git a/apps/parser/src/visitors/printers/paren.ts b/apps/parser/src/visitors/printers/paren.ts index 52dd402..74883ea 100644 --- a/apps/parser/src/visitors/printers/paren.ts +++ b/apps/parser/src/visitors/printers/paren.ts @@ -18,7 +18,7 @@ import { BasePrinter } from './printer.ts'; const start = ANSIColor.BrightRed; const range = ANSIColor.BrightWhite - start; -export class CalvinPrinter extends BasePrinter implements ICstNodeVisitor { +export class ParenPrinter extends BasePrinter implements ICstNodeVisitor { constructor(colors: boolean = true, output: Logger | null = console.log) { super(colors, output); } diff --git a/apps/parser/src/visitors/semantics.ts b/apps/parser/src/visitors/semantics.ts index 43baa7a..e79565c 100644 --- a/apps/parser/src/visitors/semantics.ts +++ b/apps/parser/src/visitors/semantics.ts @@ -142,7 +142,7 @@ export class Scope { } } -export class CalvinTypeAnalyzer +export class TypeAnalyzer extends BaseCstVisitor implements ICstNodeVisitor { diff --git a/apps/parser/test/end-to-end/parsing.test.ts b/apps/parser/test/end-to-end/parsing.test.ts index 15ace8d..f1074bb 100644 --- a/apps/parser/test/end-to-end/parsing.test.ts +++ b/apps/parser/test/end-to-end/parsing.test.ts @@ -1,4 +1,4 @@ -import * as TestSubject from '@calvin-lang/parser/lib'; +import * as TestSubject from '@encode/parser/lib'; import { bold, dim, yellow } from '@std/fmt/colors'; import { walk } from '@std/fs'; import { toFileUrl } from '@std/path'; @@ -21,13 +21,13 @@ Deno.test('Loading & parsing', async (t) => { await t.step(file.name, async () => { using _globalSettings = useGlobalSettings({ debugTrees: false }); - const parser = new TestSubject.CalvinParser(); + const parser = new TestSubject.EncodeParser(); const precedenceHandler = new TestSubject.PrecedenceHandler(); - const printer = new TestSubject.CalvinPrinter(); + const printer = new TestSubject.ParenPrinter(); - const typeAnalyzer = new TestSubject.CalvinTypeAnalyzer(); + const typeAnalyzer = new TestSubject.TypeAnalyzer(); const _testCaseOutputs = performParsingTestCase({ code: await Deno.readTextFile(toFileUrl(file.path)), diff --git a/apps/parser/test/integration/comments.test.ts b/apps/parser/test/integration/comments.test.ts index 85f2729..af1dad2 100644 --- a/apps/parser/test/integration/comments.test.ts +++ b/apps/parser/test/integration/comments.test.ts @@ -1,17 +1,17 @@ -import * as TestSubject from '@calvin-lang/parser/lib'; +import * as TestSubject from '@encode/parser/lib'; import { assert, assertEquals } from '@std/assert'; import { performParsingTestCase, useGlobalSettings } from '@/test/utils/mod.ts'; Deno.test('Comment parsing #integration', async (t) => { using _globalSettings = useGlobalSettings({ debugTrees: true }); - const parser = new TestSubject.CalvinParser(); + const parser = new TestSubject.EncodeParser(); const precedenceHandler = new TestSubject.PrecedenceHandler(); const printer = new TestSubject.JSONPrinter(false, null, 0); - const typeAnalyzer = new TestSubject.CalvinTypeAnalyzer(); + const typeAnalyzer = new TestSubject.TypeAnalyzer(); await t.step('line comment', () => { const { parserOutput, afterReorder } = performParsingTestCase({ diff --git a/apps/parser/test/integration/control-flow.test.ts b/apps/parser/test/integration/control-flow.test.ts index a678ff3..9247b13 100644 --- a/apps/parser/test/integration/control-flow.test.ts +++ b/apps/parser/test/integration/control-flow.test.ts @@ -1,17 +1,17 @@ -import * as TestSubject from '@calvin-lang/parser/lib'; +import * as TestSubject from '@encode/parser/lib'; import { assert, assertEquals, assertGreater } from '@std/assert'; import { performParsingTestCase, useGlobalSettings } from '@/test/utils/mod.ts'; Deno.test('Control flow parsing #integration', async (t) => { using _globalSettings = useGlobalSettings({ debugTrees: true }); - const parser = new TestSubject.CalvinParser(); + const parser = new TestSubject.EncodeParser(); const precedenceHandler = new TestSubject.PrecedenceHandler(); - const printer = new TestSubject.CalvinPrinter(); + const printer = new TestSubject.ParenPrinter(); - const typeAnalyzer = new TestSubject.CalvinTypeAnalyzer(); + const typeAnalyzer = new TestSubject.TypeAnalyzer(); await t.step('simple if statement', () => { const { parserOutput, typeOutput } = performParsingTestCase({ diff --git a/apps/parser/test/integration/data-types.test.ts b/apps/parser/test/integration/data-types.test.ts index bac4808..5aba759 100644 --- a/apps/parser/test/integration/data-types.test.ts +++ b/apps/parser/test/integration/data-types.test.ts @@ -1,17 +1,17 @@ -import * as TestSubject from '@calvin-lang/parser/lib'; +import * as TestSubject from '@encode/parser/lib'; import { assert, assertEquals } from '@std/assert'; import { performParsingTestCase, useGlobalSettings } from '@/test/utils/mod.ts'; Deno.test('Data type parsing #integration', async (t) => { using _globalSettings = useGlobalSettings({ debugTrees: true }); - const parser = new TestSubject.CalvinParser(); + const parser = new TestSubject.EncodeParser(); const precedenceHandler = new TestSubject.PrecedenceHandler(); - const printer = new TestSubject.CalvinPrinter(); + const printer = new TestSubject.ParenPrinter(); - const typeAnalyzer = new TestSubject.CalvinTypeAnalyzer(); + const typeAnalyzer = new TestSubject.TypeAnalyzer(); await t.step('real number literal', () => { const { parserOutput } = performParsingTestCase({ diff --git a/apps/parser/test/integration/expressions.test.ts b/apps/parser/test/integration/expressions.test.ts index 0d24bec..4384c56 100644 --- a/apps/parser/test/integration/expressions.test.ts +++ b/apps/parser/test/integration/expressions.test.ts @@ -1,17 +1,17 @@ -import * as TestSubject from '@calvin-lang/parser/lib'; +import * as TestSubject from '@encode/parser/lib'; import { assert, assertEquals, assertGreater } from '@std/assert'; import { performParsingTestCase, useGlobalSettings } from '@/test/utils/mod.ts'; Deno.test('Expression parsing #integration', async (t) => { using _globalSettings = useGlobalSettings({ debugTrees: true }); - const parser = new TestSubject.CalvinParser(); + const parser = new TestSubject.EncodeParser(); const precedenceHandler = new TestSubject.PrecedenceHandler(); - const printer = new TestSubject.CalvinPrinter(); + const printer = new TestSubject.ParenPrinter(); - const typeAnalyzer = new TestSubject.CalvinTypeAnalyzer(); + const typeAnalyzer = new TestSubject.TypeAnalyzer(); await t.step('simple expression', () => { const { parserOutput, precOutput } = performParsingTestCase({ diff --git a/apps/parser/test/integration/keywords.test.ts b/apps/parser/test/integration/keywords.test.ts index 42d4b13..911914b 100644 --- a/apps/parser/test/integration/keywords.test.ts +++ b/apps/parser/test/integration/keywords.test.ts @@ -1,17 +1,17 @@ -import * as TestSubject from '@calvin-lang/parser/lib'; +import * as TestSubject from '@encode/parser/lib'; import { assert } from '@std/assert'; import { performParsingTestCase, useGlobalSettings } from '@/test/utils/mod.ts'; Deno.test('Keyword parsing #integration', async (t) => { using _globalSettings = useGlobalSettings({ debugTrees: true }); - const parser = new TestSubject.CalvinParser(); + const parser = new TestSubject.EncodeParser(); const precedenceHandler = new TestSubject.PrecedenceHandler(); - const printer = new TestSubject.CalvinPrinter(); + const printer = new TestSubject.ParenPrinter(); - const typeAnalyzer = new TestSubject.CalvinTypeAnalyzer(); + const typeAnalyzer = new TestSubject.TypeAnalyzer(); await t.step('if-elif-else block and do-while-finally block keywords', () => { const { parserOutput } = performParsingTestCase({ diff --git a/apps/parser/test/utils/mod.ts b/apps/parser/test/utils/mod.ts index f454dea..1e6589e 100644 --- a/apps/parser/test/utils/mod.ts +++ b/apps/parser/test/utils/mod.ts @@ -1,24 +1,24 @@ import { type BasePrinter, - CalvinLexer, - type CalvinParser, - type CalvinTypeAnalyzer, debug, + EncodeLexer, + type EncodeParser, Globals, type PrecedenceHandler, -} from '@calvin-lang/parser/lib'; + type TypeAnalyzer, +} from '@encode/parser/lib'; import type { ILexingResult } from 'chevrotain'; import type { FileCstChildren } from '@/generated/cst-types.ts'; export interface TestCaseParameters { /** - * The parser to use for parsing Calvin code. + * The parser to use for parsing Encode code. * * **Note:** We choose not to instantiate this ourselves in case we want to inject something else, e.g. a shim or an experimental impl */ - parser: CalvinParser; + parser: EncodeParser; /** - * The parser to use for parsing Calvin code. + * The parser to use for parsing Encode code. * * **Note:** We choose not to instantiate this ourselves in case we want to inject something else, e.g. a shim or an experimental impl */ @@ -34,9 +34,9 @@ export interface TestCaseParameters { * * **Note:** We choose not to instantiate this ourselves in case we want to inject something else, e.g. a shim or an experimental impl */ - typeAnalyzer: CalvinTypeAnalyzer; + typeAnalyzer: TypeAnalyzer; /** - * The Calvin code to parse + * The Encode code to parse */ code: string; } @@ -54,7 +54,7 @@ export interface TestCaseOutputs { } /** - * Executes a standard procedure to parse Calvin code. + * Executes a standard procedure to parse Encode code. * * **Caveats:** * @@ -66,7 +66,7 @@ export interface TestCaseOutputs { export function performParsingTestCase(params: TestCaseParameters): TestCaseOutputs { const { code, parser, printer, typeAnalyzer, precedenceHandler } = params; - const lexingResult = CalvinLexer.tokenize(code); + const lexingResult = EncodeLexer.tokenize(code); parser.input = lexingResult.tokens; const parserOutput = parser.file(); diff --git a/deno.jsonc b/deno.jsonc index 785841e..f6074f6 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -2,7 +2,7 @@ "workspace": ["apps/*", "scripts/*", "packages/*"], "tasks": { - "generate": "deno run --allow-write @calvin-lang/generate", + "generate": "deno run --allow-write @encode/generate", "check": "deno run --allow-env --allow-run @biomejs/biome check", "fmt": "deno run --allow-env --allow-run --allow-write @biomejs/biome format --write" }, diff --git a/docs/Implementation.md b/docs/Implementation.md index 26995b7..03e128b 100644 --- a/docs/Implementation.md +++ b/docs/Implementation.md @@ -3,7 +3,7 @@ For now at least, the compiler will be implemented using a pre-existing parser-generator. Potential options: GNU Bison/YACC, ANTLR -In the future, the compiler will be written in Calvin itself. +In the future, the compiler will be written in Encode itself. ## Targets diff --git a/docs/Type System.md b/docs/Type System.md index 53d74f9..8fa038f 100644 --- a/docs/Type System.md +++ b/docs/Type System.md @@ -58,7 +58,7 @@ An arbitrary precision complex type can be expressed as `Complex`. ## References -Calvin has two reference types: references (`T&`), which will always be valid, +Encode has two reference types: references (`T&`), which will always be valid, and `Maybe` (`T?`), which can hold `null`. Both are implemented as pointers under the hood. ## Enums @@ -69,7 +69,7 @@ to `u8`. An enum can take strings as the underlying data type for easier printi ## Unions -Calvin provides tagged unions as a data type. Tagged unions will require either a programmer defined +Encode provides tagged unions as a data type. Tagged unions will require either a programmer defined enum to be specified, or will create a hidden enum under the hood to handle the options. If there is no enum provided, the types provided in the options must be distinct from each other (there is no such constraint when the programmer provides an enum). Accessing a member of a tagged union will diff --git a/scripts/generate/deno.jsonc b/scripts/generate/deno.jsonc index 2f45f5c..41103b6 100644 --- a/scripts/generate/deno.jsonc +++ b/scripts/generate/deno.jsonc @@ -1,5 +1,5 @@ { - "name": "@calvin-lang/generate", + "name": "@encode/generate", "version": "0.1.0", "exports": { diff --git a/scripts/generate/main.ts b/scripts/generate/main.ts index b4b3c7c..8b04f74 100644 --- a/scripts/generate/main.ts +++ b/scripts/generate/main.ts @@ -1,4 +1,4 @@ -import { parser } from '@calvin-lang/parser/lib'; +import { parser } from '@encode/parser/lib'; import { parseArgs } from '@std/cli/parse-args'; import { bold, yellow } from '@std/fmt/colors'; import { generateDiagrams, generateTypes } from './mod.ts'; @@ -45,7 +45,7 @@ export async function main(): Promise { * to import files. This means we don't have to hard-code the exact path, only what package * export point we want to use. */ - const workspacePath = new URL(import.meta.resolve('@calvin-lang/parser/lib')); + const workspacePath = new URL(import.meta.resolve('@encode/parser/lib')); /** * An array of tasks to perform in parallel