Page 1 of 1

JScript syntax file: common class member lists

Posted: 21 Feb 2010 14:10
by Marcus
Hi everyone,

First of all, I wish make my personal congratualtions to Rickard for the x[index].member implementation: with this feature, writing JScritp code, with a well defined JScript syntax file, has become very very easy and funny!

Yesterday, I started to add a lot of class and class member to the JScript syntax file. During this activity I see that more member lists are common to many class. For example: the

Code: Select all

HTMLElement
members (properties, methods, events and arrays) are applyed to

Code: Select all

anchors
,

Code: Select all

forms
ecc.
So, for the

Code: Select all

document.anchors[].
array I have to define the specific members for the anchor class and then add the members of the

Code: Select all

HTMLElement
class (beacuse anchor is actually an object of

Code: Select all

HTMLElement
class). In the same mode, I have define the specific members for the

Code: Select all

form
class (of the array

Code: Select all

document.forms[].
) and then add all the members for

Code: Select all

HTMLElement
to the form class.

I think that is possible to reduce a lot of work if we can define "virtual" class and use that as item in the class member list. A "virtual" class in not a part of class list (allow autocompletion to distinguish real class from virtual class), but is a specific list. Then, when we build the class members list, we can add specific class items and add all the members of a "virtual" class, simply specifing the name of the virtual class.
For example, in the

Code: Select all

document.anchors[].
class I add

Code: Select all

href
as proper member and, adding

Code: Select all

HTMLElement
as "virual" class, I can automatically add all the member of that "virtual" class to the

Code: Select all

document.anchors[].
!

Do you think that is a reasonable/praticable solutions?

Thankyou in advance for your comments

Posted: 21 Feb 2010 14:30
by Rickard Johansson
Maybe something like this?

Code: Select all

[AutoComplete]
@BaseClass=members common in most classes
FooClass=@BaseClass|other members not in the BaseClass list
I guess we could add @Class lists in its own section e.g.

[BaseClassLists]
@BaseClass=...

Posted: 22 Feb 2010 21:22
by Marcus
Oh Yes Rickard, it will works fine.
I think that is better to leave the [AutoComplete] section as it is and add a new [BaseClassList] section.
Please, take a look to the following real case

Code: Select all

[AutoComplete]
document.archors[].=href|href+p##@HTMLElement##

[BaseClassList]
HTMLElement=name|name+p##@attributes[].|attributes[]+n##@childNodes[].|childNodes[]+n##setAttribute()|setAttribute+m##getAttribute()|getAttribute()+m##...
attributes[].=name|name+p##value|value+p##nodeValue|nodeValue+p
childNodes[].=@HTMLElement
-- 1st case --
we write the following code

Code: Select all

document.anchors[x].
we looking for document.anchors[]. in the [AutoComplete] section, finding realted match.
The list in the autocomplete pop-up window will show href and the "expansion" of @HTMLElement, that

href
name
attributes[]
childNodes[]
setAttribute()
getAttribute()
...

-- 2 case --
we write the code

Code: Select all

document.anchors[x].attributes[y].
We looking for document.archors[].attributes[]. in the [AutoComplete] section, finding no match.
We can stripping-out the last part of the class chain (attributes[].) obtaining document.anchors[]. that exists in the [AutoComplete] section.
Expangin @HTMLElement, and selecting only the members starting with the '@' character, we obtain attributes[]. and childNodes[].; we can combine these two with the starting code, obtaining

document.anchors[].attributes[].
document.anchors[].childNodes[].

Does any of these match the starting code? Yes: we have document.archors[].attributes[]. !!
So we can list the member of attributes[]. in the [BaseClassList] section, obtain the following items to show in the autocomplete pop-up window.

name
value
nodeValue

-- 3rd case --
we write the code

Code: Select all

document.anchors[x].childNodes[y].
So, we looking for document.anchors[].childNodes[]. in the [AutoComplete] section, finding no match.
Again, we can stripping-out the last part of the code and looking for document.anchors[]. in the [AutoComplete] section.
Expanding the @HTMLElement, only for the members that start with the '@' character, we have attributes[]. and childNodes[].; combine these members with the starting code, we can have

document.anchors[].attributes[].
document.anchors[].childNodes[].

The second item, match the code of the 3rd case, so we can search the childNodes[]. in the [BaseClassList] section and expand the @HTMLElement, obtaining the follogin items to show in the autocomplete pop-up window

name
attributes[]
childNodes[]
getAttribute()
setAttribute()
...

What do you think about?

Posted: 23 Feb 2010 12:08
by Rickard Johansson
It's a bit to complicated. I want it to be rather simple and the [BaseClassList] , or whatever I decide to call it, should just be a list of variables with a member list.

Code: Select all

[BaseClassList]
@HTMLElement=name|name+p##attributes[]|attributes[]+n##childNodes[]|childNodes[]+n##setAttribute()|setAttribute+m##getAttribute()|getAttribute()+m##...

[AutoComplete]
document.archors[].=href|href+p##@HTMLElement##
document.archors[].attributes[].=name|name+p##value|value+p##nodeValue|nodeValue+p
document.archors[].childNodes[].=@HTMLElement 

Posted: 23 Feb 2010 14:00
by Marcus
Yes Rickard, simplify is always right!

Please note that attributes[]. and childNodes[]. (like other base class) could be base-class themself, because could be use in other class (some class could use only attributes[]., some other class could use only childNodes).
But this is only an example!

Thank-you very much for your support.