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",
"description": "",
"license": "MIT",
@ -11,8 +11,12 @@
"package": "electron-forge package",
"make": "electron-forge make",
"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": {
"@electron-forge/cli": "^7.11.1",
"@electron-forge/maker-deb": "^7.11.1",
@ -45,6 +49,6 @@
"codemirror": "^6.0.2",
"electron-squirrel-startup": "^1.0.1",
"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 fs from 'fs';
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 { valueToString } from '../debug/value_show';
import { Program } from '../program';

View file

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

View file

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

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

View file

@ -1,6 +1,6 @@
import { Cursor } from './cursor';
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 { 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 type { Span, CodePoint } from 'source-text';
import { CARRIAGE_RETURN, char, NEW_LINE } from 'source-region';
import type { Span, CodePoint } from 'source-region';
import { isDigit, isWhitespace, scanNumber, scanString } 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";
export function DisplayLineView(prop: { view: LineView }) {

View file

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

View file

@ -1,6 +1,6 @@
import { For, Match, Show, Switch } from "solid-js";
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 { Program } from "src/lang/program";

View file

@ -2,7 +2,7 @@ import { createSignal, Show } from "solid-js";
import { Digith } from "src/ui/Digith";
import { useProgram } from "src/ui/ProgramProvider";
import { CodeEditor } from "src/ui/Component/CodeEditor";
import { sourceText } from "source-text";
import { sourceText } from "source-region";
import { Program } from "src/lang/program";
import { V, Validation, letValidate } from "src/ui/validation";
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 { useProgram } from "src/ui/ProgramProvider";
import { CodeEditor } from "src/ui/Component/CodeEditor";
import { sourceText } from "source-text";
import { sourceText } from "source-region";
import { Program } from "src/lang/program";
import { V, Validation, letValidate } from "src/ui/validation";
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 { Value } from 'src/lang/eval/value';
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 { ShowParseError } from 'src/ui/Component/ParseError';
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 { useProgram } from "src/ui/ProgramProvider";
import { CodeEditor } from "src/ui/Component/CodeEditor";
import { sourceText } from "source-text";
import { sourceText } from "source-region";
import { Program } from "src/lang/program";
import { V, Validation, letValidate } from "src/ui/validation";
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 { useProgram } from "src/ui/ProgramProvider";
import { CodeEditor } from "src/ui/Component/CodeEditor";
import { sourceText } from "source-text";
import { sourceText } from "source-region";
import { Program } from "src/lang/program";
import { V, Validation, letValidate } from "src/ui/validation";
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 { sourceText } from "source-text";
import { sourceText } from "source-region";
import { Expr, FunctionName, ProductPattern, SignalExpr } from "src/lang/expr";
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
# Tests

View file

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