-
Notifications
You must be signed in to change notification settings - Fork 43
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
Conversation
@@ -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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 => |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops. Fixed in 8bf944f
8bf944f
to
3fe60c2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Converts the number literal type to
Int
orDouble
.Int
if it is valid-integer and does not have the fraction part, , e.g.1
or0x1
Double
if it has the fraction part, e.g.0.1
,1.0
or00000000001001000110100
Compared to the string literal type, the usage seems very low... but not zero, e.g. Pixi.