Skip to content

Commit

Permalink
Allow repeated tables, but ignore nested tables
Browse files Browse the repository at this point in the history
  • Loading branch information
sverhoeven committed Oct 9, 2024
1 parent 929ef70 commit 7b794d4
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## @i-vresse/wb-core 3.2.4 - 2024-10-09

### Fixed

- Do treat `['caprieval.1']` as a node, but `['section1.1'.mol1]` not as a node

## @i-vresse/wb-core 3.2.3 - 2024-10-09

### Fixed

- Do not treat `[topoaa.mol1]` as a module
- Do not treat `[topoaa.mol1]` as a node

## @i-vresse/wb-core 3.2.2 - 2024-10-09

Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@i-vresse/wb-core",
"version": "3.2.3",
"version": "3.2.4",
"description": "React components to construct a workflow builder application",
"keywords": [
"react",
Expand Down
27 changes: 27 additions & 0 deletions packages/core/src/toml.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1129,4 +1129,31 @@ describe('lines2node()', () => {
const expected = [-1, -1, -1, -1, -1, 0, 0, 0]
expect(lookup).toEqual(expected)
})

it('given repeated table with nested table', () => {
const workflow = [
'',
'molecules = [',
']',
'',
'[section1]', // node 0
'',
'[section1.mol1]',
'',
"['section1.1']", // node 1
'',
"['section1.1'.mol1]",
'',
'[section2]', // node 2
'',
"['section1.42']", // node 3
'',
"['section1.42'.mol12]"
].join('\n')

const lookup = lines2node(workflow)

const expected = [-1, -1, -1, -1, -1, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3]
expect(lookup).toEqual(expected)
})
})
8 changes: 6 additions & 2 deletions packages/core/src/toml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ export function dedupWorkflow (inp: string): string {
* For each line in the text, return the node index.
* -1 for global parameters.
*
* Ignores table with dots in the name.
* Ignores table with dots in the name,
* but do allow dot in the name if it inside qoutes.
*
* @param text The TOML text
* @returns
Expand All @@ -319,9 +320,12 @@ export function lines2node (text: string): number[] {
// highlighter linenumber starts with 1 so add offset
const nodeLines: number[] = [-1]
let nodeIndex = -1
// Matches ['section1.1'] , but not ['section1.1'.mol1]
const isRepeatedNodeRegexp = /^\[['"].*\.\d+['"]\]$/g
for (let i = 0; i < lines.length; i++) {
const line = lines[i]
if (line.startsWith('[') && !line.includes('.')) {
const isRepeatedNode = isRepeatedNodeRegexp.test(line)
if (line.startsWith('[') && (!line.includes('.') || isRepeatedNode)) {
nodeIndex++
}
nodeLines.push(nodeIndex)
Expand Down

0 comments on commit 7b794d4

Please sign in to comment.