-
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.
- Loading branch information
Showing
1 changed file
with
49 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/- | ||
Copyright (c) 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Authors: Jean-Baptiste Tristan | ||
-/ | ||
import SHerLOC.AST.Basic | ||
import SHerLOC.Parsing.Parser | ||
import SHerLOC.Parsing.Identifiers | ||
import SHerLOC.Parsing.Types | ||
import SHerLOC.Parsing.Constants | ||
|
||
namespace StableHLO | ||
|
||
def parseAttribute : PState Attribute := do | ||
push "parseAttribute" | ||
let id ← parseId | ||
parseItem "=" | ||
let constant ← parseConstant | ||
pop "parseAttribute" | ||
return { id := id , constant := constant } | ||
|
||
def parseAttributes : PState (List Attribute) := do | ||
push "parseAttributes" | ||
let r ← parseList "{" "}" (some ",") parseAttribute | ||
pop "parseAttributes" | ||
return r | ||
|
||
def parseValueUseList : PState (List ValueId) := do | ||
push "parseValueUseList" | ||
let r ← parseList "(" ")" "," parseValueId | ||
pop "parseValueUseList" | ||
return r | ||
|
||
def tryParseDictionaryEntry (name : String) (parser : PState T) : PState (Option T) := do | ||
let st ← get | ||
if st.is name then | ||
parseItem name | ||
parseItem "=" | ||
let t ← parser | ||
return some t | ||
else return none | ||
|
||
def parseDictionaryProperties : PState (List Attribute) := do | ||
push "parseDictionaryProperties" | ||
let r ← parseList "<{" "}>" "," parseAttribute | ||
pop "parseDictionaryProperties" | ||
return r | ||
|
||
end StableHLO |