Skip to content

Commit

Permalink
Better handling of list of literals
Browse files Browse the repository at this point in the history
  • Loading branch information
jtristan committed Sep 13, 2024
1 parent 73e9335 commit 1e63bdf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 42 deletions.
7 changes: 3 additions & 4 deletions SHerLOC/AST1.lean
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,13 @@ inductive Literal where
| string (literal : String)
| stableHLORecord (literal : List StableHLORecordField)
| convolution (literal : Convolution)
| func (literal : FuncId)
| list (literal : List Literal)

| special
| use_global_device_ids
| array (literal : ArrayLiteral)
| experiment1 (literal : List FuncId)
| experiment2 (literal : List (List FuncId))
| experiment3 (literal : List EnumLiteral)
| func (literal : FuncId)

deriving Repr, Inhabited, Nonempty

structure IntegerType where
Expand Down
41 changes: 3 additions & 38 deletions SHerLOC/Parsing/Numbers.lean
Original file line number Diff line number Diff line change
Expand Up @@ -232,25 +232,6 @@ def parseEnumLiteral : PState EnumLiteral := do
return res
else throw <| ← error "enumeration"

def parseEnumLiteral' : PState EnumLiteral := do
push "parseEnumLiteral'"
parseItem "#stablehlo"
parseItem "<"
let mut r := none
if ← isParse "comparison_direction" then r := EnumLiteral.comparisonDirection <| ← parseComparisonDirection
if ← isParse "comparison_type" then r := EnumLiteral.compareType <| ← parseCompareType
if ← isParse "precision" then r := EnumLiteral.precisionConfig <| ← parsePrecisionConfig
if ← isParse "fft_type" then r := EnumLiteral.fftType <| ← parseFftType
if ← isParse "channel_type" then r := EnumLiteral.channelType <| ← parseChannelType
if ← isParse "rng_distribution" then r := EnumLiteral.rngDistribution <| ← parseRngDistribution
if ← isParse "rng_algorithm" then r := EnumLiteral.rngAlgorithm <| ← parseRngAlgorithm
if ← isParse "transpose" then r := EnumLiteral.transposeA <| ← parseTransposeA
if let some res := r then
parseItem ">"
pop "parseEnumLiteral'"
return res
else throw <| ← error "enumeration"

def parseArrayLiteral : PState ArrayLiteral := do
parseItems ["array", "<"]
if ← isParse "i64" then
Expand All @@ -267,15 +248,6 @@ def parseArrayLiteral : PState ArrayLiteral := do
return ArrayLiteral.array1 r
throw <| ← error "array literal"

def parseExperiment1 : PState (List FuncId) := do
parseList "[" "]" "," parseFuncId

def parseExperiment2 : PState (List (List FuncId)) := do
parseList "[" "]" "," parseExperiment1

def parseExperiment3 : PState (List EnumLiteral) := do
parseList "[" "]" "," parseEnumLiteral'

def parseStableHLORecordFieldValue : PState (StableHLORecordFieldValue) := do
if (← is "[") then
let value ← parseDecimals
Expand Down Expand Up @@ -328,7 +300,7 @@ def parseConvolution : PState Convolution := do
pop "parseConvolution"
return { lhs, rhs, result }

def parseLiteral : PState Literal := do
partial def parseLiteral : PState Literal := do
skip
if (← isDigit) || (← isChar '+') || (← isChar '-') then
return Literal.element <| ElementLiteral.floatLiteral <| ← parseFloatLiteral
Expand All @@ -354,15 +326,8 @@ def parseLiteral : PState Literal := do
} else return Literal.enum <| ← parseEnumLiteral
}

if ← isChar '[' then {

if ← is "[[" then
return Literal.experiment2 <| ← parseExperiment2
if ← is "[#" then
return Literal.experiment3 <| ← parseExperiment3
if ← is "[" then
return Literal.experiment1 <| ← parseExperiment1
}
if ← isChar '[' then
return Literal.list <| ← parseList "[" "]" "," parseLiteral

if ← isChar '{' then
flyOver "{" "}"; return Literal.special -- throw <| ← error "literal"
Expand Down

0 comments on commit 1e63bdf

Please sign in to comment.