Skip to content

Commit

Permalink
libSyntax: parse float literal syntax node.
Browse files Browse the repository at this point in the history
  • Loading branch information
nkcsgexi committed Nov 4, 2017
1 parent 7f8e0ec commit b246cf4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
2 changes: 2 additions & 0 deletions lib/Parse/ParseExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1398,6 +1398,8 @@ ParserResult<Expr> Parser::parseExprPostfix(Diag<> ID, bool isExprBasic) {
case tok::floating_literal: {
StringRef Text = copyAndStripUnderscores(Context, Tok.getText());
SourceLoc Loc = consumeToken(tok::floating_literal);
SyntaxContext->addTokenSyntax(Loc);
SyntaxContext->makeNode(SyntaxKind::FloatLiteralExpr);
Result = makeParserResult(new (Context) FloatLiteralExpr(Text, Loc,
/*Implicit=*/false));
break;
Expand Down
1 change: 1 addition & 0 deletions lib/Syntax/SyntaxParsingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ void SyntaxParsingContextChild::makeNode(SyntaxKind Kind) {

// Create syntax nodes according to the given kind.
switch (Kind) {
case SyntaxKind::FloatLiteralExpr:
case SyntaxKind::IntegerLiteralExpr: {
// Integer may include the signs before the digits, so check if the sign
// exists and create.
Expand Down
10 changes: 7 additions & 3 deletions test/Syntax/Outputs/round_trip_parse_gen.swift.withkinds
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
<DeclarationStmt><UnknownDecl>// RUN: %swift-syntax-test -input-source-filename %s -parse-gen > %t
// RUN: diff -u %t %s
// RUN: diff -u %s %t
// RUN: %swift-syntax-test -input-source-filename %s -parse-gen -print-node-kind > %t.withkinds
// RUN: diff -u %t.withkinds %S/Outputs/round_trip_parse_gen.swift.withkinds
// RUN: diff -u %S/Outputs/round_trip_parse_gen.swift.withkinds %t.withkinds

class C {<UnknownDecl>
func bar(_ a: Int) {}</UnknownDecl><UnknownDecl>
func bar1(_ a: Float) -> Float { return <UnknownExpr><FloatLiteralExpr>-0.6 </FloatLiteralExpr>+ <FloatLiteralExpr>0.1 </FloatLiteralExpr>- <FloatLiteralExpr>0.3 </FloatLiteralExpr></UnknownExpr>}</UnknownDecl><UnknownDecl>
func foo() {<UnknownDecl>
var a = /*comment*/<StringLiteralExpr>"abc"/*comment*/</StringLiteralExpr></UnknownDecl><UnknownDecl>
var b = /*comment*/<IntegerLiteralExpr>+2/*comment*/</IntegerLiteralExpr></UnknownDecl><UnknownExpr>
bar(<IntegerLiteralExpr>1</IntegerLiteralExpr>)</UnknownExpr><UnknownExpr>
bar(<IntegerLiteralExpr>+10</IntegerLiteralExpr>)</UnknownExpr><UnknownExpr>
bar(<IntegerLiteralExpr>-10</IntegerLiteralExpr>)</UnknownExpr>
bar(<IntegerLiteralExpr>-10</IntegerLiteralExpr>)</UnknownExpr><UnknownExpr>
bar1(<FloatLiteralExpr>-1.1</FloatLiteralExpr>)</UnknownExpr><UnknownExpr>
bar1(<FloatLiteralExpr>1.1</FloatLiteralExpr>)</UnknownExpr><UnknownDecl>
var f = /*comments*/<FloatLiteralExpr>+0.1/*comments*/</FloatLiteralExpr></UnknownDecl>
}</UnknownDecl>
}</UnknownDecl></DeclarationStmt>
8 changes: 6 additions & 2 deletions test/Syntax/round_trip_parse_gen.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
// RUN: %swift-syntax-test -input-source-filename %s -parse-gen > %t
// RUN: diff -u %t %s
// RUN: diff -u %s %t
// RUN: %swift-syntax-test -input-source-filename %s -parse-gen -print-node-kind > %t.withkinds
// RUN: diff -u %t.withkinds %S/Outputs/round_trip_parse_gen.swift.withkinds
// RUN: diff -u %S/Outputs/round_trip_parse_gen.swift.withkinds %t.withkinds

class C {
func bar(_ a: Int) {}
func bar1(_ a: Float) -> Float { return -0.6 + 0.1 - 0.3 }
func foo() {
var a = /*comment*/"abc"/*comment*/
var b = /*comment*/+2/*comment*/
bar(1)
bar(+10)
bar(-10)
bar1(-1.1)
bar1(1.1)
var f = /*comments*/+0.1/*comments*/
}
}

0 comments on commit b246cf4

Please sign in to comment.