Skip to content

Booleans might not be parsing properly? #76

@tetoNidan

Description

@tetoNidan

OS: Arch
python venv version: 3.14.3
luaparser version: 4.0.1
install method: pip

Simplified lua file:

hl.monitor({ output = "eDP-2", disabled = true })

hl.monitor({
	output = "DP-1",
	mode = "2560x1440@144",
	position = "0x0",
	scale = 0.80,
	bitdepth = 10,
	cm = "hdr",
})

-- unscale XWayland
hl.config({
	xwayland = {
		force_zero_scaling = true, -- unscale XWayland
	},
})

-- toolkit-specific scale
hl.env("GDK_SCALE", "2") -- GDK toolkit-specific scale
hl.env("XCURSOR_SIZE", "32") -- X11 toolkit-specific scale

Python call:

with Popen(["luaparser", self.display_conf], stdout=PIPE, stderr=PIPE) as data:
    j_data = loads(data.communicate()[0])

    pprint(j_data, sort_dicts=False)

The output for hl.config that is using a boolian:

{'comments': [],
                    'wrapped': False,
                    'func': {'comments': [],
                             'wrapped': False,
                             'idx': {'comments': [],
                                     'wrapped': False,
                                     'id': 'config',
                                     'attribute': None},
                             'value': {'comments': [],
                                       'wrapped': False,
                                       'id': 'hl',
                                       'attribute': None},
                             'notation': {}},
                    'args': [{'comments': [],
                              'wrapped': False,
                              'fields': [{'comments': [],
                                          'wrapped': False,
                                          'key': {'comments': [],
                                                  'wrapped': False,
                                                  'id': 'xwayland',
                                                  'attribute': None},
                                          'value': {'comments': [],
                                                    'wrapped': False,
                                                    'fields': [{'comments': [{'comments': [],
                                                                              's': '-- '
                                                                                   'unscale '
                                                                                   'XWayland',
                                                                              'is_multi_line': False}],
                                                                'wrapped': False,
                                                                'key': {'comments': [],
                                                                        'wrapped': False,
                                                                        'id': 'force_zero_scaling',
                                                                        'attribute': None},
                                                                'value': {'comments': [],
                                                                          'wrapped': False},
                                                                'between_brackets': False}]},
                                          'between_brackets': False}]}]

The output for one of the hl.monitor's that is using a boolean:

'body': [{'comments': [],
                    'wrapped': False,
                    'func': {'comments': [],
                             'wrapped': False,
                             'idx': {'comments': [],
                                     'wrapped': False,
                                     'id': 'monitor',
                                     'attribute': None},
                             'value': {'comments': [],
                                       'wrapped': False,
                                       'id': 'hl',
                                       'attribute': None},
                             'notation': {}},
                    'args': [{'comments': [],
                              'wrapped': False,
                              'fields': [{'comments': [],
                                          'wrapped': False,
                                          'key': {'comments': [],
                                                  'wrapped': False,
                                                  'id': 'output',
                                                  'attribute': None},
                                          'value': {'comments': [],
                                                    'wrapped': False,
                                                    's': 'eDP-2',
                                                    'raw': 'eDP-2',
                                                    'delimiter': {}},
                                          'between_brackets': False},
                                         {'comments': [],
                                          'wrapped': False,
                                          'key': {'comments': [],
                                                  'wrapped': False,
                                                  'id': 'disabled',
                                                  'attribute': None},
                                          'value': {'comments': [],
                                                    'wrapped': False},
                                          'between_brackets': False}]}]

Edit: Ignore this below here I'm pretty sure this is operator error. I put a try/catch for the AttributeError to bypass the error and found that the to_json() does not do what I thought it would in this instance.

The below is probably a separate issue or user error?
Also I tried to use the .to_json() method but was unclear if I was using it wrong, here is the code:

from luaparser import ast

with open("../../hyprconfigs/monitors.lua", 'r') as _file:
     l_file = ast.parse(_file.read())

l_file.to_json()

the error from the above code:

File /lib/python3.14/site-packages/luaparser/astnodes.py:113, in Node.line(self)
    110 @property
    111 def line(self) -> Optional[int]:
    112     """Line number."""
--> 113     return self._tokens[0].line if self._tokens else None

AttributeError: 'Chunk' object has no attribute '_tokens'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions