feat(frontends/lean/scanner): add more checks to read_quoted_symbol
This commit is contained in:
parent
6c34718cbc
commit
dbfebd5409
3 changed files with 32 additions and 8 deletions
|
@ -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) {
|
||||||
|
case '`':
|
||||||
|
if (start)
|
||||||
|
throw_exception("unexpected end of quoted symbol");
|
||||||
m_name_val = name(m_buffer.c_str());
|
m_name_val = name(m_buffer.c_str());
|
||||||
return token_kind::QuotedSymbol;
|
return token_kind::QuotedSymbol;
|
||||||
} else if (c != '\"' && c != '\n' && c != '\t') {
|
case '\"':
|
||||||
m_buffer += c;
|
case '\n':
|
||||||
} else {
|
case '\t':
|
||||||
// TODO(Leo): intra-token space
|
|
||||||
throw_exception("invalid quoted symbol, invalid character");
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
5
tests/lean/bad_quoted_symbol.lean
Normal file
5
tests/lean/bad_quoted_symbol.lean
Normal 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 `
|
5
tests/lean/bad_quoted_symbol.lean.expected.out
Normal file
5
tests/lean/bad_quoted_symbol.lean.expected.out
Normal 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
|
Loading…
Reference in a new issue