Browse Source

Change parsing for floats and disallow `x.0`

gingerBill 7 years ago
parent
commit
27b7dc336a
2 changed files with 10 additions and 4 deletions
  1. 3 3
      src/parser.cpp
  2. 7 1
      src/tokenizer.cpp

+ 3 - 3
src/parser.cpp

@@ -2106,9 +2106,9 @@ AstNode *parse_atom_expr(AstFile *f, AstNode *operand, bool lhs) {
 			case Token_Ident:
 			case Token_Ident:
 				operand = ast_selector_expr(f, token, operand, parse_ident(f));
 				operand = ast_selector_expr(f, token, operand, parse_ident(f));
 				break;
 				break;
-			case Token_Integer:
-				operand = ast_selector_expr(f, token, operand, parse_expr(f, lhs));
-				break;
+			// case Token_Integer:
+				// operand = ast_selector_expr(f, token, operand, parse_expr(f, lhs));
+				// break;
 			case Token_OpenParen: {
 			case Token_OpenParen: {
 				Token open = expect_token(f, Token_OpenParen);
 				Token open = expect_token(f, Token_OpenParen);
 				AstNode *type = parse_type(f);
 				AstNode *type = parse_type(f);

+ 7 - 1
src/tokenizer.cpp

@@ -536,6 +536,9 @@ Token scan_number_to_token(Tokenizer *t, bool seen_decimal_point) {
 	token.pos.column = t->curr-t->line+1;
 	token.pos.column = t->curr-t->line+1;
 
 
 	if (seen_decimal_point) {
 	if (seen_decimal_point) {
+		token.string.text -= 1;
+		token.string.len  += 1;
+		token.pos.column -= 1;
 		token.kind = Token_Float;
 		token.kind = Token_Float;
 		scan_mantissa(t, 10);
 		scan_mantissa(t, 10);
 		goto exponent;
 		goto exponent;
@@ -906,7 +909,6 @@ Token tokenizer_get_token(Tokenizer *t) {
 		} break;
 		} break;
 
 
 		case '.':
 		case '.':
-			token.kind = Token_Period; // Default
 			if (t->curr_rune == '.') { // Could be an ellipsis
 			if (t->curr_rune == '.') { // Could be an ellipsis
 				advance_to_next_rune(t);
 				advance_to_next_rune(t);
 				token.kind = Token_HalfClosed;
 				token.kind = Token_HalfClosed;
@@ -914,6 +916,10 @@ Token tokenizer_get_token(Tokenizer *t) {
 					advance_to_next_rune(t);
 					advance_to_next_rune(t);
 					token.kind = Token_Ellipsis;
 					token.kind = Token_Ellipsis;
 				}
 				}
+			} else if ('0' <= t->curr_rune && t->curr_rune <= '9') {
+				token = scan_number_to_token(t, true);
+			} else {
+				token.kind = Token_Period;
 			}
 			}
 			break;
 			break;