Skip to content

Commit

Permalink
rearrange types such that types are followed by their parser
Browse files Browse the repository at this point in the history
  • Loading branch information
brandly committed Mar 12, 2019
1 parent 7e3ff3f commit 9c96894
Showing 1 changed file with 20 additions and 40 deletions.
60 changes: 20 additions & 40 deletions src/DotLang.elm
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,6 @@ type Stmt
| SubgraphStmt Subgraph


type Subgraph
= Subgraph (Maybe ID) (List Stmt)


stmtList : EdgeType -> Parser (List Stmt)
stmtList type_ =
let
Expand Down Expand Up @@ -189,26 +185,6 @@ statement type_ =
]


nodeStmt : Parser Stmt
nodeStmt =
succeed NodeStmt
|= nodeId
|. spacing
|= parseWithDefault attrList []


edgeStmtNode : EdgeType -> Parser Stmt
edgeStmtNode type_ =
succeed EdgeStmtNode
|= nodeId
|. spacing
|= edgeRHS type_
|. spacing
|= repeatingRhs type_
|. spacing
|= parseWithDefault attrList []


type EdgeRHS
= EdgeNode NodeId
| EdgeSubgraph Subgraph
Expand Down Expand Up @@ -280,6 +256,14 @@ repeatingRhs type_ =
loop [] help


attrStmt : Parser Stmt
attrStmt =
succeed AttrStmt
|= attrStmtType
|. spacing
|= attrList


type AttrStmtType
= AttrGraph
| AttrNode
Expand All @@ -295,18 +279,20 @@ attrStmtType =
]


attrStmt : Parser Stmt
attrStmt =
succeed AttrStmt
|= attrStmtType
|. spacing
|= attrList


type Attr
= Attr ID ID


attr : Parser Attr
attr =
succeed Attr
|= id
|. spacing
|. symbol "="
|. spacing
|= id


attrList : Parser (List Attr)
attrList =
let
Expand Down Expand Up @@ -336,14 +322,8 @@ attrList =
|= lazy (\_ -> parseWithDefault attrList [])


attr : Parser Attr
attr =
succeed Attr
|= id
|. spacing
|. symbol "="
|. spacing
|= id
type Subgraph
= Subgraph (Maybe ID) (List Stmt)


subgraph : EdgeType -> Parser Subgraph
Expand Down

0 comments on commit 9c96894

Please sign in to comment.