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

Browsable source code #294

Open
3 tasks
jeetu7 opened this issue Apr 17, 2020 · 5 comments
Open
3 tasks

Browsable source code #294

jeetu7 opened this issue Apr 17, 2020 · 5 comments

Comments

@jeetu7
Copy link
Contributor

jeetu7 commented Apr 17, 2020

MarcelineVQ (at IRC) pointed at the Agda browsable source code. Agda stdlib example . This looks good for browsing source code, wherein we can go through various variables and jump across the code for declarations/definitions etc. Also, we can discuss various approaches for doing the same here.

  • Browsable code for Idris2.
  • Hosting Idris2 Browsable Code (probably on github.ion as Agda itself)
  • Mechanism to convert local code written in Idris2 for local browsing.
@jeetu7 jeetu7 changed the title Agda style browsable source code Browsable source code Apr 17, 2020
@jeetu7
Copy link
Contributor Author

jeetu7 commented Apr 17, 2020

For an example source idr file, pygments can generate prettly decent colorful html. The colors and lexer itself is customizable. Check the rarw code of gists input idr fileand output html. The output html should be downloaded and opened in your browser. Command used is as follows:

pygmentize -f html -O full -o /tmp/x.html ~/tmp/example.idr

So getting to html colorful code is easy.
Next is linking it with declarations.

@jeetu7
Copy link
Contributor Author

jeetu7 commented Apr 20, 2020

For linking, we have to customize (extend) the html formatter for idris1 in pygments. And also, to make it support idris2, we might have to extend the pygment's lexer as well.

For doing the linking part, we should be able to get this information from the idris2 compiler about how it parses and resolves the declaration and usage of types/variable/functions etc. Assuming the above information is available, conceptually the process of linking can go like this

  1. Extracts information from compiling process about which line the compiler sees the token usage (which we want to show as clickable) and which we want to link to (the declaration of that token)

  2. Modify the formatter of the pygment to add anchor to each line so that it can be hyperlinked to. Ref Html anchor links

  3. Generate output file with line numbered source code in html (with anchors for each line number id-ed as line number itself). Example with line numbers is already possible with pygments Line numbered html output
    pygmentize -f html -O full,linenos=1 -o /tmp/x.html ~/tmp/example.idr

  4. Use this information in the formatter, or might be a second pass by some other script.

@gallais
Copy link
Collaborator

gallais commented Apr 20, 2020

Do we gain much by using pygment rather than outputting e.g. markdown to be
post-processed by pandoc?

Re, looking at rendered examples we can use htmlpreview.github.io.
See for instance: your syntax highlighted file

@jfdm
Copy link
Contributor

jfdm commented Apr 22, 2020

We must also look at how it works in Idris1 where you can use the --highlight flag dump an SExpr containing highlighting information. There is a tool idrishl which can generate HTML and LaTeX sources. The SExpr is a version of the same information sent out by Idris1 IDE mode for highlighting, and the source is the same information used by idrisdoc Idris1's javadoc like tool

@jeetu7
Copy link
Contributor Author

jeetu7 commented May 1, 2020

@jfdm @gallais I will look into them. I might be little slow as I am learning Idris along the way.

  1. Also any pointers, at which point I can get the info about compiler finding the linking of declaration of tokens and their usages. Where should I start (which file or written material). Can I store the info in some output file as in ctags. Or do I have to decipher the scheme output for that.

  2. My aim is to get it going using whichever way is possible to get a wroking method. Then switch it step by step to better tools (preferably self contained idris methods).

  3. Generate line numbered linkable source code. Now you can link to a particular line using
    file:///tmp/x.html#line-5. Check the bottom two links for only html and particular line linked. You might have to reduce the size of the browser to actually notice the difference.
    pygmentize -f html -O full,linenos=1,lineanchors=line -o /tmp/x.html ~/tmp/example.idr

https://htmlpreview.github.io/?https://gist.githubusercontent.com/jeetu7/2873ac9befd63b1b0ef87347b5e41540/raw/3423e337d024df2f41653b2bd52614b1e6b7cb33/idris_doc_2.html

https://htmlpreview.github.io/?https://gist.githubusercontent.com/jeetu7/2873ac9befd63b1b0ef87347b5e41540/raw/3423e337d024df2f41653b2bd52614b1e6b7cb33/idris_doc_2.html#line-5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants