Skip to content

Commit

Permalink
fix(backend/parse): allow ref with postfix bond now
Browse files Browse the repository at this point in the history
Closes #9.
  • Loading branch information
ForkKILLET committed Jan 21, 2023
1 parent c4b1fb5 commit 19771a3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion backend/core/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ export class ChemParser extends Parser<Formula> {

if (! inCharset(this.current, BondCharset)) {
if (requirePrefix) throw this.expect('prefix-styled bond')
if (inCharset(this.current, GroupCharset)) {
if (inCharset(this.current, GroupCharset) || this.current === '&') {
const n = this.doParseStruct({ dirFrom: null })
const { c, d, a } = this.doParseBondType({ isPrefix: false, parsedBonds, dirFrom })
bond = { c, d, a, n }
Expand Down
1 change: 1 addition & 0 deletions backend/test/testcases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export default [
[ "A{&:1}; &1-&1", Error("Self-loop on ref &1") ],
[ "A{&:1}; &1-B|C!D!|&1", "<svg width=\"84\" height=\"84\" viewBox=\"0 0 84 84\"><line x1=\"32\" y1=\"56\" x2=\"52\" y2=\"56\"></line><line x1=\"58\" y1=\"48\" x2=\"58\" y2=\"28\"></line><line x1=\"52\" y1=\"20\" x2=\"32\" y2=\"20\"></line><line x1=\"26\" y1=\"28\" x2=\"26\" y2=\"48\"></line><text x=\"26\" y=\"56\">A</text><rect group-id=\"0\" fill=\"none\" x=\"20\" y=\"48\" width=\"12\" height=\"16\"></rect><text x=\"58\" y=\"56\">B</text><rect group-id=\"1\" fill=\"none\" x=\"52\" y=\"48\" width=\"12\" height=\"16\"></rect><text x=\"58\" y=\"20\">C</text><rect group-id=\"2\" fill=\"none\" x=\"52\" y=\"12\" width=\"12\" height=\"16\"></rect><text x=\"26\" y=\"20\">D</text><rect group-id=\"3\" fill=\"none\" x=\"20\" y=\"12\" width=\"12\" height=\"16\"></rect><rect group-id=\"-1\" fill=\"none\" x=\"20\" y=\"56\" width=\"12\" height=\"16\"></rect></svg>" ],
[ "A[B/,\\&1]; D[C{&:1}/,\\E]", "<svg width=\"117.85640646055103\" height=\"72.24871130596429\" viewBox=\"0 0 117.85640646055103 72.24871130596429\"><line x1=\"39\" y1=\"28\" x2=\"29\" y2=\"45.3205081\"></line><line x1=\"45.9282032\" y1=\"28\" x2=\"55.9282032\" y2=\"45.3205081\"></line><line x1=\"62.3923048\" y1=\"44.2487113\" x2=\"72.3923048\" y2=\"26.9282032\"></line><line x1=\"78.8564065\" y1=\"28\" x2=\"88.8564065\" y2=\"45.3205081\"></line><text x=\"42.4641016\" y=\"20\">A</text><rect group-id=\"0\" fill=\"none\" x=\"36.4641016\" y=\"12\" width=\"12\" height=\"16\"></rect><text x=\"26\" y=\"52.2487113\">B</text><rect group-id=\"1\" fill=\"none\" x=\"20\" y=\"44.2487113\" width=\"12\" height=\"16\"></rect><text x=\"58.9282032\" y=\"52.2487113\">C</text><rect group-id=\"3\" fill=\"none\" x=\"52.9282032\" y=\"44.2487113\" width=\"12\" height=\"16\"></rect><text x=\"75.3923048\" y=\"20\">D</text><rect group-id=\"2\" fill=\"none\" x=\"69.3923048\" y=\"12\" width=\"12\" height=\"16\"></rect><text x=\"91.8564065\" y=\"52.2487113\">E</text><rect group-id=\"4\" fill=\"none\" x=\"85.8564065\" y=\"44.2487113\" width=\"12\" height=\"16\"></rect></svg>" ],
[ "A[B/,\\C{&:1}]; D[&1/,\\E]", "<svg width=\"117.85640646055103\" height=\"72.24871130596429\" viewBox=\"0 0 117.85640646055103 72.24871130596429\"><line x1=\"39\" y1=\"28\" x2=\"29\" y2=\"45.3205081\"></line><line x1=\"45.9282032\" y1=\"28\" x2=\"55.9282032\" y2=\"45.3205081\"></line><line x1=\"62.3923048\" y1=\"44.2487113\" x2=\"72.3923048\" y2=\"26.9282032\"></line><line x1=\"78.8564065\" y1=\"28\" x2=\"88.8564065\" y2=\"45.3205081\"></line><text x=\"42.4641016\" y=\"20\">A</text><rect group-id=\"0\" fill=\"none\" x=\"36.4641016\" y=\"12\" width=\"12\" height=\"16\"></rect><text x=\"26\" y=\"52.2487113\">B</text><rect group-id=\"1\" fill=\"none\" x=\"20\" y=\"44.2487113\" width=\"12\" height=\"16\"></rect><text x=\"58.9282032\" y=\"52.2487113\">C</text><rect group-id=\"2\" fill=\"none\" x=\"52.9282032\" y=\"44.2487113\" width=\"12\" height=\"16\"></rect><text x=\"75.3923048\" y=\"20\">D</text><rect group-id=\"3\" fill=\"none\" x=\"69.3923048\" y=\"12\" width=\"12\" height=\"16\"></rect><text x=\"91.8564065\" y=\"52.2487113\">E</text><rect group-id=\"4\" fill=\"none\" x=\"85.8564065\" y=\"44.2487113\" width=\"12\" height=\"16\"></rect></svg>" ],
[ "A[-C{&:1},|B{&:2}]; D{&:3};\n&1|&3; &2-&3", "<svg width=\"84\" height=\"84\" viewBox=\"0 0 84 84\"><line x1=\"32\" y1=\"56\" x2=\"52\" y2=\"56\"></line><line x1=\"58\" y1=\"48\" x2=\"58\" y2=\"28\"></line><line x1=\"52\" y1=\"20\" x2=\"32\" y2=\"20\"></line><line x1=\"26\" y1=\"28\" x2=\"26\" y2=\"48\"></line><text x=\"26\" y=\"56\">A</text><rect group-id=\"0\" fill=\"none\" x=\"20\" y=\"48\" width=\"12\" height=\"16\"></rect><text x=\"58\" y=\"56\">C</text><rect group-id=\"1\" fill=\"none\" x=\"52\" y=\"48\" width=\"12\" height=\"16\"></rect><text x=\"58\" y=\"20\">D</text><rect group-id=\"3\" fill=\"none\" x=\"52\" y=\"12\" width=\"12\" height=\"16\"></rect><text x=\"26\" y=\"20\">B</text><rect group-id=\"2\" fill=\"none\" x=\"20\" y=\"12\" width=\"12\" height=\"16\"></rect><rect group-id=\"-1\" fill=\"none\" x=\"20\" y=\"56\" width=\"12\" height=\"16\"></rect></svg>" ],
[ ".{ref:1}|.~/.~\\.!|.!~/.!~\\&1", "<svg width=\"85.83716857408417\" height=\"80\" viewBox=\"0 0 85.83716857408417 80\"><line x1=\"31.1961524\" y1=\"50\" x2=\"31.1961524\" y2=\"30\"></line><line x1=\"31.1961524\" y1=\"30\" x2=\"48.5166605\" y2=\"20\"></line><line x1=\"48.5166605\" y1=\"20\" x2=\"65.8371686\" y2=\"30\"></line><line x1=\"65.8371686\" y1=\"30\" x2=\"65.8371686\" y2=\"50\"></line><line x1=\"65.8371686\" y1=\"50\" x2=\"48.5166605\" y2=\"60\"></line><line x1=\"48.5166605\" y1=\"60\" x2=\"31.1961524\" y2=\"50\"></line><rect x=\"31.1961524\" y=\"42\" width=\"0\" height=\"16\" mask=\"\"></rect><text x=\"31.1961524\" y=\"50\"></text><rect group-id=\"0\" fill=\"none\" x=\"31.1961524\" y=\"42\" width=\"0\" height=\"16\"></rect><rect x=\"31.1961524\" y=\"22\" width=\"0\" height=\"16\" mask=\"\"></rect><text x=\"31.1961524\" y=\"30\"></text><rect group-id=\"1\" fill=\"none\" x=\"31.1961524\" y=\"22\" width=\"0\" height=\"16\"></rect><rect x=\"48.5166605\" y=\"12\" width=\"0\" height=\"16\" mask=\"\"></rect><text x=\"48.5166605\" y=\"20\"></text><rect group-id=\"2\" fill=\"none\" x=\"48.5166605\" y=\"12\" width=\"0\" height=\"16\"></rect><rect x=\"65.8371686\" y=\"22\" width=\"0\" height=\"16\" mask=\"\"></rect><text x=\"65.8371686\" y=\"30\"></text><rect group-id=\"3\" fill=\"none\" x=\"65.8371686\" y=\"22\" width=\"0\" height=\"16\"></rect><rect x=\"65.8371686\" y=\"42\" width=\"0\" height=\"16\" mask=\"\"></rect><text x=\"65.8371686\" y=\"50\"></text><rect group-id=\"4\" fill=\"none\" x=\"65.8371686\" y=\"42\" width=\"0\" height=\"16\"></rect><rect x=\"48.5166605\" y=\"52\" width=\"0\" height=\"16\" mask=\"\"></rect><text x=\"48.5166605\" y=\"60\"></text><rect group-id=\"5\" fill=\"none\" x=\"48.5166605\" y=\"52\" width=\"0\" height=\"16\"></rect><rect group-id=\"-1\" fill=\"none\" x=\"20\" y=\"38\" width=\"12\" height=\"16\"></rect></svg>" ],
[ ".{&:1}[|C*H3]~=\\{S:R}.{&:a2}!|.!~=/{S:R}.{&:a1}~!\\.=|{S:R}.{&:a3}~/&1;\n&a1!|NO2;\n&a2~NO2;\n&a3!~O2N", "<svg width=\"167.67433714816835\" height=\"136\" viewBox=\"0 0 167.67433714816835 136\"><line x1=\"83.8371686\" y1=\"48\" x2=\"83.8371686\" y2=\"28\"></line><line x1=\"89.8371686\" y1=\"20\" x2=\"89.8371686\" y2=\"20\"></line><line x1=\"83.8371686\" y1=\"48\" x2=\"101.1576766\" y2=\"58\"></line><line x1=\"82.3371686\" y1=\"50.5980762\" x2=\"99.6576766\" y2=\"60.5980762\"></line><line x1=\"101.1576766\" y1=\"58\" x2=\"101.1576766\" y2=\"78\"></line><line x1=\"101.1576766\" y1=\"78\" x2=\"83.8371686\" y2=\"88\"></line><line x1=\"99.6576766\" y1=\"75.4019238\" x2=\"82.3371686\" y2=\"85.4019238\"></line><line x1=\"83.8371686\" y1=\"88\" x2=\"66.5166605\" y2=\"78\"></line><line x1=\"66.5166605\" y1=\"78\" x2=\"66.5166605\" y2=\"58\"></line><line x1=\"69.5166605\" y1=\"78\" x2=\"69.5166605\" y2=\"58\"></line><line x1=\"66.5166605\" y1=\"58\" x2=\"83.8371686\" y2=\"48\"></line><line x1=\"66.5166605\" y1=\"58\" x2=\"49.1961524\" y2=\"48\"></line><line x1=\"83.8371686\" y1=\"88\" x2=\"83.8371686\" y2=\"108\"></line><line x1=\"101.1576766\" y1=\"58\" x2=\"118.4781847\" y2=\"48\"></line><rect x=\"83.8371686\" y=\"40\" width=\"0\" height=\"16\" mask=\"\"></rect><text x=\"83.8371686\" y=\"48\"></text><rect group-id=\"0\" fill=\"none\" x=\"83.8371686\" y=\"40\" width=\"0\" height=\"16\"></rect><text x=\"83.8371686\" y=\"20\">C</text><rect group-id=\"1\" fill=\"none\" x=\"77.8371686\" y=\"12\" width=\"12\" height=\"16\"></rect><text x=\"95.8371686\" y=\"20\">H</text><text x=\"104.8371686\" y=\"20\" box-align=\"sub\">3</text><rect group-id=\"2\" fill=\"none\" x=\"89.8371686\" y=\"12\" width=\"18\" height=\"16\"></rect><rect x=\"101.1576766\" y=\"50\" width=\"0\" height=\"16\" mask=\"\"></rect><text x=\"101.1576766\" y=\"58\"></text><rect group-id=\"3\" fill=\"none\" x=\"101.1576766\" y=\"50\" width=\"0\" height=\"16\"></rect><rect x=\"101.1576766\" y=\"70\" width=\"0\" height=\"16\" mask=\"\"></rect><text x=\"101.1576766\" y=\"78\"></text><rect group-id=\"4\" fill=\"none\" x=\"101.1576766\" y=\"70\" width=\"0\" height=\"16\"></rect><rect x=\"83.8371686\" y=\"80\" width=\"0\" height=\"16\" mask=\"\"></rect><text x=\"83.8371686\" y=\"88\"></text><rect group-id=\"5\" fill=\"none\" x=\"83.8371686\" y=\"80\" width=\"0\" height=\"16\"></rect><rect x=\"66.5166605\" y=\"70\" width=\"0\" height=\"16\" mask=\"\"></rect><text x=\"66.5166605\" y=\"78\"></text><rect group-id=\"6\" fill=\"none\" x=\"66.5166605\" y=\"70\" width=\"0\" height=\"16\"></rect><rect x=\"66.5166605\" y=\"50\" width=\"0\" height=\"16\" mask=\"\"></rect><text x=\"66.5166605\" y=\"58\"></text><rect group-id=\"7\" fill=\"none\" x=\"66.5166605\" y=\"50\" width=\"0\" height=\"16\"></rect><rect group-id=\"-1\" fill=\"none\" x=\"83.033321\" y=\"36\" width=\"12\" height=\"16\"></rect><text x=\"26\" y=\"44\">O</text><text x=\"35\" y=\"44\" box-align=\"sub\">2</text><text x=\"44\" y=\"44\">N</text><rect group-id=\"10\" fill=\"none\" x=\"20\" y=\"36\" width=\"30\" height=\"16\"></rect><text x=\"83.8371686\" y=\"116\">N</text><text x=\"95.8371686\" y=\"116\">O</text><text x=\"104.8371686\" y=\"116\" box-align=\"sub\">2</text><rect group-id=\"8\" fill=\"none\" x=\"77.8371686\" y=\"108\" width=\"30\" height=\"16\"></rect><text x=\"123.6743371\" y=\"44\">N</text><text x=\"135.6743371\" y=\"44\">O</text><text x=\"144.6743371\" y=\"44\" box-align=\"sub\">2</text><rect group-id=\"9\" fill=\"none\" x=\"117.6743371\" y=\"36\" width=\"30\" height=\"16\"></rect></svg>" ],
Expand Down

0 comments on commit 19771a3

Please sign in to comment.