edubart / nelua-lang

Minimal, efficient, statically-typed and meta-programmable systems programming language heavily inspired by Lua, which compiles to C and native code.
https://nelua.io
MIT License
2.06k stars 67 forks source link

Not expected AST output for specific tests #150

Closed stefanos82 closed 3 years ago

stefanos82 commented 3 years ago

I'm studying syntaxdefs_spec and have found a mismatch between some tests.

For these two expect_ast() which I tested in my demo, I got different output:

the culprit

expect_ast('return [[\ntest]]', n.Block{n.Return{n.String{"test"}}})
expect_ast('return [[\ntest\n]]', n.Block{n.Return{n.String{"test\n"}}})

the output for return [[\ntest]]

Block {                                                                         
  Return {                                                                      
    String {                                                                    
      "\\ntest"                                                                 
    }                                                                           
  }                                                                             
}

the output for return [[\ntest\n]]

Block {                                                                         
  Return {                                                                      
    String {                                                                    
      "\\ntest\\n"                                                              
    }                                                                           
  }                                                                             
}
stefanos82 commented 3 years ago

Another observation is how single quotes when used are interpreted as double quotes.

This code expect_ast("return ''", n.Block{n.Return{n.String{''}}}) is been interpreted as

Block {
  Return {
    String {
      ""
    }
  }
}

and it's no different than expect_ast('return ""', n.Block{n.Return{n.String{""}}})

stefanos82 commented 3 years ago

Eemmm...seems like there's an issue in escape sequence ast as well:

  it("escape sequence", function()
    expect_ast([[return "\a"]], n.Block{n.Return{n.String{"\a"}}})
    expect_ast([[return "\b"]], n.Block{n.Return{n.String{"\b"}}})
    expect_ast([[return "\f"]], n.Block{n.Return{n.String{"\f"}}})
    expect_ast([[return "\n"]], n.Block{n.Return{n.String{"\n"}}})
    expect_ast([[return "\r"]], n.Block{n.Return{n.String{"\r"}}})
    expect_ast([[return "\t"]], n.Block{n.Return{n.String{"\t"}}})
    expect_ast([[return "\v"]], n.Block{n.Return{n.String{"\v"}}})
    expect_ast([[return "\\"]], n.Block{n.Return{n.String{"\\"}}})
    expect_ast([[return "\'"]], n.Block{n.Return{n.String{"\'"}}})
    expect_ast([[return "\""]], n.Block{n.Return{n.String{"\""}}})
...

I have tested it with:

return [[return "\a"]]
return [[return "\b"]]
return [[return "\f"]]
return [[return "\n"]]
return [[return "\r"]]
return [[return "\t"]]
return [[return "\v"]]
return [[return "\\"]]
return [[return "\'"]]
return [[return "\""]]

and produced the following output:

Block {
  Return {
    String {
      "return \"\\a\""
    }
  },
  Return {
    String {
      "return \"\\b\""
    }
  },
  Return {
    String {
      "return \"\\f\""
    }
  },
  Return {
    String {
      "return \"\\n\""
    }
  },
  Return {
    String {
      "return \"\\r\""
    }
  },
  Return {
    String {
      "return \"\\t\""
    }
  },
  Return {
    String {
      "return \"\\v\""
    }
  },
  Return {
    String {
      "return \"\\\\\""
    }
  },
  Return {
    String {
      "return \"\\'\""
    }
  },
  Return {
    String {
      "return \"\\\"\""
    }
  }
}
edubart commented 3 years ago

There aren't any issues there, all the above outputs is working as expected.