-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make syntax slicing extensible so that custom slicers can be written for various productions that aren't handled well by the default heuristics.
- Loading branch information
1 parent
f2b840b
commit 495b429
Showing
3 changed files
with
107 additions
and
13 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import Lean | ||
import Lean.Elab | ||
|
||
open Lean Elab Term | ||
|
||
|
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,45 @@ | ||
/- | ||
Copyright (c) 2024 Lean FRO LLC. All rights reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Author: David Thrane Christiansen | ||
-/ | ||
import Lean.Data.Position | ||
import Lean.Syntax | ||
import Lean.KeyedDeclsAttribute | ||
|
||
namespace SubVerso.Examples.Slice.Attribute | ||
|
||
open Lean | ||
|
||
private unsafe def mkSliceExpanderAttrUnsafe (attrName typeName : Name) (descr : String) (attrDeclName : Name) : IO (KeyedDeclsAttribute α) := | ||
KeyedDeclsAttribute.init { | ||
name := attrName, | ||
descr := descr, | ||
valueTypeName := typeName | ||
} attrDeclName | ||
|
||
@[implemented_by mkSliceExpanderAttrUnsafe] | ||
private opaque mkSliceExpanderAttributeSafe (attrName typeName : Name) (desc : String) (attrDeclName : Name) : IO (KeyedDeclsAttribute α) | ||
|
||
private def mkSliceExpanderAttribute (attrName typeName : Name) (desc : String) (attrDeclName : Name := by exact decl_name%) : IO (KeyedDeclsAttribute α) := | ||
mkSliceExpanderAttributeSafe attrName typeName desc attrDeclName | ||
|
||
abbrev Slicer := (Syntax → Syntax) → Syntax → Array String.Range → Option Syntax | ||
|
||
initialize slicerAttr : KeyedDeclsAttribute Slicer ← | ||
mkSliceExpanderAttribute `slicer ``Slicer "Indicates that this function is used to slice the given syntax kind" | ||
|
||
unsafe def slicersForUnsafe [Monad m] [MonadEnv m] (x : Name) : m (List Slicer) := do | ||
let expanders := slicerAttr.getEntries (← getEnv) x | ||
return expanders.map (·.value) | ||
|
||
@[implemented_by slicersForUnsafe] | ||
opaque slicersFor [Monad m] [MonadEnv m] (x : Name) : m (List Slicer) | ||
|
||
|
||
unsafe def slicersInEnvUnsafe (env : Environment) (x : Name) : List Slicer := | ||
let expanders := slicerAttr.getEntries env x | ||
expanders.map (·.value) | ||
|
||
@[implemented_by slicersInEnvUnsafe] | ||
opaque slicersInEnv (env : Environment) (x : Name) : List Slicer |