Giter Club home page Giter Club logo

Comments (3)

IogaMaster avatar IogaMaster commented on September 27, 2024 1

Nevermind, we arent getting a nix lezer parser.

image

from motion-canvas.

IogaMaster avatar IogaMaster commented on September 27, 2024 1

https://github.com/tree-sitter/node-tree-sitter
Seems to almost match the api you use already.

from motion-canvas.

aarthificial avatar aarthificial commented on September 27, 2024

Here's a really simple example of using the shell parser from @codemirror/legacy-modes (There's a few more parsers there than the 15 you've mentioned):
image

Source code
import {StreamLanguage} from '@codemirror/language';
import {shell} from '@codemirror/legacy-modes/mode/shell';
import {Code, LezerHighlighter, makeScene2D} from '@motion-canvas/2d';
import {createRef, waitFor} from '@motion-canvas/core';

const Bash = new LezerHighlighter(StreamLanguage.define(shell).parser);

export default makeScene2D(function* (view) {
  const code = createRef<Code>();

  view.add(
    <Code
      ref={code}
      fontSize={28}
      highlighter={Bash}
      fontFamily={'JetBrains Mono, monospace'}
      offsetX={-1}
      x={-600}
      code={`\
#!/bin/bash

# start the server in HTTPS mode
cd web
sudo node ../server.js 443 'yes' >> ../node.log &

# here is how to stop the server
for pid in \`ps aux | grep 'node ../server.js' | awk '{print $2}'\` ; do
  sudo kill -9 $pid 2> /dev/null
done

exit 0
`}
    />,
  );

  yield* waitFor(0.6);
});

https://github.com/tree-sitter/node-tree-sitter
Seems to almost match the api you use already.

The rendering part of Motion Canvas doesn't run on Node.js. You'd need the WASM bindings.
The API is similar because Lezer is based on Treesitter.


I'm closing this issue because I'm not interested in working on this in the context of this repository.

The CodeHighlighter interface is independent of Lezer and can be used to integrate any parser/highlighter solution into Motion Canvas without changing our code. When designing the interface, I made sure to account for Treesitter as that's what I used for prototyping.

Sadly, their documentation (both the wasm and node.js one) does not describe how to highlight the parsed tree so I gave up on the implementation and went for Lezer.

If anyone wants to give Treesitter a try, they can easily do that in their own npm package because, again, it's just a matter of implementing an interface - no changes to this repo necessary. Once a package like this exists I'll gladly talk about upstreaming it here.

from motion-canvas.

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.