未验证 提交 97a5b658 编写于 作者: D dawe 提交者: GitHub

Add a Paren case to SynRationalConst (#15885)

* add ranges for lparen, /, rparen to SynRationalConst.Rational

* extend SynRationalConst with a new case "Paren" to capture SynRationalConsts wrapped in parens

* use rhs2 to help recovery
上级 0f308539
......@@ -757,6 +757,7 @@ let rec TcSynRationalConst c =
| SynRationalConst.Integer(value = i) -> intToRational i
| SynRationalConst.Negate(rationalConst = c2) -> NegRational (TcSynRationalConst c2)
| SynRationalConst.Rational(numerator = p; denominator = q) -> DivRational (intToRational p) (intToRational q)
| SynRationalConst.Paren(rationalConst = c) -> TcSynRationalConst c
/// Typecheck constant terms in expressions and patterns
let TcConst (cenv: cenv) (overallTy: TType) m env synConst =
......
......@@ -106,8 +106,9 @@ type InterfaceData =
let rec (|RationalConst|) =
function
| SynRationalConst.Integer (value = i) -> string i
| SynRationalConst.Rational (numerator = numerator; denominator = denominator) -> sprintf "(%i/%i)" numerator denominator
| SynRationalConst.Rational (numerator = numerator; denominator = denominator) -> sprintf "%i/%i" numerator denominator
| SynRationalConst.Negate (rationalConst = (RationalConst s)) -> sprintf "- %s" s
| SynRationalConst.Paren (rationalConst = (RationalConst s)) -> sprintf "(%s)" s
let rec (|TypeIdent|_|) =
function
......
......@@ -195,10 +195,12 @@ type SynRationalConst =
| Integer of value: int32 * range: range
| Rational of numerator: int32 * numeratorRange: range * denominator: int32 * denominatorRange: range * range: range
| Rational of numerator: int32 * numeratorRange: range * divRange: range * denominator: int32 * denominatorRange: range * range: range
| Negate of rationalConst: SynRationalConst * range: range
| Paren of rationalConst: SynRationalConst * range: range
[<RequireQualifiedAccess>]
type SynAccess =
| Public of range: range
......
......@@ -216,10 +216,18 @@ type SynRationalConst =
| Integer of value: int32 * range: range
| Rational of numerator: int32 * numeratorRange: range * denominator: int32 * denominatorRange: range * range: range
| Rational of
numerator: int32 *
numeratorRange: range *
divRange: range *
denominator: int32 *
denominatorRange: range *
range: range
| Negate of rationalConst: SynRationalConst * range: range
| Paren of rationalConst: SynRationalConst * range: range
/// Represents an accessibility modifier in F# syntax
[<RequireQualifiedAccess>]
type SynAccess =
......
......@@ -3314,13 +3314,13 @@ rationalConstant:
{ if $2 <> "/" then reportParseErrorAt (rhs parseState 2) (FSComp.SR.parsUnexpectedOperatorForUnitOfMeasure())
if fst $3 = 0 then reportParseErrorAt (rhs parseState 3) (FSComp.SR.parsIllegalDenominatorForMeasureExponent())
if (snd $1) || (snd $3) then errorR(Error(FSComp.SR.lexOutsideThirtyTwoBitSigned(), lhs parseState))
SynRationalConst.Rational(fst $1, rhs parseState 1, fst $3, rhs parseState 3, lhs parseState) }
SynRationalConst.Rational(fst $1, rhs parseState 1, rhs parseState 2, fst $3, rhs parseState 3, lhs parseState) }
| MINUS INT32 INFIX_STAR_DIV_MOD_OP INT32
{ if $3 <> "/" then reportParseErrorAt (rhs parseState 3) (FSComp.SR.parsUnexpectedOperatorForUnitOfMeasure())
if fst $4 = 0 then reportParseErrorAt (rhs parseState 4) (FSComp.SR.parsIllegalDenominatorForMeasureExponent())
if (snd $2) || (snd $4) then errorR(Error(FSComp.SR.lexOutsideThirtyTwoBitSigned(), lhs parseState))
SynRationalConst.Negate(SynRationalConst.Rational(fst $2, rhs parseState 2, fst $4, rhs parseState 4, lhs parseState), lhs parseState) }
SynRationalConst.Negate(SynRationalConst.Rational(fst $2, rhs parseState 2, rhs parseState 3, fst $4, rhs parseState 4, lhs parseState), lhs parseState) }
| INT32
{ if snd $1 then errorR(Error(FSComp.SR.lexOutsideThirtyTwoBitSigned(), lhs parseState))
......@@ -3335,7 +3335,7 @@ atomicUnsignedRationalConstant:
SynRationalConst.Integer(fst $1, lhs parseState) }
| LPAREN rationalConstant rparen
{ $2 }
{ SynRationalConst.Paren($2, rhs2 parseState 1 3) }
atomicRationalConstant:
| atomicUnsignedRationalConstant { $1 }
......
......@@ -8238,8 +8238,14 @@ FSharp.Compiler.Syntax.SynRationalConst+Negate: FSharp.Compiler.Syntax.SynRation
FSharp.Compiler.Syntax.SynRationalConst+Negate: FSharp.Compiler.Syntax.SynRationalConst rationalConst
FSharp.Compiler.Syntax.SynRationalConst+Negate: FSharp.Compiler.Text.Range get_range()
FSharp.Compiler.Syntax.SynRationalConst+Negate: FSharp.Compiler.Text.Range range
FSharp.Compiler.Syntax.SynRationalConst+Paren: FSharp.Compiler.Syntax.SynRationalConst get_rationalConst()
FSharp.Compiler.Syntax.SynRationalConst+Paren: FSharp.Compiler.Syntax.SynRationalConst rationalConst
FSharp.Compiler.Syntax.SynRationalConst+Paren: FSharp.Compiler.Text.Range get_range()
FSharp.Compiler.Syntax.SynRationalConst+Paren: FSharp.Compiler.Text.Range range
FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range denominatorRange
FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range divRange
FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range get_denominatorRange()
FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range get_divRange()
FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range get_numeratorRange()
FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range get_range()
FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range numeratorRange
......@@ -8250,18 +8256,23 @@ FSharp.Compiler.Syntax.SynRationalConst+Rational: Int32 get_numerator()
FSharp.Compiler.Syntax.SynRationalConst+Rational: Int32 numerator
FSharp.Compiler.Syntax.SynRationalConst+Tags: Int32 Integer
FSharp.Compiler.Syntax.SynRationalConst+Tags: Int32 Negate
FSharp.Compiler.Syntax.SynRationalConst+Tags: Int32 Paren
FSharp.Compiler.Syntax.SynRationalConst+Tags: Int32 Rational
FSharp.Compiler.Syntax.SynRationalConst: Boolean IsInteger
FSharp.Compiler.Syntax.SynRationalConst: Boolean IsNegate
FSharp.Compiler.Syntax.SynRationalConst: Boolean IsParen
FSharp.Compiler.Syntax.SynRationalConst: Boolean IsRational
FSharp.Compiler.Syntax.SynRationalConst: Boolean get_IsInteger()
FSharp.Compiler.Syntax.SynRationalConst: Boolean get_IsNegate()
FSharp.Compiler.Syntax.SynRationalConst: Boolean get_IsParen()
FSharp.Compiler.Syntax.SynRationalConst: Boolean get_IsRational()
FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst NewInteger(Int32, FSharp.Compiler.Text.Range)
FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst NewNegate(FSharp.Compiler.Syntax.SynRationalConst, FSharp.Compiler.Text.Range)
FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst NewRational(Int32, FSharp.Compiler.Text.Range, Int32, FSharp.Compiler.Text.Range, FSharp.Compiler.Text.Range)
FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst NewParen(FSharp.Compiler.Syntax.SynRationalConst, FSharp.Compiler.Text.Range)
FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst NewRational(Int32, FSharp.Compiler.Text.Range, FSharp.Compiler.Text.Range, Int32, FSharp.Compiler.Text.Range, FSharp.Compiler.Text.Range)
FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst+Integer
FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst+Negate
FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst+Paren
FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst+Rational
FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst+Tags
FSharp.Compiler.Syntax.SynRationalConst: Int32 Tag
......@@ -8238,8 +8238,14 @@ FSharp.Compiler.Syntax.SynRationalConst+Negate: FSharp.Compiler.Syntax.SynRation
FSharp.Compiler.Syntax.SynRationalConst+Negate: FSharp.Compiler.Syntax.SynRationalConst rationalConst
FSharp.Compiler.Syntax.SynRationalConst+Negate: FSharp.Compiler.Text.Range get_range()
FSharp.Compiler.Syntax.SynRationalConst+Negate: FSharp.Compiler.Text.Range range
FSharp.Compiler.Syntax.SynRationalConst+Paren: FSharp.Compiler.Syntax.SynRationalConst get_rationalConst()
FSharp.Compiler.Syntax.SynRationalConst+Paren: FSharp.Compiler.Syntax.SynRationalConst rationalConst
FSharp.Compiler.Syntax.SynRationalConst+Paren: FSharp.Compiler.Text.Range get_range()
FSharp.Compiler.Syntax.SynRationalConst+Paren: FSharp.Compiler.Text.Range range
FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range denominatorRange
FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range divRange
FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range get_denominatorRange()
FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range get_divRange()
FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range get_numeratorRange()
FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range get_range()
FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range numeratorRange
......@@ -8250,18 +8256,23 @@ FSharp.Compiler.Syntax.SynRationalConst+Rational: Int32 get_numerator()
FSharp.Compiler.Syntax.SynRationalConst+Rational: Int32 numerator
FSharp.Compiler.Syntax.SynRationalConst+Tags: Int32 Integer
FSharp.Compiler.Syntax.SynRationalConst+Tags: Int32 Negate
FSharp.Compiler.Syntax.SynRationalConst+Tags: Int32 Paren
FSharp.Compiler.Syntax.SynRationalConst+Tags: Int32 Rational
FSharp.Compiler.Syntax.SynRationalConst: Boolean IsInteger
FSharp.Compiler.Syntax.SynRationalConst: Boolean IsNegate
FSharp.Compiler.Syntax.SynRationalConst: Boolean IsParen
FSharp.Compiler.Syntax.SynRationalConst: Boolean IsRational
FSharp.Compiler.Syntax.SynRationalConst: Boolean get_IsInteger()
FSharp.Compiler.Syntax.SynRationalConst: Boolean get_IsNegate()
FSharp.Compiler.Syntax.SynRationalConst: Boolean get_IsParen()
FSharp.Compiler.Syntax.SynRationalConst: Boolean get_IsRational()
FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst NewInteger(Int32, FSharp.Compiler.Text.Range)
FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst NewNegate(FSharp.Compiler.Syntax.SynRationalConst, FSharp.Compiler.Text.Range)
FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst NewRational(Int32, FSharp.Compiler.Text.Range, Int32, FSharp.Compiler.Text.Range, FSharp.Compiler.Text.Range)
FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst NewParen(FSharp.Compiler.Syntax.SynRationalConst, FSharp.Compiler.Text.Range)
FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst NewRational(Int32, FSharp.Compiler.Text.Range, FSharp.Compiler.Text.Range, Int32, FSharp.Compiler.Text.Range, FSharp.Compiler.Text.Range)
FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst+Integer
FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst+Negate
FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst+Paren
FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst+Rational
FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst+Tags
FSharp.Compiler.Syntax.SynRationalConst: Int32 Tag
......@@ -10,9 +10,11 @@ ImplFile
Seq
([Power
(Named ([kg], (3,3--3,5)), (3,8--3,9),
Rational
(-12345, (3,21--3,27), 123, (3,28--3,31),
(3,21--3,31)), (3,3--3,32))], (3,3--3,32)),
Paren
(Rational
(-12345, (3,21--3,27), (3,27--3,28), 123,
(3,28--3,31), (3,21--3,31)), (3,20--3,32)),
(3,3--3,32))], (3,3--3,32)),
{ LessRange = (3,2--3,3)
GreaterRange = (3,32--3,33) }), (3,0--3,33)), (3,0--3,33))],
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None,
......
......@@ -11,12 +11,13 @@ ImplFile
([Power
(Named ([kg], (3,3--3,5)), (3,5--3,6),
Negate
(Rational
(12345, (3,13--3,18), 123, (3,19--3,22),
(3,13--3,22)), (3,6--3,23)), (3,3--3,23))],
(3,3--3,23)), { LessRange = (3,2--3,3)
GreaterRange = (3,23--3,24) }),
(3,0--3,24)), (3,0--3,24))],
(Paren
(Rational
(12345, (3,13--3,18), (3,18--3,19), 123,
(3,19--3,22), (3,13--3,22)), (3,12--3,23)),
(3,6--3,23)), (3,3--3,23))], (3,3--3,23)),
{ LessRange = (3,2--3,3)
GreaterRange = (3,23--3,24) }), (3,0--3,24)), (3,0--3,24))],
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None,
(1,0--3,24), { LeadingKeyword = Module (1,0--1,6) })], (true, true),
{ ConditionalDirectives = []
......
......@@ -11,12 +11,13 @@ ImplFile
([Power
(Named ([kg], (3,3--3,5)), (3,5--3,6),
Negate
(Rational
(12345, (3,10--3,15), 123, (3,16--3,19),
(3,10--3,19)), (3,7--3,20)), (3,3--3,20))],
(3,3--3,20)), { LessRange = (3,2--3,3)
GreaterRange = (3,20--3,21) }),
(3,0--3,21)), (3,0--3,21))],
(Paren
(Rational
(12345, (3,10--3,15), (3,15--3,16), 123,
(3,16--3,19), (3,10--3,19)), (3,9--3,20)),
(3,7--3,20)), (3,3--3,20))], (3,3--3,20)),
{ LessRange = (3,2--3,3)
GreaterRange = (3,20--3,21) }), (3,0--3,21)), (3,0--3,21))],
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None,
(1,0--3,21), { LeadingKeyword = Module (1,0--1,6) })], (true, true),
{ ConditionalDirectives = []
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册