2
0
mirror of https://github.com/tenrok/BBob.git synced 2026-06-20 20:00:33 +03:00

feat: add start and end positions of tag nodes (#246)

Closes #134

* feat: Add start and end positions of tag nodes

Improves accuracy of row/col error reporting. Now targets the start of the relevant token instead of the end.

* Simplify language for TagNode and Token

* Update static TagNode.create to ingest setStart() logic

improve readability of end pos offset for no attr tags
This commit is contained in:
Steven Chang
2024-08-01 00:42:29 -07:00
committed by GitHub
parent 0beab56d7f
commit 40848747d4
13 changed files with 929 additions and 386 deletions
+11 -7
View File
@@ -1,13 +1,17 @@
export type StringNode = string | number
export type StringNode = string | number;
export interface TagNodeObject<TagValue extends any = any> {
readonly tag: TagValue
attrs?: Record<string, unknown>
content?: TagNodeTree<TagValue>
readonly tag: TagValue;
attrs?: Record<string, unknown>;
content?: TagNodeTree<TagValue>;
start?: TagPosition;
end?: TagPosition;
}
export type NodeContent<TagValue extends any = any> = TagNodeObject<TagValue> | StringNode | null
export type NodeContent<TagValue extends any = any> = TagNodeObject<TagValue> | StringNode | null;
export type PartialNodeContent<TagValue extends any = any> = Partial<TagNodeObject<TagValue>> | StringNode | null
export type PartialNodeContent<TagValue extends any = any> = Partial<TagNodeObject<TagValue>> | StringNode | null;
export type TagNodeTree<TagValue extends any = any> = NodeContent<TagValue> | NodeContent<TagValue>[] | null
export type TagNodeTree<TagValue extends any = any> = NodeContent<TagValue> | NodeContent<TagValue>[] | null;
export type TagPosition = { from: number; to: number; };
+4 -2
View File
@@ -1,4 +1,4 @@
import { TagNodeTree } from "./common";
import { TagNodeTree, TagPosition } from "./common";
export interface ParseError {
tagName: string;
@@ -9,7 +9,9 @@ export interface ParseError {
export interface TagNode {
readonly tag: string
attrs?: Record<string, unknown>
content?: TagNodeTree
content?: TagNodeTree,
start?: TagPosition;
end?: TagPosition;
}
export interface Token<TokenValue = string> {