py-lua-parser icon indicating copy to clipboard operation
py-lua-parser copied to clipboard

Literal string gets evaluated as Lua code

Open bendrissou opened this issue 2 years ago • 2 comments

Hi,

When a Lua string starts with prefix \u, the string is parsed as Lua code. For example:

a="\u9"

Returns the following output:

line 1:2 token recognition error at: '"\u'
line 1:6 token recognition error at: '"\n'
{
    "Chunk": {
        "body": {
            "Block": {
                "body": [
                    {
                        "Assign": {
                            "targets": [
                                {
                                    "Name": {
                                        "id": "a",
                                        "start_char": 0,
                                        "stop_char": 0,
                                        "line": 1
                                    }
                                }
                            ],
                            "values": [
                                {
                                    "Number": {
                                        "n": 9,
                                        "start_char": 5,
                                        "stop_char": 5,
                                        "line": 1
                                    }
                                }
                            ],
                            "start_char": 0,
                            "stop_char": 5,
                            "line": 1
                        }
                    }
                ],
                "start_char": 0,
                "stop_char": 5,
                "line": 1
            }
        },
        "start_char": 0,
        "stop_char": 5,
        "line": 1
    }
}

Digit 9 is evaluated to Number. I was expecting everything enclosed in quotes to be String.

Is that correct?

bendrissou avatar Oct 02 '23 10:10 bendrissou

Hi @boolangery

Any new updates on this?

Thank you.

bendrissou avatar Jun 10 '24 14:06 bendrissou

Can you test it against master? Or give me a better code sample: a="\u9" does not compile on Lua 5.4

boolangery avatar Oct 27 '24 10:10 boolangery

Hi @boolangery

Here is a valid Lua example:

a="\u{9}"

The input value should be parsed as a UTF-8 value, but py-lua-parser returns the following output:

line 1:2 token recognition error at: '"\u'
line 1:8 token recognition error at: '"\n'

Chunk: {} 2 keys
  body: {} 2 keys
    Block: {} 2 keys
      body: [] 1 item
        0: {} 1 key          
          Assign: {} 3 keys
            targets: [] 1 item
              0: {} 1 key                
                Name: {} 2 keys
                  id: 'a'
            values: [] 1 item
              0: {} 1 key                
                Table: {} 2 keys
                  fields: [] 1 item
                    0: {} 1 key                      
                      Field: {} 4 keys
                        key: {} 2 keys
                          Number: {} 2 keys
                            n: 1
                        value: {} 2 keys
                          Number: {} 2 keys
                            n: 9
                        between_brackets: False

bendrissou avatar Nov 18 '24 16:11 bendrissou

Hi @boolangery Can you please confirm this?

bendrissou avatar Nov 19 '24 10:11 bendrissou

Please use last version it's already working on it

boolangery avatar Mar 12 '25 20:03 boolangery