-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #98 from JorikSchellekens/rational_literal_types
Implement parser for rational literal types
- Loading branch information
Showing
5 changed files
with
34 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Range } from "../../misc"; | ||
import { TypeNode } from "./type"; | ||
|
||
interface Rational { | ||
numerator: bigint; | ||
denominator: bigint; | ||
} | ||
|
||
export class RationalLiteralType extends TypeNode { | ||
public readonly literal: Rational; | ||
|
||
constructor(literal: Rational, src?: Range) { | ||
super(src); | ||
|
||
this.literal = literal; | ||
} | ||
|
||
pp(): string { | ||
return `rational_const ${ppRational(this.literal)}`; | ||
} | ||
|
||
getFields(): any[] { | ||
return [this.literal]; | ||
} | ||
} | ||
|
||
function ppRational(literal: Rational): string { | ||
return `${literal.numerator.toString()} / ${literal.denominator.toString()}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,5 +46,7 @@ contract TestStorage { | |
uint[4] memory t; | ||
|
||
t; | ||
|
||
1.1; | ||
} | ||
} |