Syntax Error: Unexpected Newline
Opened this issue · 2 comments
I found this error. This error is a parse error on line 11. A newline character was encountered unexpectedly instead of one of the expected tokens, indicating a syntax error in the code.
Code:
graph TB
U["Usuario"] -- "Inicia sesión" --> L["Página de Préstamo"]
L -- "Click en Añadir Artículo" --> AI["Formulario de Añadir Artículo"]
AI -- "Llena el formulario y añade accesorio" --> AC["Formulario de Accesorios"]
AC -- "Marca la casilla de Activo y guarda" --> AI
AI -- "Guarda el artículo" --> ID["Página de Detalles del Artículo"]
ID -- "El accesorio aparece como Activo" --> E["Editar Artículo"]
E -- "El accesorio aparece como Activo" --> EA["Editar Accesorio"]
EA -- "La casilla de Activo está desmarcada" --> E
E -- "Guarda sin cambios" --> ID
ID -- "El accesorio aparece como Inactivo"
linkStyle 0 stroke:#2ecd71,stroke-width:2px;
linkStyle 1 stroke:#2ecd71,stroke-width:2px;
linkStyle 2 stroke:#2ecd71,stroke-width:2px;
linkStyle 3 stroke:#2ecd71,stroke-width:2px;
linkStyle 4 stroke:#2ecd71,stroke-width:2px;
linkStyle 5 stroke:#2ecd71,stroke-width:2px;
linkStyle 6 stroke:#2ecd71,stroke-width:2px;
linkStyle 7 stroke:#2ecd71,stroke-width:2px;
linkStyle 8 stroke:#2ecd71,stroke-width:2px;
Error:
Parse error on line 11:
...arece como Inactivo" linkStyle 0 strok
-----------------------^
Expecting 'SPACE', 'GRAPH', 'DIR', 'subgraph', 'end', 'AMP', 'ALPHA', 'COLON', 'TAGEND', 'START_LINK', 'LINK', 'STYLE', 'LINKSTYLE', 'CLASSDEF', 'CLASS', 'CLICK', 'DOWN', 'UP', 'DEFAULT', 'NUM', 'COMMA', 'MINUS', 'BRKT', 'DOT', 'PCT', 'TAGSTART', 'PUNCTUATION', 'UNICODE_TEXT', 'PLUS', 'EQUALS', 'MULT', 'UNDERSCORE', got 'NEWLINE'
Solution:
While working on the Mermaid diagram for the project, I discovered a small error in the diagram syntax which was causing a parsing error. The error was due to a line of code where a connection was made without specifying a destination node. Mermaid syntax requires every connection to have both a source and a destination node.
Specifically, the line of code ID -- "El accesorio aparece como Inactivo" was missing a destination. As such, the diagram could not be generated due to this incomplete instruction. The parser was essentially left waiting for further instructions that never arrived, hence the error.
To resolve this issue, I added a destination node to this line, which I named "Fin". This node represents the end of the workflow in the diagram. The corrected line now reads ID -- "El accesorio aparece como Inactivo" --> F["Fin"].
Moreover, I ensured that all link styles were immediately followed by the connections to which they apply.
With these changes, the diagram now correctly represents our intended process flow and generates without error.
Code:
graph TB
U["Usuario"] -- "Inicia sesión" --> L["Página de Préstamo"]
L -- "Click en Añadir Artículo" --> AI["Formulario de Añadir Artículo"]
AI -- "Llena el formulario y añade accesorio" --> AC["Formulario de Accesorios"]
AC -- "Marca la casilla de Activo y guarda" --> AI
AI -- "Guarda el artículo" --> ID["Página de Detalles del Artículo"]
ID -- "El accesorio aparece como Activo" --> E["Editar Artículo"]
E -- "El accesorio aparece como Activo" --> EA["Editar Accesorio"]
EA -- "La casilla de Activo está desmarcada" --> E
E -- "Guarda sin cambios" --> ID
ID -- "El accesorio aparece como Inactivo" --> F["Fin"]
linkStyle 0 stroke:#2ecd71,stroke-width:2px;
linkStyle 1 stroke:#2ecd71,stroke-width:2px;
linkStyle 2 stroke:#2ecd71,stroke-width:2px;
linkStyle 3 stroke:#2ecd71,stroke-width:2px;
linkStyle 4 stroke:#2ecd71,stroke-width:2px;
linkStyle 5 stroke:#2ecd71,stroke-width:2px;
linkStyle 6 stroke:#2ecd71,stroke-width:2px;
linkStyle 7 stroke:#2ecd71,stroke-width:2px;
linkStyle 8 stroke:#2ecd71,stroke-width:2px;
Unfortunately gpt still makes mistakes when generating these diagrams. I don't think it can really be prevented