Moving towards a "custom" parser for NextReg 0xF0
This commit is contained in:
@@ -5,11 +5,12 @@ export const parseDescriptionDefault = (reg: Register, description: string) => {
|
||||
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: [] };
|
||||
const detail: RegisterDetail = { read: undefined, write: undefined, common: undefined, text: ''};
|
||||
|
||||
for (const line of descriptionLines) {
|
||||
if (line.includes('Issue 4 Only')) reg.issue_4_only = true;
|
||||
|
||||
const spaces_at_start = line.match(/^(\s*)/)?.[0].length || 0;
|
||||
const trimmedLine = line.trim();
|
||||
reg.source.push(line);
|
||||
|
||||
@@ -50,7 +51,7 @@ export const parseDescriptionDefault = (reg: Register, description: string) => {
|
||||
|
||||
if (currentAccess) {
|
||||
const bitMatch = trimmedLine.match(/^(bits?|bit)\s+([\d:-]+)\s*=\s*(.*)/);
|
||||
const valueMatch = !line.match(/^\s+/) && trimmedLine.match(/^([01\s]+)\s*=\s*(.*)/);
|
||||
// const valueMatch = !line.match(/^\s+/) && trimmedLine.match(/^([01\s]+)\s*=\s*(.*)/);
|
||||
|
||||
if (bitMatch) {
|
||||
let bitDescription = bitMatch[3];
|
||||
@@ -65,13 +66,15 @@ export const parseDescriptionDefault = (reg: Register, description: string) => {
|
||||
description: bitDescription,
|
||||
footnoteRef: footnoteRef,
|
||||
});
|
||||
} else if (valueMatch) {
|
||||
accessData.operations.push({
|
||||
bits: valueMatch[1].trim().replace(/\s/g, ''),
|
||||
description: valueMatch[2].trim(),
|
||||
});
|
||||
// } else if (valueMatch) {
|
||||
// console.error("VALUE MATCH",valueMatch);
|
||||
// accessData.operations.push({
|
||||
// bits: valueMatch[1].trim().replace(/\s/g, ''),
|
||||
// description: valueMatch[2].trim(),
|
||||
// });
|
||||
} else if (trimmedLine.startsWith('*')) {
|
||||
const noteMatch = trimmedLine.match(/^(\*+)\s*(.*)/);
|
||||
console.log("NOTE MATCH",noteMatch);
|
||||
if (noteMatch) {
|
||||
accessData.notes.push({
|
||||
ref: noteMatch[1],
|
||||
@@ -79,6 +82,12 @@ export const parseDescriptionDefault = (reg: Register, description: string) => {
|
||||
});
|
||||
}
|
||||
} else if (trimmedLine) {
|
||||
if(spaces_at_start == 2) {
|
||||
reg.text += `${line}\n`;
|
||||
continue;
|
||||
}
|
||||
// console.log("LINE",line);
|
||||
console.log(line.match(/^\s+/), line);
|
||||
if (line.match(/^\s+/) && accessData.operations.length > 0) {
|
||||
accessData.operations[accessData.operations.length - 1].description += `\n${line}`;
|
||||
} else {
|
||||
@@ -92,7 +101,7 @@ export const parseDescriptionDefault = (reg: Register, description: string) => {
|
||||
if (trimmedLine.startsWith('*')) {
|
||||
const noteMatch = trimmedLine.match(/^(\*+)\s*(.*)/);
|
||||
if (noteMatch) {
|
||||
detail.notes.push({
|
||||
reg.notes.push({
|
||||
ref: noteMatch[1],
|
||||
text: noteMatch[2],
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user