Skip to content

Commit

Permalink
Use full smalltalk parser when parsing refinement expression
Browse files Browse the repository at this point in the history
This commit uses a full smalltalk parser (based on `PetitSmalltalk`) when
parsing refining expression in refinement type (as opposed to simply
reading everything up first closing bracket).
  • Loading branch information
janvrany authored and shingarov committed Dec 5, 2023
1 parent e67a71f commit 2417634
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,15 @@ BaselineOfMachineArithmetic >> baseline: spec [
package: #'Refinements-Doodles' with:
[spec requires: 'Refinements-Parsing'];

package: #'PetitSmalltalk' with:
[
spec requires: 'PetitParser'.
spec repository: 'github://shingarov/PetitParser:ULD'];

package: #'SpriteLang' with:
[spec requires: 'Refinements'];
[
spec requires: 'PetitSmalltalk'.
spec requires: 'Refinements'];

package: #'SpriteLang-Tests' with:
[spec requires: 'SpriteLang'].
Expand Down
31 changes: 31 additions & 0 deletions src/SpriteLang/RefinementExpressionParser.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Class {
#name : #RefinementExpressionParser,
#superclass : #PPSmalltalkParser,
#instVars : [
'binaryChar'
],
#category : #'SpriteLang-Parsing'
}

{ #category : #primitives }
RefinementExpressionParser >> binary [
^binaryChar plus
]

{ #category : #primitives }
RefinementExpressionParser >> binaryChar [
| scanner |

"Here we delegate decisiton whether or not a character can occur in
binary selector to RBScanner. For example: MathNotation hacks RBScanner
to allow fancy math characters and we do not want to duplicate that code
here."

scanner := RBScanner on:'' readStream.
^ (PPPredicateObjectParser on: [:c | (scanner classify: c) == #binary ] message:'binary')
]

{ #category : #accessing }
RefinementExpressionParser >> start [
^sequence
]
8 changes: 7 additions & 1 deletion src/SpriteLang/RefinementParser.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Class {
#name : #RefinementParser,
#superclass : #PPCompositeParser,
#instVars : [
'concReftBExpr',
'matchedParen',
'funArg',
'reftB',
Expand Down Expand Up @@ -43,14 +44,19 @@ RefinementParser >> aRefBody [

{ #category : #grammar }
RefinementParser >> concReftB [
^ self lowerId trim, $| asParser trim, self nonBracket plus flatten
^ self lowerId trim, $| asParser trim, concReftBExpr
==> [ :id_pred |
| id pred |
id := id_pred first.
pred := id_pred last.
(Reft symbol: id expr: (DecidableRefinement text: pred)) known ]
]

{ #category : #grammar }
RefinementParser >> concReftBExpr [
^RefinementExpressionParser new ==> [ :seq | seq formattedCode ]
]

{ #category : #grammar }
RefinementParser >> forall [
^ '' asParser trim, rall ==> #last
Expand Down

0 comments on commit 2417634

Please sign in to comment.