Giter Site home page Giter Site logo

Comments (11)

jmtd avatar jmtd commented on September 24, 2024 1

The main difficulty seems to be finding a way to escape characters without sacrificing the polymorphic interface.

You're right ,that's a detail I overlooked entirely when I first reported this (I subsequently came up with concatMap (\x-> if elem x badChars then ["\\",x] else [x]), felt pleased with myself, and thought all that was needed was plugging it into the right place).

Text.JSON.Escape

I don't know of a better approach; this looks reasonable but I'll do some looking around (probably Tomorrow) and see what else comes up.

from alga.

snowleopard avatar snowleopard commented on September 24, 2024

@jmtd Thanks! Indeed, this looks problematic.

Presumably, this is the right output?

digraph
{
  "\"1\""
  "\"2\""
  "\"1\"" -> "\"2\""
}

from alga.

snowleopard avatar snowleopard commented on September 24, 2024

While this is being resolved, the workaround is to use exportAsIs after converting all vertex labels to strings using the right escaping. For example:

> putStrLn (exportAsIs (path ["1", "2"]) :: String)

digraph
{
  "1"
  "2"
  "1" -> "2"
}

from alga.

jmtd avatar jmtd commented on September 24, 2024

Hi,

Presumably, this is the right output?

Yep that's right.

While this is being resolved, the workaround is to use exportAsIs after converting all vertex labels to strings using the right escaping.

Very useful, thanks!

from alga.

jmtd avatar jmtd commented on September 24, 2024

This seems like a suitable piece of work for a beginner PR, so I am going to take a stab at this, however if anyone else wants to try it please don't let me stop you.

from alga.

snowleopard avatar snowleopard commented on September 24, 2024

@jmtd Sure, please give it a try!

The main difficulty seems to be finding a way to escape characters without sacrificing the polymorphic interface. At the moment users can export into String, Text or any other similar datatype. How do we implement the escaping logic generically?

Perhaps, we need to define a type class of 'escapable strings' with a couple of standard instances:

class Escape s where
    escape :: s -> s

instance Escape String where
    escape [] = []
    escape (c:cs) = escapeChar c ++ escape cs
      where
        escapeChar :: Char -> String
        escapeChar c = ...

instance Escape Text where ...

For example, I found exactly the same solution here.

Then we'll need to strengthen the constraint on exportViaShow from Show s to (Show s, Escape s).

Does this make sense? Or is there a better approach?

from alga.

jmtd avatar jmtd commented on September 24, 2024

Sorry for the radio silence here, slow progress, my WIP (not PR-worthy yet) is here https://github.com/jmtd/alga/tree/escape-typeclass

from alga.

snowleopard avatar snowleopard commented on September 24, 2024

@jmtd No problem, take you time :) Don't hesitate to send a draft PR -- happy to review and iterate.

from alga.

jmtd avatar jmtd commented on September 24, 2024

OK I'll open one (now :)) as I have something that works for the simple case above, but there's clearly more work to be done.

from alga.

jmtd avatar jmtd commented on September 24, 2024

A brief update. I thought it wise to look at what others had done already, and so I was reading through Data.GraphViz.Printing, in particular addEscapes (anchor in that link). The de-facto rules appear to be considerably different to the theoretical ones (I was surprised for example to see escLetters = Set.fromList ['N', 'G', 'E', 'T', 'H', 'L', 'n', 'l', 'r']. I wonder why they are escaped?)

I imagine that Data.GraphViz.Printing reflects the truth of the Dot format, but the real test would be whether dot accepts it. So I was considering writing a simple test harness that would attempt an export of a given escaped string and see whether dot complained or not, as part of developing a proper escape routine (and/or verifying the rules in Data.GraphViz.Printing)

from alga.

snowleopard avatar snowleopard commented on September 24, 2024

@jmtd Good idea to check what others are doing!

I was surprised for example to see escLetters = Set.fromList ['N', 'G', 'E', 'T', 'H', 'L', 'n', 'l', 'r']. I wonder why they are escaped?

I guess if we have a string Hello\nWorld we don't want to mess with the \ but leave it as is? Not sure, this all is getting quite complicated ;)

Yes, we need to collect a dozen of examples/tests and make sure our translation agrees with dot.

from alga.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.