feat(frontends/lean/scanner): add more checks to read_quoted_symbol

This commit is contained in:
Sebastian Ullrich 2015-10-09 18:09:42 +02:00 committed by Leonardo de Moura
parent 6c34718cbc
commit dbfebd5409
3 changed files with 32 additions and 8 deletions

View file

@ -150,18 +150,32 @@ auto scanner::read_quoted_symbol() -> token_kind {
if (std::isdigit(curr())) if (std::isdigit(curr()))
throw_exception("first character of a quoted symbols cannot be a digit"); throw_exception("first character of a quoted symbols cannot be a digit");
m_buffer.clear(); m_buffer.clear();
bool start = true;
bool trailing_space = false;
while (true) { while (true) {
check_not_eof("unexpected quoted identifier"); check_not_eof("unexpected quoted identifier");
char c = curr(); char c = curr();
next(); next();
if (c == '`') { switch (c) {
m_name_val = name(m_buffer.c_str()); case '`':
return token_kind::QuotedSymbol; if (start)
} else if (c != '\"' && c != '\n' && c != '\t') { throw_exception("unexpected end of quoted symbol");
m_buffer += c; m_name_val = name(m_buffer.c_str());
} else { return token_kind::QuotedSymbol;
// TODO(Leo): intra-token space case '\"':
throw_exception("invalid quoted symbol, invalid character"); case '\n':
case '\t':
throw_exception("invalid quoted symbol, invalid character");
case ' ':
if (!start)
trailing_space = true;
m_buffer += c;
break;
default:
start = false;
if (trailing_space)
throw_exception("unexpected space inside of quoted symbol");
m_buffer += c;
} }
} }
} }

View file

@ -0,0 +1,5 @@
notation a ` \/ ` b := a b
notation a `1\/` b := a b
notation a ` \ / ` b := a b
notation a ` ` b := a b
notation `

View file

@ -0,0 +1,5 @@
tests/lean/bad_quoted_symbol.lean:2:12: error: first character of a quoted symbols cannot be a digit
tests/lean/bad_quoted_symbol.lean:3:16: error: unexpected space inside of quoted symbol
tests/lean/bad_quoted_symbol.lean:4:14: error: unexpected end of quoted symbol
tests/lean/bad_quoted_symbol.lean:5:10: error: invalid quoted symbol, invalid character
tests/lean/bad_quoted_symbol.lean:5:10: error: invalid notation declaration, symbol expected