Reputation: 315
This is Ada 2012, using the GNAT IDE.
I am trying to test my project and I am getting the following error
bad input for 'Value: "x "
as the only output to the console. I think the issue comes from this function;
function get_next_id(lex: in out Lexical_Analyzer) return Id is
tok: Token := get_lookahead_token(lex);
tok_type: Token_Type := get_token_type(tok);
theId: Id;
begin
match(tok, ID_TOK);
get_next_token(lex, tok);
theId := create_id(Character'Value(String(get_lexeme(tok)))); -- Problem caused here?
return theId;
end get_next_id;
I think this is causing my problem, it seems to be trying to convert the x and the white space that follows. How do I get it to only read the first element?
Upvotes: 0
Views: 470
Reputation: 2715
The proper solution is to use a substring of length 1.
declare
S : constant String := Get_Lexeme (Tok);
begin
theId := Create_Id (S (S'First));
end;
Note the use of 'First instead of assuming the first character is at index 1.
Upvotes: 3