Coder Social home page Coder Social logo

Comments (26)

cpitclaudel avatar cpitclaudel commented on June 15, 2024 1

Hmm. I think only quote, backslash, comma, backtick, and #'.

from coq-serapi.

ejgallego avatar ejgallego commented on June 15, 2024

Indeed, sexplib serializes data in a particular way. The base data type, quoting from: https://github.com/janestreet/sexplib/blob/master/src/type.ml is

type t = Atom of string | List of t list

Thus, the choice is really what to do with strings!

For that, sexplib uses the code at
https://github.com/janestreet/sexplib/blob/master/src/pre_sexp.ml#L22
to guess when it should add quotes, as to make the output more "sexpy"-friendly.

Unfortunately the comma is not there, so I wonder what would the best solution be on our part; I am not an expert on S-expressions myself, but I will definitively try to bring this issue with sexplib developers.

from coq-serapi.

ejgallego avatar ejgallego commented on June 15, 2024

@cpitclaudel , do you know if this comma thing will create problems in emacs?

from coq-serapi.

ejgallego avatar ejgallego commented on June 15, 2024

Ok, a53964e should provide a more sensible escaping if --custom-escape is passed: we now treat every Atom as a UTF-8 string. Also, naked commas should not be produced.

Would you mind testing the comma part? Thanks

from coq-serapi.

cpitclaudel avatar cpitclaudel commented on June 15, 2024

I think it will be an issue in Emacs as well, yes; , is taken by the lisp reader to be a reader macro expanding to unquote.

Then again, it shouldn't be very hard to write a separate parser in list; but it would be nice to use the off-the-shelf one. The surprising thing is that Sexplib doesn't distinguish between symbols and strings.

from coq-serapi.

ejgallego avatar ejgallego commented on June 15, 2024

@cpitclaudel , any other special character we should keep in mind?

--custom-escape should solve the comma issue. I'm happy having our own printer.

Indeed sexplib makes the choice of "symbols == strings".

from coq-serapi.

ejgallego avatar ejgallego commented on June 15, 2024

Cool thanks, I'm gonna ask upstream about the quoting. It seems that double quote and backslash are OK.

The rest don't seem OK, I'll fix them in --custom-escape, while I get an answer from sexplib upstream.

Comma, quote, and backtick should be escaped only if at the beginning of a symbol, right?
What about #'?

I couldn't find an elisp grammar/lexical conventions.

from coq-serapi.

ejgallego avatar ejgallego commented on June 15, 2024

How to test sexplib quoting

Install utop and sexplib using OPAM, then:

$ utop 
# #require "sexplib";;
# let p x = Sexplib.Sexp.(Format.(printf "@[%a@]@\n" pp (Atom x)));;
# p ",";;

from coq-serapi.

cpitclaudel avatar cpitclaudel commented on June 15, 2024

Comma, quote, and backtick should be escaped only if at the beginning of a symbol, right?
What about #'?

No, anywhere in a symbol. Same for #' (and there's actually #< and ## as well apparently, though just escaping # would fix that too.

from coq-serapi.

cpitclaudel avatar cpitclaudel commented on June 15, 2024

I wonder why sexplib doesn't simply use quotes for everything that is a string on the OCaml side, and symbols for the rest.

from coq-serapi.

ejgallego avatar ejgallego commented on June 15, 2024

What do you mean by "everything that is a string on the OCaml side" ?

For sexplib, everything is a string, so it would then print ("Control" ("StmAdd" () "Command")), etc...

from coq-serapi.

cpitclaudel avatar cpitclaudel commented on June 15, 2024

Is Control a string? I thought it was the name of a constructor.

from coq-serapi.

ejgallego avatar ejgallego commented on June 15, 2024

At the sexp-level, Control is indeed a string. Recall the sexp syntax:

type t = Atom of string | List of t list

so sexplib expressions are just possibly nested lists of strings.

from coq-serapi.

cpitclaudel avatar cpitclaudel commented on June 15, 2024

Ah, right.

Maybe it would be simpler to just quote everything?

from coq-serapi.

ejgallego avatar ejgallego commented on June 15, 2024

Maybe we should quote everything, would that be a problem for emacs?

The new printer has been committed, I will close this once I add the proper documentation.

from coq-serapi.

cpitclaudel avatar cpitclaudel commented on June 15, 2024

Quoting everything would be totally fine :)

from coq-serapi.

Ptival avatar Ptival commented on June 15, 2024

I no longer have a problem with (PCData ,), but I have a problem with (PCData fold').

from coq-serapi.

ejgallego avatar ejgallego commented on June 15, 2024

@Ptival understood, will fix.

from coq-serapi.

riswords avatar riswords commented on June 15, 2024

Can square braces also be quoted? In (Query () (Vernac "Print nat.")) for example, I see (Pp_string ]) which causes an error for the emacs parser.

from coq-serapi.

ejgallego avatar ejgallego commented on June 15, 2024

@riswords , sure, I'll take of it.

from coq-serapi.

ejgallego avatar ejgallego commented on June 15, 2024

Should be better now, note that we currently depend on coq/coq#822 due to them having broke its linking spec.

from coq-serapi.

ejgallego avatar ejgallego commented on June 15, 2024

See e2982c1 if you need to tweak escaping more, and of course submit a pull request!

from coq-serapi.

riswords avatar riswords commented on June 15, 2024

Great, thank you!

from coq-serapi.

ejgallego avatar ejgallego commented on June 15, 2024

NP, let me know if you have any additional trouble, note also that we have a gitter channel that may work well for concrete questions.

from coq-serapi.

Ptival avatar Ptival commented on June 15, 2024

Ha, just got bit by (PCData [) and (PCData ]) myself!

from coq-serapi.

ejgallego avatar ejgallego commented on June 15, 2024

Yup at some point we'll make the custom quoting the default.

from coq-serapi.

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.