jscad / OpenJSCAD.org

JSCAD is an open source set of modular, browser and command line tools for creating parametric 2D and 3D designs with JavaScript code. It provides a quick, precise and reproducible method for generating 3D models, and is especially useful for 3D printing applications.
https://openjscad.xyz/
MIT License
2.61k stars 511 forks source link

OpenSCAD Wrong line indication on import error messages #1024

Open udif opened 2 years ago

udif commented 2 years ago

Expected Behavior

When an error is encountered, report the correct line number.

Actual Behavior

Under Window, the line number reported is 2 * the actual line number, probably due to \r\n counted as two lines.

Steps to Reproduce the Problem

  1. Create a fake SCAD file with a few comment lines, then a dummy error:

test.scad:

//a
//b
//c
xxxxx

And the container OpenJSCAD file:

var parser = require('@jscad/openscad-openjscad-translator')
var fs = require('fs')

var openSCADText = fs.readFileSync("test.scad", "UTF8")
var openJSCADResult = parser.parse(openSCADText)

console.log(openJSCADResult)
  1. Now run it:
    
    node ./cli.js test.js
    JSCAD: generating output
    from:  test.js
    to:  test.stl (STereoLithography, ASCII)

Function { message: "Parse error on line 7:\n\r\r\rxxxxx\r\n---------^\nExpecting '(', '=', got '1'", hash: { text: '', token: 1, line: 8, loc: { first_line: 7, last_line: 7, first_column: 0, last_column: 5 }, expected: [ "'('", "'='" ] } }


  3. As you can see, an error is reported for line 8, not 4.

## Specifications

  - Version: [Release : 2022 MAR 03](https://github.com/jscad/OpenJSCAD.org/commit/317c2ada65f7fb5d4e0b579feb1e45c5f1c79b51)
  - Platform: Windows 10
  - Environment: Chrome (Version 98.0.4758.102 (Official Build) (64-bit)), Latest NodsJS LTS (16.14.0), npm 8.3.1

<!-- Love openjscad? Please consider supporting our collective:
👉  https://opencollective.com/openjscad/donate -->
z3dev commented 2 years ago

This is even worse in #881

z3dev commented 2 years ago

@udif sorry, but we have no plans to support SCAD to JSCAD translation at this time.

the version that you have been trying to used is very old; published 1.0.0-alpha.d0fb3056 • 3 years ago

i'll keep this issue open for those brave and bold enough to port this module to V2.