@@ -41,7 +41,7 @@ object FastParserCompanion {
4141 def identStarts [$ : P ] = CharIn (" A-Z" , " a-z" , " $_" )
4242 def identContinues [$ : P ] = CharIn (" 0-9" , " A-Z" , " a-z" , " $_" )
4343
44- type Pos = (Position , Position )
44+ type Pos = (FilePosition , FilePosition )
4545 import scala .language .implicitConversions
4646 implicit def LeadingWhitespaceStr [$ : P ](p : String ): LeadingWhitespace [Unit ] = new LeadingWhitespace (() => P (p))
4747 implicit def LeadingWhitespace [T ](p : => P [T ]) = new LeadingWhitespace (() => p)
@@ -62,7 +62,7 @@ object FastParserCompanion {
6262 def ~~~ [$ : P , V , R ](other : LW [V ])(implicit s : Implicits .Sequencer [T , V , R ]): P [R ] = (p() ~~ other.p()).asInstanceOf [P [R ]]
6363 def ~~~/ [$ : P , V , R ](other : LW [V ])(implicit s : Implicits .Sequencer [T , V , R ]): P [R ] = (p() ~~/ other.p()).asInstanceOf [P [R ]]
6464 }
65- class PositionParsing [T ](val p : () => P [((Position , Position )) => T ]) extends AnyVal {
65+ class PositionParsing [T ](val p : () => P [((FilePosition , FilePosition )) => T ]) extends AnyVal {
6666 def pos (implicit ctx : P [Any ], lineCol : LineCol , _file : Path ): P [T ] = {
6767 // TODO: switch over to this?
6868 // Index ~~ p() ~~ Index map { case (start, f, end) => {
@@ -71,7 +71,7 @@ object FastParserCompanion {
7171 // f((FilePosition(_file, startPos._1, startPos._2), FilePosition(_file, finishPos._1, finishPos._2)))
7272 // }}
7373 val startPos = lineCol.getPos(ctx.index)
74- val res : P [((Position , Position )) => T ] = p()
74+ val res : P [((FilePosition , FilePosition )) => T ] = p()
7575 val finishPos = lineCol.getPos(ctx.index)
7676 res.map(_((FilePosition (_file, startPos._1, startPos._2), FilePosition (_file, finishPos._1, finishPos._2))))
7777 }
@@ -286,7 +286,7 @@ class FastParser {
286286 j += 1
287287 }
288288 }
289- PProgram (imports, macros, domains, fields, functions, predicates, methods, extensions, errors )(p.pos)
289+ PProgram (imports, macros, domains, fields, functions, predicates, methods, extensions)(p.pos, errors )
290290 }
291291
292292
@@ -304,7 +304,7 @@ class FastParser {
304304 case _ =>
305305 SourcePosition (_file, 0 , 0 )
306306 }
307- PProgram (Nil , Nil , Nil , Nil , Nil , Nil , Nil , Nil , Seq (ParseError (msg, location)))(( NoPosition , NoPosition ))
307+ PProgram (Nil , Nil , Nil , Nil , Nil , Nil , Nil , Nil )(( NoPosition , NoPosition ), Seq (ParseError (msg, location)))
308308 }
309309 }
310310
@@ -517,9 +517,9 @@ class FastParser {
517517
518518 def idnuse [$ : P ]: P [PIdnUseExp ] = P (ident map (PIdnUseExp .apply _)).pos
519519
520- def idnref [$ : P ] : P [PIdnRef ] = P (ident map (PIdnRef .apply _)).pos
520+ def idnref [$ : P , T <: PDeclarationInner ]( implicit ctag : scala.reflect. ClassTag [ T ]) : P [PIdnRef [ T ]] = P (ident map (PIdnRef .apply[ T ] _)).pos
521521
522- def oldLabel [$ : P ]: P [PLabelUse ] = P ((P (PKw .Lhs ) map (PLhsLabel .apply _)).pos | idnuse )
522+ def oldLabel [$ : P ]: P [Either [ PKw . Lhs , PIdnRef [ PLabel ]]] = P ((P (PKw .Lhs ) map (Left ( _))) | (idnref[$, PLabel ] map ( Right (_))) )
523523
524524 def old [$ : P ]: P [PKwOp .Old => Pos => POldExp ] = P (oldLabel.brackets.? ~ exp.parens).map {
525525 case (lbl, g) => POldExp (_, lbl, g)
@@ -560,7 +560,7 @@ class FastParser {
560560 => SuffixedExpressionGenerator [PExp ](e0 => PLookup (e0, l, e1, r)(e0.pos._1, pos._2)) })
561561
562562 def fieldAccess [$ : P ]: P [SuffixedExpressionGenerator [PExp ]] =
563- P (((! P (PSymOp .DotDot ) ~~ PSymOp .Dot ) ~ idnref) map { case (dot, id) => pos : Pos => SuffixedExpressionGenerator [PExp ](e => PFieldAccess (e, dot, id)(e.pos._1, pos._2)) }).pos
563+ P (((! P (PSymOp .DotDot ) ~~ PSymOp .Dot ) ~ idnref[$, PFieldDecl ] ) map { case (dot, id) => pos : Pos => SuffixedExpressionGenerator [PExp ](e => PFieldAccess (e, dot, id)(e.pos._1, pos._2)) }).pos
564564
565565 def sliceEnd [$ : P ]: P [((PSymOp .LBracket , PSymOp .RBracket )) => Pos => SuffixedExpressionGenerator [PExp ]] =
566566 P ((P (PSymOp .DotDot ) ~ exp).map { case (d, n) => b => pos : Pos
@@ -617,9 +617,9 @@ class FastParser {
617617
618618 def chainComp (op : PReserved [PBinaryOp ], right : PExp )(pos : Pos )(from : PExp ) = SuffixedExpressionGenerator (_ match {
619619 case left@ PBinExp (_, op0, middle) if cmpOps.contains(op0.rs.token) && left != from =>
620- PBinExp (left, PReserved (PSymOp .AndAnd )(NoPosition , NoPosition ), PBinExp (middle, op, right)(middle.pos._1, pos._2))(left.pos._1, pos._2)
620+ PBinExp (left, PReserved (PSymOp .AndAnd )(NoPosition , NoPosition ), PBinExp (middle.deepCopyAll. asInstanceOf [ PExp ] , op, right)(middle.pos._1, pos._2))(left.pos._1, pos._2)
621621 case left@ PBinExp (_, PReserved (PSymOp .AndAnd ), PBinExp (_, op0, middle)) if cmpOps.contains(op0.rs.token) && left != from =>
622- PBinExp (left, PReserved (PSymOp .AndAnd )(NoPosition , NoPosition ), PBinExp (middle, op, right)(middle.pos._1, pos._2))(left.pos._1, pos._2)
622+ PBinExp (left, PReserved (PSymOp .AndAnd )(NoPosition , NoPosition ), PBinExp (middle.deepCopyAll. asInstanceOf [ PExp ] , op, right)(middle.pos._1, pos._2))(left.pos._1, pos._2)
623623 case left => PBinExp (left, op, right)(left.pos._1, pos._2)
624624 })
625625
@@ -674,11 +674,7 @@ class FastParser {
674674 P (idndef ~ PSymOp .EqEq ~ parenthesizedExp ~ PKwOp .In ~ exp).map {
675675 case (id, eq, exp1, in, exp2) =>
676676 val nestedScope = PLetNestedScope (exp2)(exp2.pos)
677- k => pos => {
678- val let = PLet (k, id, eq, exp1, in, nestedScope)(pos)
679- nestedScope.outerLet = let
680- let
681- }
677+ k => PLet (k, id, eq, exp1, in, nestedScope)(_)
682678 }
683679
684680 def idndef [$ : P ]: P [PIdnDef ] = P (ident map (PIdnDef .apply _)).pos
@@ -717,7 +713,7 @@ class FastParser {
717713
718714 def typ [$ : P ]: P [PType ] = P (typReservedKw | domainTyp | macroType)
719715
720- def domainTyp [$ : P ]: P [PDomainType ] = P ((idnref ~~~ typeList(typ).lw.? ) map (PDomainType .apply _).tupled).pos
716+ def domainTyp [$ : P ]: P [PDomainType ] = P ((idnref[$, PTypeDeclaration ] ~~~ typeList(typ).lw.? ) map (PDomainType .apply _).tupled).pos
721717
722718 def seqType [$ : P ]: P [PKw .Seq => Pos => PSeqType ] = P (typ.brackets map { t => PSeqType (_, t) })
723719
@@ -804,11 +800,15 @@ class FastParser {
804800
805801 def newExp [$ : P ]: P [PKw .New => Pos => PNewExp ] = P (newExpFields.parens map { n => PNewExp (_, n) })
806802
807- def newExpFields [$ : P ]: P [Either [PSym .Star , PDelimited [PIdnUseExp , PSym .Comma ]]] = P (P (PSym .Star ).map(Left (_)) | P (idnuse .delimited(PSym .Comma ).map(Right (_))))
803+ def newExpFields [$ : P ]: P [Either [PSym .Star , PDelimited [PIdnRef [ PFieldDecl ] , PSym .Comma ]]] = P (P (PSym .Star ).map(Left (_)) | P (idnref[$, PFieldDecl ] .delimited(PSym .Comma ).map(Right (_))))
808804
809- def funcApp [$ : P ]: P [PCall ] = P ((idnref ~ argList(exp)) map {
810- case (func, args) => PCall (func, args, None )(_)
811- }).pos
805+ def funcApp [$ : P ]: P [PCall ] = P (idnref[$, PGlobalCallable ] ~~ " " .repX(1 ).map { _ => pos : Pos => pos }.pos.? ~~ argList(exp)).map {
806+ case (func, space, args) =>
807+ space.foreach { space =>
808+ _warnings = _warnings :+ ParseWarning (" Whitespace between a function identifier and the opening paren is deprecated, remove the spaces" , SourcePosition (_file, space._1, space._2))
809+ }
810+ PCall (func, args, None )(_)
811+ }.pos
812812
813813 def maybeTypedFuncApp [$ : P ](bracketed : Boolean ): P [PCall ] = P (if (! bracketed) funcApp else (funcApp ~~~ (P (PSym .Colon ) ~ typ).lw.? ).map {
814814 case (func, typeGiven) => func.copy(typeAnnotated = typeGiven)(_)
@@ -905,13 +905,13 @@ class FastParser {
905905 P ((nonEmptyIdnTypeList(PLocalVarDecl (_)) ~~~ (P (PSymOp .Assign ) ~ exp).lw.? ) map { case (a, i) => PVars (_, a, i) })
906906
907907 def defineDecl [$ : P ]: P [PKw .Define => PAnnotationsPosition => PDefine ] =
908- P ((idndef ~~~/ NoCut (argList(idndef)).lw.? ~ (stmtBlock(false ) | exp)) map {
908+ P ((idndef ~~~/ NoCut (argList(( idndef map PDefineParam .apply).pos )).lw.? ~ (stmtBlock(false ) | exp)) map {
909909 case (idn, args, body) => k => ap : PAnnotationsPosition => PDefine (ap.annotations, k, idn, args, body)(ap.pos)
910910 })
911911
912912 def defineDeclStmt [$ : P ]: P [PKw .Define => Pos => PDefine ] = P (defineDecl.map { f => k => pos : Pos => f(k)(PAnnotationsPosition (Nil , pos)) })
913913
914- def goto [$ : P ]: P [PKw .Goto => Pos => PGoto ] = P (idnuse map { i => PGoto (_, i) _ })
914+ def goto [$ : P ]: P [PKw .Goto => Pos => PGoto ] = P (idnref[$, PLabel ] map { i => PGoto (_, i) _ })
915915
916916 def label [$ : P ]: P [PKw .Label => Pos => PLabel ] =
917917 P ((idndef ~ semiSeparated(invariant)) map { case (i, inv) => k=> PLabel (k, i, inv) _ })
@@ -954,8 +954,7 @@ class FastParser {
954954 decls.collect { case p : PPredicate => p }, // Predicates
955955 decls.collect { case m : PMethod => m }, // Methods
956956 decls.collect { case e : PExtender => e }, // Extensions
957- warnings // Parse Warnings
958- )(_)
957+ )(_, warnings) // Parse Warnings
959958 }
960959 }).pos
961960
@@ -981,8 +980,8 @@ class FastParser {
981980 val members = block.inner.members
982981 val funcs1 = members collect { case m : PDomainFunction1 => m }
983982 val axioms1 = members collect { case m : PAxiom1 => m }
984- val funcs = funcs1 map (f => (PDomainFunction (f.annotations, f.unique, f.function, f.idndef, f.args, f.c, f.typ, f.interpretation)(PIdnRef (name.name)(name.pos))( f.pos), f.s))
985- val axioms = axioms1 map (a => (PAxiom (a.annotations, a.axiom, a.idndef, a.exp)(PIdnRef (name.name)(name.pos))( a.pos), a.s))
983+ val funcs = funcs1 map (f => (PDomainFunction (f.annotations, f.unique, f.function, f.idndef, f.args, f.c, f.typ, f.interpretation)(f.pos), f.s))
984+ val axioms = axioms1 map (a => (PAxiom (a.annotations, a.axiom, a.idndef, a.exp)(a.pos), a.s))
986985 val allMembers = block.update(PDomainMembers (PDelimited (funcs)(NoPosition , NoPosition ), PDelimited (axioms)(NoPosition , NoPosition ))(block.pos))
987986 k => ap : PAnnotationsPosition => PDomain (
988987 ap.annotations,
@@ -1000,11 +999,11 @@ class FastParser {
1000999 case (unique, (function, idn, args, c, typ), interpretation, s) => ap : PAnnotationsPosition => PDomainFunction1 (ap.annotations, unique, function, idn, args, c, typ, interpretation, s)(ap.pos)
10011000 }
10021001
1003- def domainFunctionSignature [$ : P ] = P (P (PKw .Function ) ~ idndef ~ argList(formalArg | unnamedFormalArg ) ~ PSym .Colon ~ typ)
1002+ def domainFunctionSignature [$ : P ] = P (P (PKw .Function ) ~ idndef ~ argList(domainFunctionArg ) ~ PSym .Colon ~ typ)
10041003
1005- def formalArg [$ : P ]: P [PFormalArgDecl ] = P (idnTypeBinding.map(PFormalArgDecl (_)))
1004+ def domainFunctionArg [$ : P ]: P [PDomainFunctionArg ] = P (idnTypeBinding.map(PDomainFunctionArg (_)) | typ.map( PDomainFunctionArg ( None , None , _) _).pos )
10061005
1007- def unnamedFormalArg [$ : P ] = P (typ map (PUnnamedFormalArgDecl .apply _)).pos
1006+ def formalArg [$ : P ]: P [ PFormalArgDecl ] = P (idnTypeBinding map (PFormalArgDecl ( _)))
10081007
10091008 def bracedExp [$ : P ]: P [PBracedExp ] = P (exp.braces map (PBracedExp (_) _)).pos
10101009
0 commit comments