Skip to content

Commit

Permalink
Ansel support and various bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianCassayre committed Jan 17, 2021
1 parent 96b55d5 commit 30576c1
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 17 deletions.
11 changes: 10 additions & 1 deletion src/model/Gedcom.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ export class Gedcom extends Node {
// undefined and null are considered as wildcards
const tagArray = tag != null ? (Array.isArray(tag) ? tag : [tag]) : null;
const idArray = id != null ? (Array.isArray(id) ? id : [id]) : null;
const withLimit = q != null;
if (withLimit && !Number.isInteger(q)) {
throw 'The quantifier provided is not an integer';
}

const data = this._data;
const arrayChildren = [], arrayParents = [];
Expand All @@ -79,16 +83,21 @@ export class Gedcom extends Node {
if (idArray !== null) { // Array of ids
idArray.forEach(id => {
const element = obj[id];
if(element !== undefined) {
if(element !== undefined && (!withLimit || q > 0)) { // A bit pointless
arrayChildren.push(element);
arrayParents.push(i);
}
});
} else { // All ids
let j = 0;
for (const id in obj) {
if (withLimit && j >= q) {
break;
}
const element = obj[id];
arrayChildren.push(element);
arrayParents.push(i);
j++;
}
}
});
Expand Down
8 changes: 4 additions & 4 deletions src/model/Name.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { NameRomanization } from './NameRomanization';
import { NameType } from './NameType';
import { Tag } from '../tag';

const rNameParts = /^(?:([^\/]*)|(?:(?:([^\/]*) )?\/([^\/]*)\/(?: ([^\/]*))?))$/;
const rNameParts = /^(?:([^\/]*)|(?:(?:([^\/]*) ?)?\/([^\/]*)\/(?: ?([^\/]*))?))$/;

export class Name extends NamePieces {
constructor(data, clazz) {
Expand All @@ -20,10 +20,10 @@ export class Name extends NamePieces {
if (!groups) {
return null;
}
if (groups[4] === undefined) {
return [groups[1], groups[2], groups[3]];
if (groups[1] === undefined) {
return [groups[2], groups[3], groups[4]];
} else {
return [groups[4], undefined, undefined];
return [groups[1], undefined, undefined];
}
});
}
Expand Down
8 changes: 4 additions & 4 deletions src/model/Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ export class Node {
});
});
} else { // All tags
let i = 0;
let j = 0;
for (const tag in tr.by_tag) {
if (withLimit && q >= i) {
if (withLimit && j >= q) {
break;
}
const objects = tr.by_tag[tag];
objects.forEach(v => {
arrayChildren.push(v);
arrayParents.push(i);
i++;
j++;
});
}
}
Expand Down Expand Up @@ -131,7 +131,7 @@ export class Node {
const newTree = [], newIndices = [];
data.tree.filter((t, i) => {
const parentIndex = data.parentIndices[i];
const unitNode = this._newInstance(data.Clazz, t, [parentIndex], data.parent);
const unitNode = this._newInstance(data.Clazz, [t], [parentIndex], data.parent);
if(f(unitNode)) {
newTree.push(t);
newIndices.push(parentIndex);
Expand Down
4 changes: 2 additions & 2 deletions src/model/Value.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class Value {
option(otherwise) {
const value = this.values[0];
if (otherwise !== undefined) {
return value !== null ? otherwise : value;
return value !== null ? value : otherwise;
} else {
return value;
}
Expand All @@ -45,6 +45,6 @@ export class Value {
}

map(f) {
return new Value(this.values.map(v => f(v)));
return new Value(this.values.map(f));
}
}
34 changes: 29 additions & 5 deletions src/parse/decoding/ansel.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/parse/tokenizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const gLineItem = `${gEscape}|${gLineText}|${gEscape}[${cDelim}]${gLineText}`;
const gXRefId = `@${gIdentifierString}@`;
const gPointer = `${gXRefId}`;
const gLineValue = `${gPointer}|(?:${gLineItem})`;
const gTag = `[${ccAlphanum}]+|_[${ccAlphanum}]+`; // TODO
const gTag = `[${ccAlphanum}]+|_[${ccAlphanum}_]+`; // TODO
const gTerminator = `${cCR}?${cLF}`;
const gGedcomLine = `(${gLevel})(?:${cDelim}(${gXRefId}))?${cDelim}(${gTag})(?:${cDelim}(${gLineValue}))?(?:${gTerminator})`;

Expand Down

0 comments on commit 30576c1

Please sign in to comment.