diff --git a/src/index.js b/src/index.js index 3cdeac5..22c3c52 100644 --- a/src/index.js +++ b/src/index.js @@ -1,8 +1,12 @@ import { parseInput } from './parser.js'; import { traverseResult } from './visitor.js'; -import { createMany } from './createStruct.js'; +import { createMany, create } from './createStruct.js'; import { currentArch } from './currentArch.js'; export function compile(str, arch = currentArch, BufferImpl = Buffer) { return createMany(traverseResult(parseInput(str).cstOutput), arch, BufferImpl); } + +export function fromConfig(config, arch = currentArch, BufferImpl = Buffer) { + return create(config, arch, BufferImpl); +} diff --git a/src/trie.js b/src/trie.js index 756f770..6e0304b 100644 --- a/src/trie.js +++ b/src/trie.js @@ -42,7 +42,12 @@ export class Trie { i = skipWhitespace(text, i) - 1; } if (current.isEnd) { - res = [text.slice(startOffset, i + 1)]; + if (i < text.length - 1 && /\w/.test(text[i + 1])) { + continue; + } + else { + res = [text.slice(startOffset, i + 1)]; + } } } return res; diff --git a/test/dataTypes.test.js b/test/dataTypes.test.js index e3c6707..8204dd3 100644 --- a/test/dataTypes.test.js +++ b/test/dataTypes.test.js @@ -7,7 +7,7 @@ test('matchType', (t) => { assert.deepEqual(matchType('unsigned long', 0), ['unsigned long']); assert.deepEqual(matchType('uint32_t', 0), ['uint32_t']); - const withPadding = 'AAAAAAAAAAAA unsigned \n\nlong longAAAAAAAA'; + const withPadding = 'AAAAAAAAAAAA unsigned \n\nlong long AAAAAAAA'; assert.deepEqual(matchType(withPadding, withPadding.indexOf('u')), ['unsigned \n\nlong long']); assert.deepEqual(matchType('uint;32_t'), null);