Compare commits

...

2 commits

Author SHA1 Message Date
Yura Dupyn
1158166e3e Finally make it work with source-region library 2026-04-06 21:27:51 +02:00
Yura Dupyn
d64c39db82 Renaming and source-region issues 2026-04-06 20:34:20 +02:00
20 changed files with 845 additions and 698 deletions

@ -1 +1 @@
Subproject commit beab541907abc8b204d63050e4d4dab82cc7db50 Subproject commit 5df8b05274f6b88097ac25400ba5aa625a8887bc

1463
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,5 +1,5 @@
{ {
"name": "electron-test", "name": "scrowl",
"version": "1.0.0", "version": "1.0.0",
"description": "", "description": "",
"license": "MIT", "license": "MIT",
@ -11,8 +11,12 @@
"package": "electron-forge package", "package": "electron-forge package",
"make": "electron-forge make", "make": "electron-forge make",
"publish": "electron-forge publish", "publish": "electron-forge publish",
"lint": "eslint --ext .ts,.tsx ." "lint": "eslint --ext .ts,.tsx .",
"build:libs": "npm run build -w source-region"
}, },
"workspaces": [
"libs/*"
],
"devDependencies": { "devDependencies": {
"@electron-forge/cli": "^7.11.1", "@electron-forge/cli": "^7.11.1",
"@electron-forge/maker-deb": "^7.11.1", "@electron-forge/maker-deb": "^7.11.1",
@ -45,6 +49,6 @@
"codemirror": "^6.0.2", "codemirror": "^6.0.2",
"electron-squirrel-startup": "^1.0.1", "electron-squirrel-startup": "^1.0.1",
"solid-js": "^1.9.11", "solid-js": "^1.9.11",
"source-text": "file:libs/source-region" "source-region": "*"
} }
} }

View file

@ -2,7 +2,7 @@
import * as readline from 'readline'; import * as readline from 'readline';
import * as fs from 'fs'; import * as fs from 'fs';
import { parseExpr, ParseError } from '../parser/parser'; import { parseExpr, ParseError } from '../parser/parser';
import { SourceRegion, SourceText, renderSpan, sourceText } from 'source-text'; import { SourceRegion, SourceText, renderSpan, sourceText } from 'source-region';
import { exprToString } from '../debug/expr_show'; import { exprToString } from '../debug/expr_show';
import { valueToString } from '../debug/value_show'; import { valueToString } from '../debug/value_show';
import { Program } from '../program'; import { Program } from '../program';

View file

@ -1,4 +1,4 @@
import { Span } from "source-text" import { Span } from "source-region"
// === Identifiers === // === Identifiers ===
export type VariableName = string export type VariableName = string

View file

@ -1,5 +1,5 @@
// AI GENERATED // AI GENERATED
import { SourceText, sourceText } from "source-text"; import { SourceText, sourceText } from "source-region";
import { Cursor, scanString, scanNumber } from "./cursor"; import { Cursor, scanString, scanNumber } from "./cursor";
import { Result } from "../result"; import { Result } from "../result";
@ -189,8 +189,8 @@ function test_cursor_tracking() {
// Check location after scan (should be after 123, before \r) // Check location after scan (should be after 123, before \r)
// Actually r1.value.span tells us where the token WAS. // Actually r1.value.span tells us where the token WAS.
const span1 = (r1 as any).value.span; const span1 = (r1 as any).value.span;
assert(span1.line === 1, "Line 1 line# wrong"); assert(span1.start.line === 1, "Line 1 line# wrong");
assert(span1.column === 1, "Line 1 col# wrong"); assert(span1.start.column === 1, "Line 1 col# wrong");
// 2. Skip Whitespace (Scanner logic simulation) // 2. Skip Whitespace (Scanner logic simulation)
// We need to manually skip \r\n // We need to manually skip \r\n
@ -201,7 +201,7 @@ function test_cursor_tracking() {
const r2 = scanNumber(cursor); const r2 = scanNumber(cursor);
assertOk(r2, 456); assertOk(r2, 456);
const span2 = (r2 as any).value.span; const span2 = (r2 as any).value.span;
assert(span2.line === 2, "Line 2 line# wrong"); assert(span2.start.line === 2, "Line 2 line# wrong");
// 4. Skip \n // 4. Skip \n
cursor.next(); cursor.next();
@ -210,7 +210,7 @@ function test_cursor_tracking() {
const r3 = scanString(cursor); const r3 = scanString(cursor);
assertOk(r3, "foo"); assertOk(r3, "foo");
const span3 = (r3 as any).value.span; const span3 = (r3 as any).value.span;
assert(span3.line === 3, "Line 3 line# wrong"); assert(span3.start.line === 3, "Line 3 line# wrong");
console.log(`${GREEN}✔ Cursor tracking passed${RESET}`); console.log(`${GREEN}✔ Cursor tracking passed${RESET}`);
} }

View file

@ -1,5 +1,5 @@
import { char, NEW_LINE, CARRIAGE_RETURN, DOT, DIGIT_0, DIGIT_9, LOWERCASE_a, LOWERCASE_f, UPPERCASE_A, UPPERCASE_F, SPACE, TAB } from 'source-text'; import { char, NEW_LINE, CARRIAGE_RETURN, DOT, DIGIT_0, DIGIT_9, LOWERCASE_a, LOWERCASE_f, UPPERCASE_A, UPPERCASE_F, SPACE, TAB } from 'source-region';
import type { SourceRegion, SourceText, Span, SourceLocation, CodePoint, StringIndex, CodePointIndex } from 'source-text'; import type { SourceRegion, SourceText, Span, SourceLocation, CodePoint, StringIndex, CodePointIndex } from 'source-region';
import { Result } from '../result'; import { Result } from '../result';
export type CursorState = { export type CursorState = {
@ -43,15 +43,14 @@ export class Cursor {
peek(n: number = 0): CodePoint | undefined { peek(n: number = 0): CodePoint | undefined {
if (this.index + n >= this.region.span.end.index) return undefined; if (this.index + n >= this.region.span.end.index) return undefined;
return this.text.chars[this.index + n]?.char; return this.region.codePointAt(this.index + n);
} }
next(): CodePoint | undefined { next(): CodePoint | undefined {
if (this.eof()) return undefined; if (this.eof()) return undefined;
const ref = this.text.chars[this.index]; const c = this.region.codePointAt(this.index);
if (!ref) return undefined; if (c === undefined) return undefined;
const c = ref.char;
this.index++; this.index++;
if (c === NEW_LINE) { if (c === NEW_LINE) {
@ -82,7 +81,7 @@ export class Cursor {
// TODO: unicode-index ~> string-offset, make that into a separate function. // TODO: unicode-index ~> string-offset, make that into a separate function.
currentOffset(): StringIndex { currentOffset(): StringIndex {
return this.text.chars[this.index]?.offset ?? this.text.source.length; return this.text.sliceByCp(0, this.index).length;
} }
currentLocation(): SourceLocation { currentLocation(): SourceLocation {

View file

@ -1,6 +1,6 @@
import { Cursor } from './cursor'; import { Cursor } from './cursor';
import { ExprScanError, exprStart, ExprStartToken, IdentifierKind, identifierScanner, isNextTokenExprStart, isNextTokenProductPatternStart, patternStart, PatternStartToken, signalExprStart, SignalExprStartToken, skipWhitespaceAndComments } from './scanner'; import { ExprScanError, exprStart, ExprStartToken, IdentifierKind, identifierScanner, isNextTokenExprStart, isNextTokenProductPatternStart, patternStart, PatternStartToken, signalExprStart, SignalExprStartToken, skipWhitespaceAndComments } from './scanner';
import { char, CodePoint, SourceRegion, SourceText, Span } from 'source-text'; import { char, CodePoint, SourceRegion, SourceText, Span } from 'source-region';
import { Result } from '../result'; import { Result } from '../result';
import { Expr, ExprBinding, FieldAssignment, FieldPattern, FunctionName, MatchBranch, Pattern, ProductPattern, SignalExpr, SignalExprBinding } from '../expr'; import { Expr, ExprBinding, FieldAssignment, FieldPattern, FunctionName, MatchBranch, Pattern, ProductPattern, SignalExpr, SignalExprBinding } from '../expr';

View file

@ -1,5 +1,5 @@
import { CARRIAGE_RETURN, char, NEW_LINE } from 'source-text'; import { CARRIAGE_RETURN, char, NEW_LINE } from 'source-region';
import type { Span, CodePoint } from 'source-text'; import type { Span, CodePoint } from 'source-region';
import { isDigit, isWhitespace, scanNumber, scanString } from './cursor'; import { isDigit, isWhitespace, scanNumber, scanString } from './cursor';
import type { Cursor, GenericScanError, NumberError, StringError } from './cursor'; import type { Cursor, GenericScanError, NumberError, StringError } from './cursor';

View file

@ -1,4 +1,4 @@
import { LineView } from "source-text"; import { LineView } from "source-region";
import { For, Show } from "solid-js"; import { For, Show } from "solid-js";
export function DisplayLineView(prop: { view: LineView }) { export function DisplayLineView(prop: { view: LineView }) {

View file

@ -1,5 +1,5 @@
import { ParseError } from "src/lang/parser/parser"; import { ParseError } from "src/lang/parser/parser";
import { renderSpan, SourceRegion } from "source-text"; import { renderSpan, SourceRegion } from "source-region";
import { DisplayLineViews } from "./LineView"; import { DisplayLineViews } from "./LineView";
export function formatErrorMesage(err: ParseError): string { export function formatErrorMesage(err: ParseError): string {

View file

@ -1,6 +1,6 @@
import { For, Match, Show, Switch } from "solid-js"; import { For, Match, Show, Switch } from "solid-js";
import { ParseError } from "src/lang/parser/parser"; import { ParseError } from "src/lang/parser/parser";
import { SourceRegion } from "source-text"; import { SourceRegion } from "source-region";
import { ShowParseError } from 'src/ui/Component/ParseError'; import { ShowParseError } from 'src/ui/Component/ParseError';
import { Program } from "src/lang/program"; import { Program } from "src/lang/program";

View file

@ -2,7 +2,7 @@ import { createSignal, Show } from "solid-js";
import { Digith } from "src/ui/Digith"; import { Digith } from "src/ui/Digith";
import { useProgram } from "src/ui/ProgramProvider"; import { useProgram } from "src/ui/ProgramProvider";
import { CodeEditor } from "src/ui/Component/CodeEditor"; import { CodeEditor } from "src/ui/Component/CodeEditor";
import { sourceText } from "source-text"; import { sourceText } from "source-region";
import { Program } from "src/lang/program"; import { Program } from "src/lang/program";
import { V, Validation, letValidate } from "src/ui/validation"; import { V, Validation, letValidate } from "src/ui/validation";
import { validateExprRaw, validateParamsRaw } from "src/ui/validation/helpers"; import { validateExprRaw, validateParamsRaw } from "src/ui/validation/helpers";

View file

@ -2,7 +2,7 @@ import { createSignal } from "solid-js";
import { Digith } from "src/ui/Digith"; import { Digith } from "src/ui/Digith";
import { useProgram } from "src/ui/ProgramProvider"; import { useProgram } from "src/ui/ProgramProvider";
import { CodeEditor } from "src/ui/Component/CodeEditor"; import { CodeEditor } from "src/ui/Component/CodeEditor";
import { sourceText } from "source-text"; import { sourceText } from "source-region";
import { Program } from "src/lang/program"; import { Program } from "src/lang/program";
import { V, Validation, letValidate } from "src/ui/validation"; import { V, Validation, letValidate } from "src/ui/validation";
import { validateExprRaw, validateNameRaw, validateParamsRaw } from "src/ui/validation/helpers"; import { validateExprRaw, validateNameRaw, validateParamsRaw } from "src/ui/validation/helpers";

View file

@ -3,7 +3,7 @@ import { useProgram } from 'src/ui/ProgramProvider';
import { eval_start } from 'src/lang/eval/evaluator'; import { eval_start } from 'src/lang/eval/evaluator';
import { Value } from 'src/lang/eval/value'; import { Value } from 'src/lang/eval/value';
import { RuntimeError } from 'src/lang/eval/error'; import { RuntimeError } from 'src/lang/eval/error';
import { SourceRegion, SourceText, sourceText } from 'source-text'; import { SourceRegion, SourceText, sourceText } from 'source-region';
import { ParseError, parseExpr } from 'src/lang/parser/parser'; import { ParseError, parseExpr } from 'src/lang/parser/parser';
import { ShowParseError } from 'src/ui/Component/ParseError'; import { ShowParseError } from 'src/ui/Component/ParseError';
import { Val } from 'src/ui/Component/Value'; import { Val } from 'src/ui/Component/Value';

View file

@ -2,7 +2,7 @@ import { createSignal } from "solid-js";
import { Digith } from "src/ui/Digith"; import { Digith } from "src/ui/Digith";
import { useProgram } from "src/ui/ProgramProvider"; import { useProgram } from "src/ui/ProgramProvider";
import { CodeEditor } from "src/ui/Component/CodeEditor"; import { CodeEditor } from "src/ui/Component/CodeEditor";
import { sourceText } from "source-text"; import { sourceText } from "source-region";
import { Program } from "src/lang/program"; import { Program } from "src/lang/program";
import { V, Validation, letValidate } from "src/ui/validation"; import { V, Validation, letValidate } from "src/ui/validation";
import { validateNameRaw, validateSignalExprRaw } from "src/ui/validation/helpers"; import { validateNameRaw, validateSignalExprRaw } from "src/ui/validation/helpers";

View file

@ -2,7 +2,7 @@ import { createEffect, createSignal, onCleanup, Show } from "solid-js";
import { Digith } from "src/ui/Digith"; import { Digith } from "src/ui/Digith";
import { useProgram } from "src/ui/ProgramProvider"; import { useProgram } from "src/ui/ProgramProvider";
import { CodeEditor } from "src/ui/Component/CodeEditor"; import { CodeEditor } from "src/ui/Component/CodeEditor";
import { sourceText } from "source-text"; import { sourceText } from "source-region";
import { Program } from "src/lang/program"; import { Program } from "src/lang/program";
import { V, Validation, letValidate } from "src/ui/validation"; import { V, Validation, letValidate } from "src/ui/validation";
import { validateSignalExprRaw } from "src/ui/validation/helpers"; import { validateSignalExprRaw } from "src/ui/validation/helpers";

View file

@ -1,5 +1,5 @@
import { ParseError, parseExpr, parseFunctionName, parseFunctionParameters, parseSignalExpr } from "src/lang/parser/parser"; import { ParseError, parseExpr, parseFunctionName, parseFunctionParameters, parseSignalExpr } from "src/lang/parser/parser";
import { sourceText } from "source-text"; import { sourceText } from "source-region";
import { Expr, FunctionName, ProductPattern, SignalExpr } from "src/lang/expr"; import { Expr, FunctionName, ProductPattern, SignalExpr } from "src/lang/expr";
import { V } from "./"; import { V } from "./";

View file

@ -1,5 +1,19 @@
```
npm install
npm run build:libs # to build the libs like `source-region`
```
# pulls latest commits of all the submodules
```
git submodule update --remote
```
npm run start npm run start
# Tests # Tests

View file

@ -9,6 +9,9 @@ export default defineConfig({
'src': path.resolve(__dirname, './src'), 'src': path.resolve(__dirname, './src'),
}, },
}, },
optimizeDeps: {
exclude: ['source-region'],
},
plugins: [ plugins: [
solidPlugin(), solidPlugin(),
], ],