') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); Booleans might not be parsing properly? · Issue #76 · boolangery/py-lua-parser · GitHub
Skip to content

Booleans might not be parsing properly? #76

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