Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# calvin-lang
# encode

Personal project to make a C/JS-like programming language
2 changes: 1 addition & 1 deletion apps/parser/deno.jsonc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@calvin-lang/parser",
"name": "@encode/parser",
"version": "0.1.0",

"exports": {
Expand Down
8 changes: 4 additions & 4 deletions apps/parser/main.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -32,11 +32,11 @@ export async function main(): Promise<void> {

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;

Expand Down
2 changes: 1 addition & 1 deletion apps/parser/src/lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,4 +274,4 @@ export const allTokens: TokenType[] = [
ERROR,
];

export const CalvinLexer: Lexer = new Lexer(allTokens);
export const EncodeLexer: Lexer = new Lexer(allTokens);
4 changes: 2 additions & 2 deletions apps/parser/src/parser.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -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<typeof parser.getBaseCstVisitorConstructor> =
parser.getBaseCstVisitorConstructor();
export const BaseCstVisitorWithDefaults: ReturnType<
Expand Down
2 changes: 1 addition & 1 deletion apps/parser/src/visitors/printers/paren.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number, void> {
export class ParenPrinter extends BasePrinter implements ICstNodeVisitor<number, void> {
constructor(colors: boolean = true, output: Logger | null = console.log) {
super(colors, output);
}
Expand Down
2 changes: 1 addition & 1 deletion apps/parser/src/visitors/semantics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class Scope {
}
}

export class CalvinTypeAnalyzer
export class TypeAnalyzer
extends BaseCstVisitor
implements ICstNodeVisitor<void, Meta | undefined>
{
Expand Down
8 changes: 4 additions & 4 deletions apps/parser/test/end-to-end/parsing.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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)),
Expand Down
6 changes: 3 additions & 3 deletions apps/parser/test/integration/comments.test.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
8 changes: 4 additions & 4 deletions apps/parser/test/integration/control-flow.test.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
8 changes: 4 additions & 4 deletions apps/parser/test/integration/data-types.test.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
8 changes: 4 additions & 4 deletions apps/parser/test/integration/expressions.test.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
8 changes: 4 additions & 4 deletions apps/parser/test/integration/keywords.test.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
22 changes: 11 additions & 11 deletions apps/parser/test/utils/mod.ts
Original file line number Diff line number Diff line change
@@ -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
*/
Expand All @@ -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;
}
Expand All @@ -54,7 +54,7 @@ export interface TestCaseOutputs {
}

/**
* Executes a standard procedure to parse Calvin code.
* Executes a standard procedure to parse Encode code.
*
* **Caveats:**
*
Expand All @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion docs/Implementation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions docs/Type System.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>` (`T?`), which can hold `null`. Both are implemented as pointers under the hood.

## Enums
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate/deno.jsonc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@calvin-lang/generate",
"name": "@encode/generate",
"version": "0.1.0",

"exports": {
Expand Down
4 changes: 2 additions & 2 deletions scripts/generate/main.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -45,7 +45,7 @@ export async function main(): Promise<void> {
* 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
Expand Down