diff --git a/packages/bbob-parser/src/lexer.js b/packages/bbob-parser/src/lexer.js index d9090676..3900ffad 100644 --- a/packages/bbob-parser/src/lexer.js +++ b/packages/bbob-parser/src/lexer.js @@ -235,6 +235,8 @@ function createLexer(buffer, options = {}) { const tagGrabber = createCharGrabber(tagStr, { onSkip }); const hasSpace = tagGrabber.includes(SPACE); + tagMode = TAG_STATE_NAME; + while (tagGrabber.hasNext()) { tagMode = nextTagState(tagGrabber, !hasSpace); } @@ -307,6 +309,8 @@ function createLexer(buffer, options = {}) { } function tokenize() { + stateMode = STATE_WORD; + while (chars.hasNext()) { switch (stateMode) { case STATE_TAG: diff --git a/packages/bbob-parser/test/lexer.test.js b/packages/bbob-parser/test/lexer.test.js index d585793a..85e1c85a 100644 --- a/packages/bbob-parser/test/lexer.test.js +++ b/packages/bbob-parser/test/lexer.test.js @@ -122,6 +122,43 @@ describe('lexer', () => { expect(tokens).toBeMantchOutput(output); }); + test('tags with single word and camel case params', () => { + const input = `[url href="/groups/123/" isNowrap=true isTextOverflow=true state=primary] + [avatar href="/avatar/4/3/b/1606.jpg@20x20?cache=1561462725&bgclr=ffffff" size=xs][/avatar] + Group Name Go[/url] `; + const tokens = tokenize(input); + + const output = [ + [TYPE.TAG, 'url', '0', '0'], + [TYPE.ATTR_NAME, 'href', '0', '0'], + [TYPE.ATTR_VALUE, '/groups/123/', '0', '0'], + [TYPE.ATTR_NAME, 'isNowrap', '0', '0'], + [TYPE.ATTR_VALUE, 'true', '0', '0'], + [TYPE.ATTR_NAME, 'isTextOverflow', '0', '0'], + [TYPE.ATTR_VALUE, 'true', '0', '0'], + [TYPE.ATTR_NAME, 'state', '0', '0'], + [TYPE.ATTR_VALUE, 'primary', '0', '0'], + [TYPE.NEW_LINE, '\n', '0', '0'], + [TYPE.SPACE, ' ', '0', '0'], + [TYPE.TAG, 'avatar', '0', '0'], + [TYPE.ATTR_NAME, 'href', '0', '0'], + [TYPE.ATTR_VALUE, '/avatar/4/3/b/1606.jpg@20x20?cache=1561462725&bgclr=ffffff', '0', '0'], + [TYPE.ATTR_NAME, 'size', '0', '0'], + [TYPE.ATTR_VALUE, 'xs', '0', '0'], + [TYPE.TAG, '/avatar', '0', '0'], + [TYPE.NEW_LINE, '\n', '0', '0'], + [TYPE.SPACE, ' ', '0', '0'], + [TYPE.WORD, 'Group', '0', '0'], + [TYPE.SPACE, ' ', '0', '0'], + [TYPE.WORD, 'Name', '0', '0'], + [TYPE.SPACE, ' ', '0', '0'], + [TYPE.WORD, 'Go', '0', '0'], + [TYPE.TAG, '/url', '0', '0'], + [TYPE.SPACE, ' ', '0', '0'], + ]; + + expect(tokens).toBeMantchOutput(output); + }); test('string with quotemarks', () => { const input = '"Someone Like You" by Adele'; diff --git a/packages/bbob-parser/test/parse.test.js b/packages/bbob-parser/test/parse.test.js index 4623f70a..6f5c173d 100644 --- a/packages/bbob-parser/test/parse.test.js +++ b/packages/bbob-parser/test/parse.test.js @@ -214,6 +214,44 @@ describe('Parser', () => { ]); }); + test('parse tag with camelCase params', () => { + const ast = parse(`[url href="/groups/123/" isNowrap=true isTextOverflow=true state=primary] + [avatar href="/avatar/4/3/b/1606.jpg@20x20?cache=1561462725&bgclr=ffffff" size=xs][/avatar] + Group Name Go[/url] `); + + expectOutput(ast, [ + { + tag: 'url', + attrs: { + href: '/groups/123/', + isNowrap: 'true', + isTextOverflow: 'true', + state: 'primary' + }, + content: [ + '\n', + ' ', + { + tag: 'avatar', + attrs: { + href: '/avatar/4/3/b/1606.jpg@20x20?cache=1561462725&bgclr=ffffff', + size: 'xs' + }, + content: [] + }, + '\n', + ' ', + 'Group', + ' ', + 'Name', + ' ', + 'Go', + ], + }, + ' ', + ]); + }); + test('parse url tag with # and = symbols [google docs]', () => { const ast = parse('[url href=https://docs.google.com/spreadsheets/d/1W9VPUESF_NkbSa_HtRFrQNl0nYo8vPCxJFy7jD3Tpio/edit#gid=0]Docs[/url]');