From a99347e9f0b9b3a18da598dd49d5816e37d9f22e Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 7 Aug 2018 22:16:22 +0100 Subject: [PATCH 1/2] Yul grammar: allow multiple $ signs (matches Solidity) --- docs/yul.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/yul.rst b/docs/yul.rst index 87ec0c030..87fd95eb6 100644 --- a/docs/yul.rst +++ b/docs/yul.rst @@ -108,7 +108,7 @@ Grammar:: 'break' | 'continue' FunctionCall = Identifier '(' ( Expression ( ',' Expression )* )? ')' - Identifier = [a-zA-Z_$] [a-zA-Z_0-9]* + Identifier = [a-zA-Z_$] [a-zA-Z_$0-9]* IdentifierList = Identifier ( ',' Identifier)* TypeName = Identifier | BuiltinTypeName BuiltinTypeName = 'bool' | [us] ( '8' | '32' | '64' | '128' | '256' ) From 3064bd17bc9393d0761fa65ac64c152d7d02319c Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 7 Aug 2018 22:29:21 +0100 Subject: [PATCH 2/2] Assert that type identifier contains only valid characters --- libsolidity/ast/Types.cpp | 11 +++++++++++ libsolidity/ast/Types.h | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 3eccc6d42..abd3bd87e 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -254,6 +254,17 @@ string Type::escapeIdentifier(string const& _identifier) return ret; } +string Type::identifier() const +{ + string ret = escapeIdentifier(richIdentifier()); + solAssert(ret.find_first_of("0123456789") != 0, "Identifier cannot start with a number."); + solAssert( + ret.find_first_not_of("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMONPQRSTUVWXYZ_$") == string::npos, + "Identifier contains invalid characters." + ); + return ret; +} + TypePointer Type::fromElementaryTypeName(ElementaryTypeNameToken const& _type) { solAssert(Token::isElementaryTypeName(_type.token()), diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h index 09323d05a..1fa2b2f5c 100644 --- a/libsolidity/ast/Types.h +++ b/libsolidity/ast/Types.h @@ -172,7 +172,7 @@ public: /// only if they have the same identifier. /// The identifier should start with "t_". /// Will not contain any character which would be invalid as an identifier. - std::string identifier() const { return escapeIdentifier(richIdentifier()); } + std::string identifier() const; /// More complex identifier strings use "parentheses", where $_ is interpreted as as /// "opening parenthesis", _$ as "closing parenthesis", _$_ as "comma" and any $ that