Moving towards multiple register parsers, to handle more exotic register types

This commit is contained in:
2025-10-10 13:46:21 +01:00
parent 5aa4c33059
commit 20764d74d3
6 changed files with 69 additions and 56 deletions

View File

@@ -18,16 +18,21 @@ export interface RegisterAccess {
operations: RegisterBitwiseOperation[];
notes: Note[];
}
export interface Register {
hex_address: string;
dec_address: number | string;
name: string;
description: string;
export interface RegisterDetail {
read?: RegisterAccess;
write?: RegisterAccess;
common?: RegisterAccess;
text: string;
notes: Note[];
}
export interface Register {
hex_address: string;
dec_address: number | string;
name: string;
modes: RegisterDetail[];
description: string;
issue_4_only: boolean;
source: string[];
}
@@ -84,8 +89,7 @@ export function processRegisterBlock(paragraph: string, registers: Register[]) {
dec_address: dec,
name: regName,
description: description,
notes: [],
text: "",
modes: [],
issue_4_only: false,
source: []
};

View File

@@ -1,9 +1,11 @@
import {Register, RegisterAccess} from "@/utils/register_parser";
import {Register, RegisterAccess, RegisterDetail} from "@/utils/register_parser";
export const parseDescriptionDefault = (reg: Register, description: string) => {
const descriptionLines = description.split('\n');
let currentAccess: 'read' | 'write' | 'common' | null = null;
let accessData: RegisterAccess = { operations: [], notes: [] };
// Prepare a new RegisterDetail for this description block
const detail: RegisterDetail = { read: undefined, write: undefined, common: undefined, text: '', notes: [] };
for (const line of descriptionLines) {
if (line.includes('Issue 4 Only')) reg.issue_4_only = true;
@@ -14,25 +16,34 @@ export const parseDescriptionDefault = (reg: Register, description: string) => {
if (trimmedLine.startsWith('//')) continue;
if (trimmedLine.startsWith('(R)')) {
if (currentAccess) reg[currentAccess] = accessData;
if (currentAccess) {
// finalize previous access block into detail
detail[currentAccess] = accessData;
}
accessData = { operations: [], notes: [] };
currentAccess = 'read';
continue;
}
if (trimmedLine.startsWith('(W)')) {
if (currentAccess) reg[currentAccess] = accessData;
if (currentAccess) {
detail[currentAccess] = accessData;
}
accessData = { operations: [], notes: [] };
currentAccess = 'write';
continue;
}
if (trimmedLine.startsWith('(R/W')) {
if (currentAccess) reg[currentAccess] = accessData;
if (currentAccess) {
detail[currentAccess] = accessData;
}
accessData = { operations: [], notes: [] };
currentAccess = 'common';
continue;
}
if (line.startsWith(trimmedLine)) {
if (currentAccess) reg[currentAccess] = accessData;
if (currentAccess) {
detail[currentAccess] = accessData;
}
accessData = { operations: [], notes: [] };
currentAccess = null;
}
@@ -81,17 +92,20 @@ export const parseDescriptionDefault = (reg: Register, description: string) => {
if (trimmedLine.startsWith('*')) {
const noteMatch = trimmedLine.match(/^(\*+)\s*(.*)/);
if (noteMatch) {
reg.notes.push({
detail.notes.push({
ref: noteMatch[1],
text: noteMatch[2],
});
}
} else if (trimmedLine) {
reg.text += `${line}\n`;
detail.text += `${line}\n`;
}
}
}
if (currentAccess) {
reg[currentAccess] = accessData;
detail[currentAccess] = accessData;
}
// Push the parsed detail into modes
reg.modes = reg.modes || [];
reg.modes.push(detail);
};

View File

@@ -1,12 +1,13 @@
// Special-case parser for 0xF0 (XDEV CMD): treat headings beginning with '*' inside access blocks
// as descriptive text instead of notes, so sub-modes become part of the section descriptions.
import {Register, RegisterAccess} from "@/utils/register_parser";
import {Register, RegisterAccess, RegisterDetail} from "@/utils/register_parser";
export const parseDescriptionF0 = (reg: Register, description: string) => {
const descriptionLines = description.split('\n');
let currentAccess: 'read' | 'write' | 'common' | null = null;
let accessData: RegisterAccess = { operations: [], notes: [] };
const detail: RegisterDetail = { read: undefined, write: undefined, common: undefined, text: '', notes: [] };
for (const line of descriptionLines) {
if (line.includes('Issue 4 Only')) reg.issue_4_only = true;
@@ -17,25 +18,25 @@ export const parseDescriptionF0 = (reg: Register, description: string) => {
if (trimmedLine.startsWith('//')) continue;
if (trimmedLine.startsWith('(R)')) {
if (currentAccess) reg[currentAccess] = accessData;
if (currentAccess) detail[currentAccess] = accessData;
accessData = { operations: [], notes: [] };
currentAccess = 'read';
continue;
}
if (trimmedLine.startsWith('(W)')) {
if (currentAccess) reg[currentAccess] = accessData;
if (currentAccess) detail[currentAccess] = accessData;
accessData = { operations: [], notes: [] };
currentAccess = 'write';
continue;
}
if (trimmedLine.startsWith('(R/W')) {
if (currentAccess) reg[currentAccess] = accessData;
if (currentAccess) detail[currentAccess] = accessData;
accessData = { operations: [], notes: [] };
currentAccess = 'common';
continue;
}
if (line.startsWith(trimmedLine)) {
if (currentAccess) reg[currentAccess] = accessData;
if (currentAccess) detail[currentAccess] = accessData;
accessData = { operations: [], notes: [] };
currentAccess = null;
}
@@ -79,20 +80,22 @@ export const parseDescriptionF0 = (reg: Register, description: string) => {
}
} else {
if (trimmedLine.startsWith('*')) {
// Outside access blocks, keep notes as-is
// Outside access blocks, keep notes as-is but attach to detail now
const noteMatch = trimmedLine.match(/^(\*+)\s*(.*)/);
if (noteMatch) {
reg.notes.push({
detail.notes.push({
ref: noteMatch[1],
text: noteMatch[2],
});
}
} else if (trimmedLine) {
reg.text += `${line}\n`;
detail.text += `${line}\n`;
}
}
}
if (currentAccess) {
reg[currentAccess] = accessData;
detail[currentAccess] = accessData;
}
reg.modes = reg.modes || [];
reg.modes.push(detail);
};