Reputation: 7
I am new in solidity and General with coding. i use this : Truffle v5.5.21 (core: 5.5.21) ,Ganache v7.2.0,Solidity v0.5.16 (solc-js) Node v12.22.12,Web3.js v1.7.4.
I took this error and i cant fix it. I checked more interesting information's about my project but the problem is problem...I would be grateful if I could have some help
(in terminal) CompileError: test:/contracts/EmailRegex.sol:49:34: ParserError: Expected ',' but got identifier cur = state(cur).func(uint c);
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.4.22 <0.9.0;
library EmailRegex {
struct State {
bool accepts;
function (byte) internal pure returns (uint) func;
}
function state(uint id) internal pure returns (State memory) {
if (id == 1) {
return State(false, s1);
}
if (id == 2) {
return State(false, s2);
}
if (id == 3) {
return State(false, s3);
}
if (id == 4) {
return State(false, s4);
}
if (id == 5) {
return State(false, s5);
}
if (id == 6) {
return State(false, s6);
}
if (id == 7) {
return State(false, s7);
}
if (id == 8) {
return State(false, s8);
}
if (id == 9) {
return State(true, s9);
}
if (id == 10) {
return State(true, s10);
}
}
function matches(string memory input) public pure returns (bool) {
uint cur = 1;
for (uint i = 0; i < bytes(input).length; i++) {
uint8 c = uint8(bytes(input)[i]);
cur = state(cur).func(uint c);
if (cur == 0) {
return false;
}
}
return state(cur).accepts;
}
function s1(uint8 c) internal pure returns (uint) {
if (c == 37 || c == 43 || c == 45 || c == 46 || c == 57 || c >= 65 && c <= 90 || c == 95 || c >= 97 && c <= 122) {
return 2;
}
return 0;
}
function s2(uint8 c) internal pure returns (uint) {
if (c == 37 || c == 43 || c == 45 || c == 46 || c >= 48 && c <= 57 || c >= 65 && c <= 90 || c == 95 || c >= 97 && c <= 122) {
return 3;
}
if (c == 64) {
return 4;
}
return 0;
}
function s3(uint8 c) internal pure returns (uint) {
if (c == 37 || c == 43 || c == 45 || c == 46 || c >= 48 && c <= 57 || c >= 65 && c <= 90 || c == 95 || c >= 97 && c <= 122) {
return 3;
}
if (c == 64) {
return 4;
}
return 0;
}
function s4(uint8 c) internal pure returns (uint) {
if (c >= 46 && c <= 47 || c >= 48 && c <= 57 || c >= 58 && c <= 64 || c >= 65 && c <= 90 || c >= 91 && c <= 95 || c >= 97 && c <= 122) {
return 5;
}
return 0;
}
function s5(uint8 c) internal pure returns (uint) {
if (c == 46) {
return 6;
}
if (c == 47 || c >= 48 && c <= 57 || c >= 58 && c <= 64 || c >= 65 && c <= 90 || c >= 91 && c <= 95 || c >= 97 && c <= 122) {
return 7;
}
return 0;
}
function s6(uint8 c) internal pure returns (uint) {
if (c == 46) {
return 6;
}
if (c == 47 || c >= 48 && c <= 57 || c >= 58 && c <= 64 || c >= 91 && c <= 95) {
return 7;
}
if (c >= 65 && c <= 90 || c >= 97 && c <= 122) {
return 8;
}
return 0;
}
function s7(uint8 c) internal pure returns (uint) {
if (c == 46) {
return 6;
}
if (c == 47 || c >= 48 && c <= 57 || c >= 58 && c <= 64 || c >= 65 && c <= 90 || c >= 91 && c <= 95 || c >= 97 && c <= 122) {
return 7;
}
return 0;
}
function s8(uint8 c) internal pure returns (uint) {
if (c == 46) {
return 6;
}
if (c == 47 || c >= 48 && c <= 57 || c >= 58 && c <= 64 || c >= 91 && c <= 95) {
return 7;
}
if (c >= 65 && c <= 90 || c >= 97 && c <= 122) {
return 9;
}
return 0;
}
function s9(uint8 c) internal pure returns (uint) {
if (c == 46) {
return 6;
}
if (c == 47 || c >= 48 && c <= 57 || c >= 58 && c <= 64 || c >= 91 && c <= 95) {
return 7;
}
if (c >= 65 && c <= 90 || c >= 97 && c <= 122) {
return 10;
}
return 0;
}
function s10(uint8 c) internal pure returns (uint) {
if (c == 46) {
return 6;
}
if (c == 47 || c >= 48 && c <= 57 || c >= 58 && c <= 64 || c >= 91 && c <= 95) {
return 7;
}
if (c >= 65 && c <= 90 || c >= 97 && c <= 122) {
return 10;
}
return 0;
}
}
Upvotes: 0
Views: 144
Reputation: 1326
Lets see your code:
cur = state(cur).func(uint c);
You are defining the input variable inside the function parameter, you can't do that, try the following:
byte c; // remember to set the value you see fit.
cur = state(cur).func(c);
I suggest you also check the rest of your code, since for some reason, you're also defining c in this loop, and variables are only defined once, yet you can reassign its value later on.
for (uint i = 0; i < bytes(input).length; i++) {
uint8 c = uint8(bytes(input)[i]);
if (cur == 0) {
return false;
}
}
Also, the interface for the function you specified on your struct's interface has a byte
type input.
struct State {
bool accepts;
function (byte) internal pure returns (uint) func;
}
But, your sX functions has a uint8
input type instead. This will also cause error's
Can't see any other issues so far, yet I haven't tried compiling it.
Upvotes: 1