-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a6d4d8c
commit 4366076
Showing
2 changed files
with
50 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import {random_id, UUID} from "./tree"; | ||
|
||
export interface Marker { | ||
} | ||
|
||
export class Markers { | ||
public static readonly EMPTY: Markers = new Markers(random_id(), []); | ||
|
||
private readonly _id: string; | ||
private readonly _markers: Marker[] = []; | ||
|
||
constructor(id: UUID, markers: Marker[]) { | ||
this._id = id; | ||
this._markers = markers; | ||
} | ||
|
||
public id(): string { | ||
return this._id; | ||
} | ||
|
||
public markers(): Marker[] { | ||
return this._markers; | ||
} | ||
|
||
public findFirst<T extends Marker>(markerType: new () => T): T | null { | ||
return this._markers.find((marker) => marker instanceof markerType) as T || null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,31 @@ | ||
import { v4 as uuidv4 } from 'uuid'; | ||
import {v4 as uuidv4} from 'uuid'; | ||
|
||
type UUID = string; | ||
export type UUID = string; | ||
|
||
export const random_id = (): UUID => { | ||
return uuidv4(); | ||
} | ||
|
||
class CompilationUnit { | ||
constructor( | ||
public readonly id: UUID | ||
) { | ||
export class Cursor { | ||
private readonly _parent: Cursor | null; | ||
private readonly _value: Object; | ||
private _messages: Map<string, Object>; | ||
|
||
constructor(parent: Cursor | null, value: Object) { | ||
this._parent = parent; | ||
this._value = value; | ||
this._messages = new Map<string, Object>(); | ||
} | ||
|
||
withId(newId: UUID): CompilationUnit { | ||
return newId == this.id ? this : new CompilationUnit(newId); | ||
public parent(): Cursor | null { | ||
return this._parent; | ||
} | ||
} | ||
|
||
public value<T>(): T { | ||
return this._value as T; | ||
} | ||
|
||
public fork(): Cursor { | ||
return new Cursor(this._parent === null ? null : this._parent.fork(), this.value); | ||
} | ||
} |