Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[AHK_L/v2] Yaml() - Yaml Parser (++JSON)


  • Please log in to reply
116 replies to this topic
hoppfrosch
  • Members
  • 399 posts
  • Last active: Feb 26 2016 05:31 AM
  • Joined: 25 Jan 2006
@HotKeyIt:

Latest version does not work with AHK 1.1.04.00 UNICODE - but works only with AHK 1.1.04.00 ANSI ... :(

noob1999
  • Members
  • 32 posts
  • Last active: Nov 05 2012 10:12 PM
  • Joined: 14 May 2011
Ok, thanks. Gotta switch to ANSI then.

I'd really like to know how to delete sequence values like:
Key:
  SubKey:
    - Dont Delete Me
    - Delete Me
    - Leave Me Here
I'd also like to know how you delete them using the older Yaml version with the Yaml_Delete(obj,"key.subkey"] style (if I recall correctly). I just couldn't find anything dealing with deleting them!

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008

Latest version does not work with AHK 1.1.04.00 UNICODE - but works only with AHK 1.1.04.00 ANSI ... :(

Can you try latest version.

I'd really like to know how to delete sequence values like...

I'd also like to know how you delete them using the older Yaml version with the Yaml_Delete(obj,"key.subkey"] style (if I recall correctly). I just couldn't find anything dealing with deleting them!

Sequence keys are saved in [""], you can access them using key.(sequence number). To remove you will need to use key[""].Remove(sequence number).
yml=										; sample yaml
(
Key:
  SubKey:
    - Dont Delete Me
    - Delete Me
    - Leave Me Here
)
y:=Yaml(yml,0)							   	; create yaml object from text
MsgBox % y.Dump()						   	; show content
y.key.subkey.(2):=""					   	; set item to empty
MsgBox % y.Dump()				   			; show content
y.key.subkey[""].Remove(2)		   		; remove item from object
MsgBox % y.Dump()					   		; show content
FileAppend,% y.Dump(),C:\Temp\MyYaml.yml	; save yaml to file.

Does Yaml_Delete in old version not work for you?

hoppfrosch
  • Members
  • 399 posts
  • Last active: Feb 26 2016 05:31 AM
  • Joined: 25 Jan 2006

Can you try latest version.



Did the test - and it still failed with Unicode versions ...

They GUI shows up - but moving the mouse on the GUI AHK 1.1.04.00 Unicode still crashes .... (after a few seconds)

_________________________
;     (.)~(.)   
;    (-------)                                    
;---ooO-----Ooo---------------------------------------------------
;    Hoppfrosch  - AHK 1.1.04.00 Unicode 32bit on Win7 Ultimate
;-----------------------------------------------------------------                        
;    ( )   ( )                            
;    /|\   /|\


HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
ObjTree was not using latest Struct version :oops:
Download ObjTree again and it should work fine ;)

  • Guests
  • Last active:
  • Joined: --
Thanks.

What am I doing wrong here or is this how it's supposed to be:

Key:
  - Item1
  - Item2
  - Item3
is shown in ObjTree as
- Key
  -
    1
    2
    3
There's an empty object below Key, which I don't think should be there.

How should I format the Yaml file to get it without the empty object?

  • Guests
  • Last active:
  • Joined: --
If instead of - Item I used Item : with no value so everything would be objects, they'd look as intended in ObjTree. Would that have drawbacks compared to having them as sequence items?

  • Guests
  • Last active:
  • Joined: --
I can shorten an object "path" from "Object.Long.Way.To.Get.There" to "Work" by

Work := Object.Long.Way.To.Get.There

so "Work" references, if that's the right term, "Object.Long.Way.To.Get.There" and then I can do MsgBox % Work.Dump()

Here's my problem:

I store "Object.Long.Way.To.Get.There" in YAML in a key "Object.Work". I retrieve it by

Work := Object.Work

Now "Work" contains "Object.Long.Way.To.Get.There" but Work.Dump() doesn't work. Apparently "Work" doesn't refer to the object but just contains the text.

How can I make it work?

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008

If instead of - Item I used Item : with no value so everything would be objects, they'd look as intended in ObjTree. Would that have drawbacks compared to having them as sequence items?

Sequence Items are saved in [""] as an array. Everything else is saved as Item:Value pair. The drawback is that object are automatically sorted alphabetically so if you like to keep the order you will have to prefix them with numbers for example.
1Item: Value
2AnotherItem: Value

Here's my problem:

I store "Object.Long.Way.To.Get.There" in YAML in a key "Object.Work". I retrieve it by

Work := Object.Work

Now "Work" contains "Object.Long.Way.To.Get.There" but Work.Dump() doesn't work. Apparently "Work" doesn't refer to the object but just contains the text.

How can I make it work?

Work does not contain an object here only the value so you cannot use Dump here.
You can simpy do:
Dump:=IsObject(Work)?Work.Dump():Work


hoppfrosch
  • Members
  • 399 posts
  • Last active: Feb 26 2016 05:31 AM
  • Joined: 25 Jan 2006

ObjTree was not using latest Struct version :oops:
Download ObjTree again and it should work fine ;)

Yup - now it works fine with AHK-Unicode ... Thx!

  • Guests
  • Last active:
  • Joined: --
Is there a way I could make "Work" contain a reference to the object, not just the string - as if I had typed it there in code (which does of course work)?

Can I turn a string into a reference to an object (that has the name f the string)? That's what this seems to call for.

Is that possible in AHK?

If not, how can I use values retrieved from the outside as strings, for these kinds of purposes? I can't hard-code the values in the code - that value needs to vary so it needs to be stored outside the code.

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
Like this?
MyObject:={a:1}
yaml=
(
Object:
	Work: Value
)
y:=Yaml(yaml,0)
y.Object.work:=MyObject
MsgBox % y.Dump()
MyObject.Remove("a")
Loop 5
	MyObject.Insert(A_Index,Chr(A_Index+64))
MsgBox % y.Dump()
Or do you mean to refference within definition of yaml?
This is not possible currently.

  • Guests
  • Last active:
  • Joined: --
That didn't do anything. Like this:
yaml=
(
Object1:
  Object2:
    Object3:
      Object4:
        Object5:
           Object6:
             Stuff:
               - Item1
               - Item2
Shortcut: y.Object1.Object2.Object3.Object4.Object5.Object6
)
y:=Yaml(yaml,0)
MsgBox % y.Dump()

; I enter it manually here
ThisWorks := y.Object1.Object2.Object3.Object4.Object5.Object6

MsgBox % ThisWorks
; Nothing is shown because it refers to the object

MsgBox % ThisWorks.Stuff.Dump()
; Result
; - Item1
; - Item2

; But I should get it from the Shortcut key
DoesntWork := y.Shortcut

MsgBox % DoesntWork
; Contains string y.Object1.Object2.Object3.Object4.Object5.Object6

MsgBox % DoesntWork.Stuff.Dump()
;Empty results


  • Guests
  • Last active:
  • Joined: --
Or it did, in a way (I there was an incomplete version first), but that didn't remove the need to type y.Object.work by hand first.

  • Guests
  • Last active:
  • Joined: --
So the problem is essentially this:

I want to have this huge deep structure in YAML, but I don't want to have them littering my code. It's like setting A_WorkingDir to some deep folder, not typing the whole path every time.