Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workcraft Parsing #36

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

thisiswhereitype
Copy link
Collaborator

Adds:
Workcraft parsing and associated docs.
Implemented with Protograph interface.
Closes #12

Copy link
Member

@snowleopard snowleopard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good, but see some comments above.

@@ -2,6 +2,7 @@

## pangraph-0.2.1
* Bump Algebraic Graphs from 0.1.* to 0.2.*
* Add Worcraft parsing via Pangraph.Workcraft.Parser
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo "Worcraft"


-- An unsafe version of the 'Text.XML.Hexml.parse' upon failure throws error to stderr.
-- An unsafe version of the 'Text.XML.Hexml.parse' upon failure throws error to stderr, showing the resulting error message.
hexmlParse :: ByteString -> Node
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we use unsafe prefix for unsafe functions -- let's keep doing this for consistency.

main :: IO ()
main = do
workcraftXML <- BS.readFile "./examples/graphs/model.xml"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also support parsing directly from work files?

followChildren h [] = [h]
followChildren h bs = (concatMap recurse . childrenBy h) (head bs)
followChildren _ [] = []
followChildren h bs = if head bs == name h
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be easier to read this if you use guard expressions, e.g. | head bs == .... Even better, avoid using partial functions like head by pattern-matching (otherwise a future refactoring could introduce a bug).

extractEdgeData :: H.Node -> [Attribute]
extractEdgeData h' = let
-- Find the child node for this Edge
child = (head $ H.followChildren h' ["node", "MathConnection"])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, can we get rid of partial functions like head? If the list is guaranteed to be non-empty, use Data.List.NonEmpty.

@thisiswhereitype thisiswhereitype self-assigned this Oct 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants