Help with table parser thing, for my CCbrowser2.0

Started by SamH, Nov 07, 2020, 04:19 PM

Previous topic - Next topic

SamH

I got a table like

{
    {
        {
            "Hello"        --That is the content of the paragraph element
            _attr = {
                style = "color: green;",
                id="title",
            },
            _tag = "p",
        },
        _attr = {},
        _tag = "body",
    },
    _attr = {},
    _tag = "html,
}
Now how do I find all elements with a
  • some content
  • some id
  • some attributes
  • Also some tag
Like Jqurey selectors, It may be a big question. Also the table comes from an xml parser (that i'm using html)

Lupus590

There is no built in ways of doing this in Lua, which means that you are going to have to implement it yourself.

At a guess, you will need to do some string processing to find out what things the user is looking for. You then will have to loop through the top level with a depth or breadth first search and make a table of results and then return the result once you have gon through the entire constuct.

Looking at the implementation of actual jqurey might be helpful.

SamH

#2
So far I made this, It returns all the "content" of all elements, how do I expand it to what I want?
gout = {}

function parse(dtable, out)
for i,v in ipairs(dtable) do
if type(v) == "table" then
parse(v, out)
else
table.insert(out, v)
end
end
end
parse(dom, gout) -- That dom is the table i want to parse
print(textutils.serialize(gout))

QuickMuffin8782

Well, what's needed on parsing out your code is to make sure you add a way to write it out by using the window API. Also you might want to re-draw the page if the screen size is changed. Also the parsing could be used for if the tags are the exact needed. You'll need to setup tables to check the tag and attributes.
"The Blue Blur" - Working on Net Star OS, a new frontier for Red Star OS 3.0
linktr.ee/quickmuffin8782

SamH

I am planing to use the window api eventually , like my 1.0 version.
Just testing the parser thingy before I do

Also how is your OS going @QuickMuffin8782

QuickMuffin8782

Quote from: SamH on Nov 07, 2020, 07:25 PMI am planing to use the window api eventually , like my 1.0 version.
Just testing the parser thingy before I do

Also how is your OS going @QuickMuffin8782
It's haven't been in dev latley. I can use a hand if you'd like. BTW I sent a invitation to a gitter in PM.
"The Blue Blur" - Working on Net Star OS, a new frontier for Red Star OS 3.0
linktr.ee/quickmuffin8782

SamH


QuickMuffin8782

Check your PM for the invite. I'll get you into XenusSoft as a developer.
"The Blue Blur" - Working on Net Star OS, a new frontier for Red Star OS 3.0
linktr.ee/quickmuffin8782