@@ -34,21 +34,13 @@ using namespace std;
34
34
35
35
namespace
36
36
{
37
- bool isDecimalDigit (char c)
38
- {
39
- return ' 0' <= c && c <= ' 9' ;
40
- }
41
- bool isWhiteSpace (char c)
42
- {
43
- return c == ' ' || c == ' \n ' || c == ' \t ' || c == ' \r ' ;
44
- }
45
37
bool isIdentifierStart (char c)
46
38
{
47
39
return c == ' _' || c == ' $' || (' a' <= c && c <= ' z' ) || (' A' <= c && c <= ' Z' );
48
40
}
49
41
bool isIdentifierPart (char c)
50
42
{
51
- return isIdentifierStart (c) || isDecimalDigit (c);
43
+ return isIdentifierStart (c) || isdigit (c);
52
44
}
53
45
}
54
46
@@ -57,33 +49,41 @@ vector<dev::solidity::test::FunctionCall> TestFileParser::parseFunctionCalls()
57
49
vector<FunctionCall> calls;
58
50
if (!accept (SoltToken::EOS))
59
51
{
60
- // TODO: check initial token state
61
- expect (SoltToken::Unknown);
52
+ assert (m_scanner.currentToken () == SoltToken::Unknown);
53
+ m_scanner.scanNextToken ();
54
+
62
55
while (!accept (SoltToken::EOS))
63
56
{
64
57
if (!accept (SoltToken::Whitespace))
65
58
{
66
59
FunctionCall call;
67
60
68
- expect (SoltToken::Newline);
69
- call.signature = parseFunctionSignature ();
61
+ // / If this is not the first call in the test,
62
+ // / the last call to parseParameter could have eaten the
63
+ // / new line already. This could only be fixed with a one
64
+ // / token lookahead that checks parseParameter
65
+ // / if the next token is an identifier.
66
+ if (calls.empty ())
67
+ expect (SoltToken::Newline);
68
+ else
69
+ accept (SoltToken::Newline, true );
70
70
71
+ call.signature = parseFunctionSignature ();
71
72
if (accept (SoltToken::Comma, true ))
72
73
call.value = parseFunctionCallValue ();
73
74
if (accept (SoltToken::Colon, true ))
74
75
call.arguments = parseFunctionCallArguments ();
75
76
76
- call.displayMode = parseNewline ();
77
+ if (accept (SoltToken::Newline, true ))
78
+ call.displayMode = FunctionCall::DisplayMode::MultiLine;
79
+
77
80
call.arguments .comment = parseComment ();
78
81
79
82
if (accept (SoltToken::Newline, true ))
80
83
call.displayMode = FunctionCall::DisplayMode::MultiLine;
81
- expect (SoltToken::Arrow);
82
84
85
+ expect (SoltToken::Arrow);
83
86
call.expectations = parseFunctionCallExpectations ();
84
-
85
- if (accept (SoltToken::Newline, false ))
86
- call.displayMode = parseNewline ();
87
87
call.expectations .comment = parseComment ();
88
88
89
89
calls.emplace_back (std::move (call));
@@ -121,12 +121,12 @@ bool TestFileParser::accept(SoltToken _token, bool const _expect)
121
121
bool TestFileParser::expect (SoltToken _token, bool const _advance)
122
122
{
123
123
if (m_scanner.currentToken () != _token)
124
- throw Error
125
- ( Error::Type::ParserError,
126
- " Unexpected " + formatToken (m_scanner.currentToken ()) + " : \" " +
127
- m_scanner.currentLiteral () + " \" . " +
128
- " Expected \" " + formatToken (_token) + " \" ."
129
- );
124
+ throw Error (
125
+ Error::Type::ParserError,
126
+ " Unexpected " + formatToken (m_scanner.currentToken ()) + " : \" " +
127
+ m_scanner.currentLiteral () + " \" . " +
128
+ " Expected \" " + formatToken (_token) + " \" ."
129
+ );
130
130
if (_advance)
131
131
m_scanner.scanNextToken ();
132
132
return true ;
@@ -143,13 +143,13 @@ string TestFileParser::parseFunctionSignature()
143
143
while (!accept (SoltToken::RParen))
144
144
{
145
145
signature += m_scanner.currentLiteral ();
146
- expect (SoltToken::UInt );
146
+ expect (SoltToken::Identifier );
147
147
while (accept (SoltToken::Comma))
148
148
{
149
149
signature += m_scanner.currentLiteral ();
150
150
expect (SoltToken::Comma);
151
151
signature += m_scanner.currentLiteral ();
152
- expect (SoltToken::UInt );
152
+ expect (SoltToken::Identifier );
153
153
}
154
154
}
155
155
signature += formatToken (SoltToken::RParen);
@@ -184,15 +184,18 @@ FunctionCallExpectations TestFileParser::parseFunctionCallExpectations()
184
184
185
185
auto param = parseParameter ();
186
186
if (param.abiType .type == ABIType::None)
187
+ {
188
+ expectations.failure = false ;
187
189
return expectations;
188
- expectations.parameters .emplace_back (param);
190
+ }
191
+ expectations.result .emplace_back (param);
189
192
190
193
while (accept (SoltToken::Comma, true ))
191
- expectations.parameters .emplace_back (parseParameter ());
194
+ expectations.result .emplace_back (parseParameter ());
192
195
193
196
// / We have always one virtual parameter in the parameter list.
194
197
// / If its type is FAILURE, the expected result is also a REVERT etc.
195
- if (expectations.parameters .at (0 ).abiType .type != ABIType::Failure)
198
+ if (expectations.result .at (0 ).abiType .type != ABIType::Failure)
196
199
expectations.failure = false ;
197
200
return expectations;
198
201
}
@@ -212,8 +215,9 @@ pair<bytes, ABIType> TestFileParser::parseABITypeLiteral()
212
215
{
213
216
try
214
217
{
215
- u256 number;
216
- ABIType abiType;
218
+ u256 number{0 };
219
+ ABIType abiType{ABIType::None, 0 };
220
+
217
221
if (accept (SoltToken::Sub))
218
222
{
219
223
abiType = ABIType{ABIType::SignedDec, 32 };
@@ -227,7 +231,7 @@ pair<bytes, ABIType> TestFileParser::parseABITypeLiteral()
227
231
abiType = ABIType{ABIType::UnsignedDec, 32 };
228
232
number = convertNumber (parseNumber ());
229
233
}
230
- if (accept (SoltToken::Failure, true ))
234
+ else if (accept (SoltToken::Failure, true ))
231
235
{
232
236
abiType = ABIType{ABIType::Failure, 0 };
233
237
return make_pair (bytes{}, abiType);
@@ -241,13 +245,6 @@ pair<bytes, ABIType> TestFileParser::parseABITypeLiteral()
241
245
}
242
246
}
243
247
244
- solidity::test::FunctionCall::DisplayMode TestFileParser::parseNewline ()
245
- {
246
- if (accept (SoltToken::Newline, true ))
247
- return FunctionCall::DisplayMode::MultiLine;
248
- return FunctionCall::DisplayMode::SingleLine;
249
- }
250
-
251
248
string TestFileParser::parseComment ()
252
249
{
253
250
string comment = m_scanner.currentLiteral ();
@@ -286,7 +283,6 @@ void TestFileParser::Scanner::scanNextToken()
286
283
{
287
284
auto detectToken = [](std::string const & _literal = " " ) -> TokenDesc {
288
285
if (_literal == " ether" ) return TokenDesc{SoltToken::Ether, _literal};
289
- if (_literal == " uint256" ) return TokenDesc{SoltToken::UInt, _literal};
290
286
if (_literal == " FAILURE" ) return TokenDesc{SoltToken::Failure, _literal};
291
287
return TokenDesc{SoltToken::Identifier, _literal};
292
288
};
@@ -336,9 +332,9 @@ void TestFileParser::Scanner::scanNextToken()
336
332
TokenDesc detectedToken = detectToken (scanIdentifierOrKeyword ());
337
333
token = selectToken (detectedToken.first , detectedToken.second );
338
334
}
339
- else if (isDecimalDigit (current ()))
335
+ else if (isdigit (current ()))
340
336
token = selectToken (SoltToken::Number, scanNumber ());
341
- else if (isWhiteSpace (current ()))
337
+ else if (isspace (current ()))
342
338
token = selectToken (SoltToken::Whitespace);
343
339
else if (isEndOfLine ())
344
340
token = selectToken (SoltToken::EOS);
@@ -348,8 +344,6 @@ void TestFileParser::Scanner::scanNextToken()
348
344
}
349
345
}
350
346
while (token.first == SoltToken::Whitespace);
351
-
352
- m_nextToken = token;
353
347
m_currentToken = token;
354
348
}
355
349
@@ -382,7 +376,7 @@ string TestFileParser::Scanner::scanNumber()
382
376
{
383
377
string number;
384
378
number += current ();
385
- while (isDecimalDigit (peek ()))
379
+ while (isdigit (peek ()))
386
380
{
387
381
advance ();
388
382
number += current ();
0 commit comments