BlueBrain / nmodl

Code Generation Framework For NEURON MODeling Language
https://bluebrain.github.io/nmodl/
Apache License 2.0
49 stars 15 forks source link

Bad error message for invalid local name. #1217

Open 1uc opened 4 months ago

1uc commented 4 months ago

The following MOD file:

$ cat invalid_name.mod
NEURON {
    SUFFIX invalid_name
}

INITIAL {
    LOCAL _kf
}

fails as follows:

[NMODL] [info] :: Processing invalid_name.mod
terminate called after throwing an instance of 'std::runtime_error'
  what():  NMODL Parser Error : syntax error, unexpected ., expecting NAME [Location : 6.11]
    LOCAL _kf
----------^

[1]    31242 IOT instruction (core dumped)  nmodl invalid_name.mod

I'd like to highlight that it blames a . when the offending character is a _.

Note that this is the better variation of the error, for intermediate transformations the error might be:

terminate called after throwing an instance of 'std::runtime_error'
  what():  NMODL Parser Error : syntax error, unexpected . [Location : 1.29]
----------------------------^
JCGoran commented 4 months ago

With some figuring out how to toggle debugging information:

$ nmodl invalid_name.mod
Starting parse
Entering state 0
Stack now 0
Reading a token
--(end of buffer or a NUL)
--accepting rule at line 183("NEURON")
Next token is token NEURON (1.1-6: )
Reducing stack by rule 3 (line 404):
-> $$ = nterm all (invalid_name.mod:1.1: )
Entering state 3
Stack now 0 3
Next token is token NEURON (1.1-6: )
Shifting token NEURON (1.1-6: )
Entering state 25
Stack now 0 3 25
Reading a token
--accepting rule at line 375(" ")
--accepting rule at line 316("{")
Next token is token { (1.8: )
Shifting token { (1.8: )
Entering state 94
Stack now 0 3 25 94
Reducing stack by rule 283 (line 1949):
-> $$ = nterm neuron_statement (1.9: )
Entering state 132
Stack now 0 3 25 94 132
Reading a token
--accepting rule at line 390("
    SUFFIX invalid_name")
LINE 2: SUFFIX invalid_name
--accepting rule at line 375(" ")
--accepting rule at line 375(" ")
--accepting rule at line 375(" ")
--accepting rule at line 375(" ")
--accepting rule at line 183("SUFFIX")
Next token is token SUFFIX (2.5-10: )
Shifting token SUFFIX (2.5-10: )
Entering state 230
Stack now 0 3 25 94 132 230
Reading a token
--accepting rule at line 375(" ")
--accepting rule at line 183("invalid_name")
Next token is token NAME (2.12-23: )
Shifting token NAME (2.12-23: )
Entering state 74
Stack now 0 3 25 94 132 230 74
Reducing stack by rule 336 (line 2246):
   $1 = token NAME (2.12-23: )
-> $$ = nterm NAME_PTR (2.12-23: )
Entering state 349
Stack now 0 3 25 94 132 230 349
Reducing stack by rule 284 (line 1952):
   $1 = nterm neuron_statement (1.9: )
   $2 = token SUFFIX (2.5-10: )
   $3 = nterm NAME_PTR (2.12-23: )
-> $$ = nterm neuron_statement (1.9-2.23: )
Entering state 132
Stack now 0 3 25 94 132
Reading a token
--accepting rule at line 390("
}")
LINE 3: }
--accepting rule at line 320("}")
Next token is token } (3.1: )
Shifting token } (3.1: )
Entering state 231
Stack now 0 3 25 94 132 231
Reducing stack by rule 282 (line 1936):
   $1 = token NEURON (1.1-6: )
   $2 = token { (1.8: )
   $3 = nterm neuron_statement (1.9-2.23: )
   $4 = token } (3.1: )
-> $$ = nterm neuron_block (1.1-3.1: )
Entering state 61
Stack now 0 3 61
Reducing stack by rule 22 (line 504):
   $1 = nterm neuron_block (1.1-3.1: )
-> $$ = nterm declare (1.1-3.1: )
Entering state 38
Stack now 0 3 38
Reducing stack by rule 7 (line 422):
   $1 = nterm all (invalid_name.mod:1.1: )
   $2 = nterm declare (1.1-3.1: )
-> $$ = nterm all (invalid_name.mod:1.1-3.1: )
Entering state 3
Stack now 0 3
Reading a token
--accepting rule at line 390("
")
LINE 4: 
--accepting rule at line 390("
INITIAL {")
LINE 5: INITIAL {
--accepting rule at line 183("INITIAL")
Next token is token INITIAL1 (5.1-7: )
Shifting token INITIAL1 (5.1-7: )
Entering state 19
Stack now 0 3 19
Reading a token
--accepting rule at line 375(" ")
--accepting rule at line 316("{")
Next token is token { (5.9: )
Shifting token { (5.9: )
Entering state 69
Stack now 0 3 19 69
Reading a token
--accepting rule at line 390("
    LOCAL _kf")
LINE 6: LOCAL _kf
--accepting rule at line 375(" ")
--accepting rule at line 375(" ")
--accepting rule at line 375(" ")
--accepting rule at line 375(" ")
--accepting rule at line 183("LOCAL")
Next token is token LOCAL (6.5-9: )
Shifting token LOCAL (6.5-9: )
Entering state 22
Stack now 0 3 19 69 22
Reading a token
--accepting rule at line 375(" ")
--accepting rule at line 421("_")
Next token is token . (6.11: )
Exception caught: cleaning lookahead and stack

Relevant code seems to be here:

https://github.com/BlueBrain/nmodl/blob/2c7c3a9a390f543c7ea8bd5170504812648231c8/src/parser/nmodl_driver.hpp#L68-L75

Setting all of the above to true reveals the above output.