Commit 0b7f3ab0 authored by Ing. Jan Trávníček's avatar Ing. Jan Trávníček

allow parsing of double in the cli

parent 3eedfe35
......@@ -181,9 +181,10 @@ q0: if ( m_source.getCharacter ( ) == EOF ) {
}
if ( m_source.getCharacter ( ) == '.' ) {
res.m_raw += static_cast < char > ( m_source.getCharacter ( ) );
res.m_value += static_cast < char > ( m_source.getCharacter ( ) );
m_source.advance ( readNextLine );
res.m_type = TokenType::DOT;
return res;
goto q14;
}
if ( m_source.getCharacter ( ) == '"' ) {
......@@ -226,6 +227,12 @@ q1: if ( m_source.getCharacter ( ) == '\0' ) {
res.m_value += static_cast < char > ( m_source.getCharacter ( ) );
m_source.advance ( readNextLine );
goto q1;
} else if ( m_source.getCharacter ( ) == '.' ) {
res.m_raw += static_cast < char > ( m_source.getCharacter ( ) );
res.m_value += static_cast < char > ( m_source.getCharacter ( ) );
m_source.advance ( readNextLine );
res.m_type = TokenType::DOUBLE;
goto q15;
} else {
res.m_type = TokenType::UNSIGNED;
return res;
......@@ -476,6 +483,39 @@ q13:
return res;
}
q14:
if ( m_source.getCharacter ( ) == EOF ) {
return res;
}
if ( m_source.getCharacter ( ) == '\0' ) {
return res;
}
if ( ( m_source.getCharacter ( ) >= '0' && m_source.getCharacter ( ) <= '9' ) ) {
res.m_raw += static_cast < char > ( m_source.getCharacter ( ) );
res.m_value += static_cast < char > ( m_source.getCharacter ( ) );
m_source.advance ( readNextLine );
res.m_type = TokenType::DOUBLE;
goto q15;
} else {
return res;
}
q15:
if ( m_source.getCharacter ( ) == EOF ) {
return res;
}
if ( m_source.getCharacter ( ) == '\0' ) {
return res;
}
if ( ( m_source.getCharacter ( ) >= '0' && m_source.getCharacter ( ) <= '9' ) ) {
res.m_raw += static_cast < char > ( m_source.getCharacter ( ) );
res.m_value += static_cast < char > ( m_source.getCharacter ( ) );
m_source.advance ( readNextLine );
goto q15;
} else {
return res;
}
qFile:
if ( m_source.getCharacter ( ) == EOF ) {
res.m_type = TokenType::EOT;
......
......@@ -29,6 +29,7 @@ public:
enum class TokenType : unsigned {
IDENTIFIER,
UNSIGNED,
DOUBLE,
STRING,
LESS_THAN,
......@@ -87,6 +88,8 @@ public:
return "identifier";
case TokenType::UNSIGNED :
return "unsigned";
case TokenType::DOUBLE :
return "double";
case TokenType::STRING :
return "string";
......@@ -197,9 +200,11 @@ public:
case TokenType::IDENTIFIER :
return res + ": " + m_value;
case TokenType::UNSIGNED :
return res + ": " + ext::to_string ( m_value );
return res + ": " + m_value;
case TokenType::DOUBLE :
return res + ": " + m_value;
case TokenType::STRING :
return res + ": \"" + ext::to_string ( m_value ) + "\"";
return res + ": \"" + m_value + "\"";
default:
return res;
}
......
......@@ -200,6 +200,9 @@ std::shared_ptr < Statement > Parser::common ( ) {
} else if ( check ( cli::Lexer::TokenType::UNSIGNED ) ) {
int value = matchInteger ( );
return std::make_shared < ImmediateStatement < int > > ( value );
} else if ( check ( cli::Lexer::TokenType::DOUBLE ) ) {
double value = matchDouble ( );
return std::make_shared < ImmediateStatement < double > > ( value );
} else if ( check_then_match ( cli::Lexer::TokenType::HASH_SIGN ) ) {
std::string value = getTokenValue ( );
match ( cli::Lexer::TokenType::UNSIGNED, cli::Lexer::TokenType::IDENTIFIER );
......@@ -221,7 +224,7 @@ std::shared_ptr < Statement > Parser::common ( ) {
std::shared_ptr < Statement > Parser::param ( ) {
clearCheckOptions ( );
if ( check ( cli::Lexer::TokenType::DOLLAR_SIGN, cli::Lexer::TokenType::LESS_THAN, cli::Lexer::TokenType::STRING, cli::Lexer::TokenType::UNSIGNED, cli::Lexer::TokenType::HASH_SIGN, cli::Lexer::TokenType::LEFT_BRACE ) ) {
if ( check ( cli::Lexer::TokenType::DOLLAR_SIGN, cli::Lexer::TokenType::LESS_THAN, cli::Lexer::TokenType::STRING, cli::Lexer::TokenType::UNSIGNED, cli::Lexer::TokenType::DOUBLE, cli::Lexer::TokenType::HASH_SIGN, cli::Lexer::TokenType::LEFT_BRACE ) ) {
return common ( );
} else if ( check_then_match ( cli::Lexer::TokenType::MINUS_SIGN ) ) {
return std::make_shared < PreviousResultStatement > ( );
......@@ -240,7 +243,7 @@ std::shared_ptr < Statement > Parser::param ( ) {
std::shared_ptr < Statement > Parser::statement ( ) {
clearCheckOptions ( );
if ( check ( cli::Lexer::TokenType::DOLLAR_SIGN, cli::Lexer::TokenType::LESS_THAN, cli::Lexer::TokenType::STRING, cli::Lexer::TokenType::UNSIGNED, cli::Lexer::TokenType::HASH_SIGN, cli::Lexer::TokenType::LEFT_BRACE ) ) {
if ( check ( cli::Lexer::TokenType::DOLLAR_SIGN, cli::Lexer::TokenType::LESS_THAN, cli::Lexer::TokenType::STRING, cli::Lexer::TokenType::UNSIGNED, cli::Lexer::TokenType::DOUBLE, cli::Lexer::TokenType::HASH_SIGN, cli::Lexer::TokenType::LEFT_BRACE ) ) {
return common ( );
} else if ( check ( cli::Lexer::TokenType::IDENTIFIER ) ) {
std::unique_ptr < Arg > name = std::make_unique < ImmediateArg > ( matchIdentifier ( ) );
......@@ -849,6 +852,9 @@ std::unique_ptr < Expression > Parser::atom ( ) {
} else if ( check ( cli::Lexer::TokenType::UNSIGNED ) ) {
int value = matchInteger ( );
return std::make_unique < ImmediateExpression < int > > ( value );
} else if ( check ( cli::Lexer::TokenType::DOUBLE ) ) {
double value = matchDouble ( );
return std::make_unique < ImmediateExpression < double > > ( value );
} else {
throw exception::CommonException ( "Mismatched set " + ext::to_string ( getCheckOptions ( ) ) + " while expanding prefix_expression and atom rules. Token is " + ( ( std::string ) m_current ) + "." );
}
......
......@@ -137,6 +137,14 @@ public:
return res;
}
double matchDouble ( ) {
if ( ! check ( Lexer::TokenType::DOUBLE ) )
throw exception::CommonException ( "Mismatched token while matching a double. Tokens in active set " + ext::to_string ( getCheckOptions ( ) ) + "." );
double res = ext::from_string < double > ( m_current.m_value );
m_current = m_lexer.nextToken ( m_forceLexerReadNext > 0 );
return res;
}
std::string getTokenValue ( ) {
return m_current.m_value;
}
......
  • I am a simple man. I see double, I upvote (where is the upvote button for commits?!).

    I dont think we use double anywhere except the automata generators (where integer suffices) but thank youu :-)

Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment