Skip to content
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

Port LiquidFixpoint's FQ ("new-format") tests #363

Merged
merged 28 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f540225
Introduce FixpointParser which will serve as the common superclass of…
shingarov Oct 17, 2024
479a793
Pull 'fixpoint' up to FixpointParser
shingarov Oct 17, 2024
a251fbe
Pull matchedParen and tok up to FixpointParser
shingarov Oct 17, 2024
999d78a
Pull lowerId, upperId up to FixpointParser class
shingarov Oct 17, 2024
03e56ca
Consistently name hThing
shingarov Oct 17, 2024
eab1c1e
Place parens in symSort (not its senders) for consistency with LF
shingarov Oct 17, 2024
a1a5eda
Introduce class FQParser, NO CODE YET
shingarov Oct 17, 2024
f7f4b9a
Use naming for hCstr consistent with LF
shingarov Oct 17, 2024
9029e70
Inline cstrAnd for consistency with LF
shingarov Oct 17, 2024
21b4d36
Parenthesize hBind consistently with LF
shingarov Oct 17, 2024
34d0146
Inline #forall, #exists for consistency with LF
shingarov Oct 17, 2024
0f49335
[cosmetic] Add "tag" TODO
shingarov Oct 17, 2024
1a1e4db
Use naming for hCstr consistent with LF
shingarov Oct 17, 2024
b4a62aa
Use naming for hPred consistent with LF
shingarov Oct 17, 2024
50694d7
Inline predAnd for consistency with LF
shingarov Oct 17, 2024
c391b31
Inline kappaApp, use kvSym for consistency with LF
shingarov Oct 17, 2024
f7d5a0d
Clear up confusion between pred, hPred and decidablePred
shingarov Oct 17, 2024
f35e147
Inline #constant for consistency with LF
shingarov Oct 17, 2024
0239e65
Rename qualif to hQualifier for consistency and to avoid confusion wi…
shingarov Oct 17, 2024
81d6ffc
Inline #constraint for consistency with LF
shingarov Oct 17, 2024
fe48a3b
Rename var to hVar for consistency with LF
shingarov Oct 17, 2024
e85d851
Pull common (i.e. non-Horn) elements from NNFParser to FixpointParser
shingarov Oct 18, 2024
c23fac1
Remove #matchedParen in favor of consistent use of RefinementExpressi…
shingarov Oct 18, 2024
a89b870
Route uses of RefinementExpressionParser through DecidableRefinement
shingarov Oct 18, 2024
35e2296
initial attempt at FQParser
shingarov Oct 18, 2024
a83429d
Create SubC via #mkSubC
shingarov Oct 18, 2024
1d1528c
First stab at FQParser
shingarov Oct 18, 2024
1a1840c
Add one smallest FQTest
shingarov Oct 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Refinements-Parsing/DecidableRefinement.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Extension { #name : #DecidableRefinement }

{ #category : #'*Refinements-Parsing' }
DecidableRefinement class >> parser [
^ RefinementExpressionParser new
==> [ :x | self text: x formattedCode ]
]
107 changes: 107 additions & 0 deletions src/Refinements-Parsing/FQParser.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
Class {
#name : #FQParser,
#superclass : #FixpointParser,
#instVars : [
'subC',
'bind',
'refa',
'sortedReft'
],
#category : #'Refinements-Parsing'
}

{ #category : #grammar }
FQParser >> bind [
^ self class lowerId trim,
$: asParser
==> #first
]

{ #category : #grammar }
FQParser >> constraint [
^ 'constraint:' asParser trim
, subC
==> #second
]

{ #category : #grammar }
FQParser >> def [
^ self fixpoint
/ self constraint
/ 'everything else' asParser
]

{ #category : #grammar }
FQParser >> fInfo [
^ self def trim plus
==> [ :x | FInfo defsFInfo: x ]
]

{ #category : #grammar }
FQParser >> ref: kind [
"
-- | (Sorted) Refinements
"
^self refBind: bind rp: refa kind: kind
]

{ #category : #grammar }
FQParser >> refBind: bp rp: rp kind: kindP [
"
-- (Sorted) Refinements with configurable sub-parsers
"
^(
bp trim,
kindP trim,
'|' asParser trim,
rp
) braces
==> [ :x | x second value: (Reft symbol: x first expr: x fourth) ]
]

{ #category : #grammar }
FQParser >> refa [
"
-- | Refa
refaP :: Parser Expr
refaP = try (pAnd <$> brackets (sepBy predP semi))
<|> predP
Cf. top-level Parse.hs
"
^".... and .... | "
pred
]

{ #category : #grammar }
FQParser >> sortedReft [
^ self ref: (sort ==> [ :aSort | [ :r | SortedReft sort: aSort reft: r ]])
]

{ #category : #grammar }
FQParser >> start [
^self fInfo trim end
]

{ #category : #grammar }
FQParser >> subC [
^ ('env []' asParser trim ==> [ :_ | IBindEnv empty])
, 'lhs' asParser trim, sortedReft trim
, 'rhs' asParser trim, sortedReft trim
, 'id' asParser, Character space asParser plus, PPParser decimalNat trim
, self tag
==> [ :x | SubC
mkSubC: x first
lhs: x third
rhs: x fifth
i: x eighth
tag: x ninth
]
]

{ #category : #grammar }
FQParser >> tag [
^ 'tag' asParser
, Character space asParser
, PPParser decimalNat semicolonSeparated brackets
==> [ :x | x third ]
]
105 changes: 105 additions & 0 deletions src/Refinements-Parsing/FixpointParser.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
Class {
#name : #FixpointParser,
#superclass : #PPCompositeParser,
#instVars : [
'sort',
'sortArg',
'funcSort',
'pred'
],
#category : #'Refinements-Parsing'
}

{ #category : #grammar }
FixpointParser class >> lowerId [
^(#lowercase asParser, (#word asParser / $_ asParser) star) flatten
]

{ #category : #grammar }
FixpointParser class >> upperId [
^(#uppercase asParser, (#word asParser / $_ asParser) star) flatten
]

{ #category : #grammar }
FixpointParser >> fTyCon [
^ ('Int' asParser ==> [ :x | Int tyCon ])
/ ('int' asParser ==> [ :x | Int tyCon ])
/ ('Bool' asParser ==> [ :x | Bool tyCon ])
/ ('bool' asParser ==> [ :x | Bool tyCon ])
/ (NNFParser upperId ==> #symbolFTycon)
]

{ #category : #grammar }
FixpointParser >> fixpoint [
^'fixpoint' asParser trim,
'"--' asParser,
('eliminate' asParser / 'rewrite' asParser / 'save' asParser / 'fuel' asParser),
($= asParser, #word asParser plus flatten) optional,
$" asParser
==> [ :x |
| selector |
selector := x third asSymbol.
x fourth isNil
ifTrue: [ HOpt perform: selector ]
ifFalse: [ HOpt perform: selector, ':' with: x fourth second ]
]

]

{ #category : #grammar }
FixpointParser >> funcSort [
"Parser for function sorts without the 'func' keyword"
^(
PPParser decimalNat,
$, asParser trim,
sort semicolonSeparated brackets
) parens
==> [ :x | Z3Sort mkFFunc: x first sorts: x third ]
]

{ #category : #grammar }
FixpointParser >> pred [
^DecidableRefinement parser
]

{ #category : #grammar }
FixpointParser >> sort [
^ self sort′: sortArg trim star
]

{ #category : #grammar }
FixpointParser >> sortArg [
^ self sort′: nil asParser
]

{ #category : #grammar }
FixpointParser >> sort′: aSortArgParser [
| sap |
sap := aSortArgParser ==> [ :args | args ifNil: [ #() ] ]. "aSortArgParser can be EpsilonParser"
^ sort parens
/ ('func' asParser, funcSort ==> [ :x | x second ])
/ (sort brackets ==> [ :x | x shouldBeImplemented listFTyCon ])
/ (self fTyCon trim, sap ==> [ :x | x first fAppTC: x second ])
/ (self tvar trim, sap ==> [ :x | x first fApp: x second ])
]

{ #category : #grammar }
FixpointParser >> tok [
^(PPPredicateObjectParser
on: (PPCharSetPredicate on: [ :ch |
(ch isSeparator or: [ ch == $( or: [ ch == $) ]]) not ])
message: 'Token expected') plus flatten

]

{ #category : #grammar }
FixpointParser >> tvar [
^ self varSort
/ ($` asParser, #lowercase asParser ==> [ :x | Z3Sort uninterpretedSortNamed: (String with: x second) ])
]

{ #category : #grammar }
FixpointParser >> varSort [
^'@(' asParser, PPParser decimalInteger, ')' asParser
==> [ :x | FVar new: x second ]
]
Loading
Loading