Skip to content

Add number literal type #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 3, 2017
Merged

Add number literal type #47

merged 5 commits into from
Dec 3, 2017

Conversation

exoego
Copy link
Contributor

@exoego exoego commented Oct 17, 2017

Converts the number literal type to Int or Double.

  • Int if it is valid-integer and does not have the fraction part, , e.g. 1 or 0x1
  • Double if it has the fraction part, e.g. 0.1, 1.0 or 00000000001001000110100

Compared to the string literal type, the usage seems very low... but not zero, e.g. Pixi.

@@ -107,7 +107,7 @@ object Trees {

case class BooleanLiteral(value: Boolean) extends Literal

case class NumberLiteral(value: Double) extends Literal
case class NumberLiteral(value: Double, isValidInt: Boolean) extends Literal
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This structure is a bit weird, IMO. Have you considered having two separate

case class IntLiteral(value: Int) extends Literal
case class DoubleLiteral(value: Double) extends Literal

instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored in 8bf944f

@@ -290,6 +295,12 @@ class TSDefParser extends StdTokenParsers with ImplicitConversions {
lazy val stringLiteral: Parser[StringLiteral] =
stringLit ^^ StringLiteral

lazy val numberLiteral: Parser[NumberLiteral] =
numericLit ^^ {s =>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coding style: missing space between { and s.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. Fixed in 8bf944f

@exoego exoego force-pushed the number-literal-type branch from 8bf944f to 3fe60c2 Compare December 3, 2017 13:41
Copy link
Owner

@sjrd sjrd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@sjrd sjrd merged commit 3db0a69 into sjrd:master Dec 3, 2017
@exoego exoego deleted the number-literal-type branch December 3, 2017 13:44
exoego referenced this pull request in exoego/scala-js-ts-importer Mar 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants