jbeard4 / SCION

SCXML/Statecharts in JavaScript, moved to gitlab: https://gitlab.com/scion-scxml/scion
https://scion.scxml.io
Apache License 2.0
149 stars 29 forks source link

incorrect line and column numbers #373

Open mattoshry opened 8 years ago

mattoshry commented 8 years ago

Running the following document through scxml-to-scjson:

<scxml xmlns="http://www.w3.org/2005/07/scxml"
  version="1.0"
  initial="s1">

<datamodel>
  <data id="counter"
    expr="0"/>
</datamodel>

<state id="s1">
  <transition target="pass"/>
</state>

<final id="pass"/>

</scxml>

yields the following {local.name, line, and column}:

onopentag scxml 2 15
onopentag datamodel 4 11
onopentag data 6 14
onopentag state 9 15
onopentag transition 10 29
onopentag final 13 18

Intuitively one would expect the line and column to reflect the location of the beginning of the start tag:

onopentag scxml 1 8
onopentag datamodel 5 12
onopentag data 6 9
onopentag state 10 8
onopentag transition 11 15
onopentag final 14 8

There are a couple of issues here:

  1. The SAX module provides line and column info using offset 0.
  2. The SAX module updates the line and column when it encounters a \n which, as demonstrated in the above example, may occur before the onopentag event is emitted after all the attributes of the tag are consumed.
mattoshry commented 8 years ago

The fix is to hook the onopentagstart event and track the state of the line and column for use when the onopentag event fires.

jbeard4 commented 6 years ago

@mattoshry Please try this again. SCION is now using a custom version of sax-js with better parsing behavior.