raineorshine/solgraph

Parse Error when pragma statement includes Logical OR (||) operator

liamgoss opened this issue · 2 comments

The code that causes the error:

pragma solidity ^0.6.6 || >=0.7.5 || ^0.8.0;

The error:

peg$SyntaxError: Expected "!=", "0", ";", "<", "<=", "==", ">", ">=", "^", "v", [1-9], comment, end of line, or whitespace but "|" found. Line: 2, Column: 24
    at peg$buildStructuredError (/usr/local/lib/node_modules/solgraph/node_modules/solidity-parser-sc/build/parser.js:1376:12)
    at Object.peg$parse [as parse] (/usr/local/lib/node_modules/solgraph/node_modules/solidity-parser-sc/build/parser.js:15723:11)
    at Object.parse (/usr/local/lib/node_modules/solgraph/node_modules/solidity-parser-sc/index.js:34:23)
    at _default (/usr/local/lib/node_modules/solgraph/dist/index.js:91:21)
    at /usr/local/lib/node_modules/solgraph/dist/bin.js:29:37 {
  expected: [
    { type: 'other', description: 'whitespace' },
    { type: 'other', description: 'end of line' },
    { type: 'other', description: 'comment' },
    { type: 'literal', text: '<=', ignoreCase: false },
    { type: 'literal', text: '>=', ignoreCase: false },
    { type: 'literal', text: '<', ignoreCase: false },
    { type: 'literal', text: '>', ignoreCase: false },
    { type: 'literal', text: '==', ignoreCase: false },
    { type: 'literal', text: '!=', ignoreCase: false },
    { type: 'literal', text: '^', ignoreCase: false },
    { type: 'other', description: 'whitespace' },
    { type: 'other', description: 'end of line' },
    { type: 'other', description: 'comment' },
    { type: 'literal', text: 'v', ignoreCase: false },
    { type: 'literal', text: '0', ignoreCase: false },
    {
      type: 'class',
      parts: [Array],
      inverted: false,
      ignoreCase: false
    },
    { type: 'other', description: 'whitespace' },
    { type: 'other', description: 'end of line' },
    { type: 'other', description: 'comment' },
    { type: 'literal', text: ';', ignoreCase: false }
  ],
  found: '|',
  location: {
    start: { offset: 55, line: 2, column: 24 },
    end: { offset: 56, line: 2, column: 25 }
  }
}

It's possible that this error is restricted to smart contracts developed using Hardhat, specifically when multiple Solidity versions are required within one contract (such as two different dependencies needing say 0.6.0 and ^0.8.0 which can't be satisfied without ||).

Hi, thanks for reporting. The parser needs to be updated from solidity-parser-sc to solidity-parser-antlr or another parser that supports the latest solc. I am no longer actively working on this project myself but I would be happy to support a PR from anyone who is interested in contributing.

Fixed in v1.0.0. Special thanks to @yellowBirdy.