ComputerCraft Forums

ComputerCraft => Ask a Pro => Topic started by: SamH on Nov 07, 2020, 04:19 PM

Title: Help with table parser thing, for my CCbrowser2.0
Post by: SamH on Nov 07, 2020, 04:19 PM
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
Like Jqurey selectors, It may be a big question. Also the table comes from an xml parser (that i'm using html)
Title: Help with table parser thing, for my CCbrowser2.0
Post by: Lupus590 on Nov 07, 2020, 05:12 PM
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.
Title: Help with table parser thing, for my CCbrowser2.0
Post by: SamH on Nov 07, 2020, 05:30 PM
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))
Title: Help with table parser thing, for my CCbrowser2.0
Post by: QuickMuffin8782 on Nov 07, 2020, 07:12 PM
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.
Title: Help with table parser thing, for my CCbrowser2.0
Post by: SamH on Nov 07, 2020, 07:25 PM
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
Title: Help with table parser thing, for my CCbrowser2.0
Post by: QuickMuffin8782 on Nov 07, 2020, 07:31 PM
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.
Title: Help with table parser thing, for my CCbrowser2.0
Post by: SamH on Nov 07, 2020, 07:31 PM
np
Title: Help with table parser thing, for my CCbrowser2.0
Post by: QuickMuffin8782 on Nov 07, 2020, 07:33 PM
Check your PM for the invite. I'll get you into XenusSoft as a developer.