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:
@@ -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; };
|
||||
|
||||
@@ -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> {
|
||||
|
||||
Reference in New Issue
Block a user