swc4j icon indicating copy to clipboard operation
swc4j copied to clipboard

Ast

Open HanzoDev1375 opened this issue 5 months ago • 8 comments

void debug() { try {

  // Create an instance of swc4j.
  Swc4j swc4j = new Swc4j();
  // Prepare a TypeScript code snippet.
  String code = "function add(a:number, b:number) { return a+b; }";
  // Prepare a script name.
  URL specifier = new URL("file:///storage/emulated/0/Apktool_M/abc.ts");
  // Prepare an option with script name and media type.
  Swc4jTranspileOptions options =
      new Swc4jTranspileOptions()
          .setSpecifier(specifier)
          .setMediaType(Swc4jMediaType.TypeScript)
          // Set capture tokens.
          .setCaptureTokens(true)
          .setParseMode(Swc4jParseMode.Script);
  // Parse the code.
  Swc4jParseOutput output = swc4j.parse(code, options);
  // Print the tokens.
  System.out.println("/*********************************************");
  System.out.println("         The tokens are as follows.");
  System.out.println("*********************************************/");
  output.getTokens().forEach(it ->{
	  binding.editor.setText(it.getSpan().getLine()+ it.getSpan().getColumn());
  });
} catch (Exception err) {
	
    binding.editor.setText(err.getLocalizedMessage());
}

}

Hello, I took this Java code from your blog. I just have one question. Why are the lines and columns not printed in my EditText when the code has an error in the for loop?

HanzoDev1375 avatar Jul 04 '25 21:07 HanzoDev1375

Please leave a repo with the issue you mentioned.

caoccao avatar Jul 05 '25 05:07 caoccao

Please leave a repo with the issue you mentioned.

This is my main problem, bro. When I want to analyze my JavaScript code, I want to get the line and column if I encounter an error and use it in my editor.

HanzoDev1375 avatar Jul 05 '25 06:07 HanzoDev1375

Please set a breakpoint and look inside. I don't understand why you want to add integer 'line' and integer 'column'.

caoccao avatar Jul 05 '25 15:07 caoccao

Please set a breakpoint and look inside. I don't understand why you want to add integer 'line' and integer 'column'.

Because I am developing my own IDE, I want to know when my code has errors so that I can give the line and column to my code. For example, see the following link https://github.com/HanzoDev1375/Ghostide/blob/main/app/src/main/java/io/github/rosemoe/sora/langs/javascript/BasicSyntaxJavaScriptAnalyzer.java#L64 I don't like my code parser to be with antlr4. I am looking for a powerful parser. Please help me.

HanzoDev1375 avatar Jul 05 '25 17:07 HanzoDev1375

Did you really understand my question? it.getSpan().getLine()+ it.getSpan().getColumn() only gives you one integer.

caoccao avatar Jul 05 '25 18:07 caoccao

Did you really understand my question? it.getSpan().getLine()+ it.getSpan().getColumn() only gives you one integer.

Honey, that's for the token. Did you see my code?

HanzoDev1375 avatar Jul 05 '25 18:07 HanzoDev1375

I don't think you are showing enough respect.

caoccao avatar Jul 05 '25 19:07 caoccao

I don't think you are showing enough respect.

I think you misunderstood what I meant. I need a feature to parse the code. If my code gives an error, I can display the error text and the line and column. like this error file in Main.js:1:40 So I need to get the line and column and apply it in my program so that a red wavy line is drawn under the word so that my user understands. We are now sending a sample image that works with the antlr4 parser.

Image

HanzoDev1375 avatar Jul 06 '25 06:07 HanzoDev1375