Sublime Forum

(ST2|ST3) SerializedDataConverter (Beta)

#1

ST2 and ST3: github.com/facelessuser/SerializedDataConverter

This will be the successor of PlistJsonConverter. SerializedDataConverter will convert plists, yaml and json to each other.

I have added a built-in yaml highlighter because sublime’s yaml highlighter isn’t even that usable. You can override the one I provided with Sublime’s, or you can override with others such as AAAPackageDev’s yaml. I personally am not using AAAPackageDev at this time its rules were a bit too sublime settings specific with keys and some other minor things. With that said, mine has flaws as well. I am working on yet another yaml highlighter to replace the current one which uses a different approach, to hopefully improve highlighting overall with yaml, and I also plan to look into AAAPackageDev’s version as well to see if its flaws can be improved and even replace mine. Overall, I feel that PackageDev’s and mine will allow you to edit languages and Sublime settings much better than Sublime’s built-in one. If you want to use them to edit general yaml files outside of sublime settings, you can evaluate which one works better for you, or use something else entirely.

Example PHP conversion:
[pre=#151515] beginCaptures:
‘1’:
name: storage.modifier.php
‘2’:
name: storage.type.function.php
‘3’:
name: storage.modifier.reference.php
‘4’:
name: support.function.magic.php
‘5’:
name: entity.name.function.php
‘6’:
name: punctuation.definition.parameters.begin.php
contentName: meta.function.arguments.php
end: ())
endCaptures:
‘1’:
name: punctuation.definition.parameters.end.php
name: meta.function.php
patterns:
- include: ‘#function-arguments
- include: ‘#invoke-call
- begin: |-
(?xi)\s*(?=
[a-z_0-9$\]+(::slight_smile:
(?:
([a-z_][a-z_0-9])\s(
|
(($+)[a-z_\x{7f}-\x{ff}][a-z0-9_\x{7f}-\x{ff}])
|
([a-z_\x{7f}-\x{ff}][a-z0-9_\x{7f}-\x{ff}]
)
)?
)
end: |-
(?x)(::slight_smile:
(?:
([A-Za-z_][A-Za-z_0-9])\s(
|
(($+)[a-zA-Z_\x{7f}-\x{ff}][a-zA-Z0-9_\x{7f}-\x{ff}])
|
([a-zA-Z_\x{7f}-\x{ff}][a-zA-Z0-9_\x{7f}-\x{ff}]
)
)?
endCaptures:[/pre]

I also added a little extra feature as well. When working with sublime settings, you can use !!regex (which is mapped to !!str for conversion), and it will highlight your data with regex highlighting. This way it isn’t too sublime-specific, but you can still use it to edit tmLanguage files.
[pre=#151515] ###################
# Lines
###################
# Scan the line for key value pairs
single-line:
begin: !!regex |-
(?x)^\ ](?:
(?:(-?])(?:\ \r\n]+))?
(?:
(\w(?:.
?^\ ])?|<<)(?:\ \r\n](:)(?:\ \r\n]+|(?=$))) |
(’]((?:(?:\.)|(?:^’\]|’{2}))
?)’])(:)(?:\ \r\n]+|(?=$))|
("]((?:(?:\.)|(?:^"\]|\"))*?)"])(:)(?:\ \r\n]+|(?=$))
)
)
beginCaptures:
‘1’: {name: keyword.operator.list.yaml-simple}
‘2’: {name: meta.tag.yaml-simple}
‘3’: {name: keyword.operator.key-separator.yaml-simple}
‘4’: {name: meta.tag.yaml-simple}
‘5’: {name: string.yaml-simple}
‘6’: {name: keyword.operator.key-separator.yaml-simple}
‘7’: {name: meta.tag.yaml-simple}
‘8’: {name: string.yaml-simple}
‘9’: {name: keyword.operator.key-separator.yaml-simple}
end: !!regex $
patterns:
- include: ‘#cast-values
- include: ‘#values

cast-values:
    patterns:
        -   captures:
                '1': {name: support.type.yaml-simple}
                '2': {name: keyword.operator.multi-line.yaml-simple}
                '3': {name: comment.yaml-simple}
            match: !!regex (?:(!!\w//]+) ]+)?(|>]-+\d\r\n]*) \r\n]*(#.*)?$
        -   begin: !!regex (!!regex) ]+
            beginCaptures:
                '1': {name: support.type.yaml-simple}
            end: !!regex (?=$)
            patterns:
            -   include: '#sublime-regex'
        -   begin: !!regex (!!\w//]+) ]+
            end: !!regex (?=$)
            patterns:
            -   include: '#values'[/pre]

Details are subject to change before release.

Anyways, if you wanted to play existing languages in yaml, this plugin will convert them over for you and provide a language file to edit it in. Then you can save it back to tmLanguage etc.

0 Likes

#2

Yes! Looking forward to using this!

0 Likes

#3

@icylace Give it a try github.com/facelessuser/SerializedDataConverter :smile:. Let me know how it works.

If you have old json languages, you can convert them to yaml as well. You can convert yaml, json, and plist between each other (at least for basic stuff, I am still not sure about all of the yaml features and if they all translate, but as far as sublime languages, themes, settings, they should all translate back and forth to any of the supported formats.

ST3 only right now.

0 Likes

#4

Small update. I broke inline associative arrays…whoops! It is fixed now.

0 Likes

#5

Now beta works for ST2 and ST3.

Includes fixes for better output, and fixes to the built-in tmLanguage. Remember, if you don’t like the yaml tmLanguage I provided, just override it in the settings file. I realize that most yaml tmLanguages have issues, and mine is no exception, so use the one that is best for you. I am working on yet another one to replace the current one I include (hopefully), I realized I would need a different approach to handle different formats of yaml to make this work as a decent general yaml language file, but again, this can always be overridden if you prefer other great yaml tmLanguages such as AAAPackageDev (one I am still looking into as a possible permanent replacement).

Updated OP

0 Likes

#6

Subscribing~ (you know there is no other way)

Edit: That reminds me: I actually worked on a syntax definition for generic YAML before the one I made for AAAPackageDev but eventually considered it to be too much of a hassle because YAML is not really a regex language and then didn’t look back at it again. I didn’t make much progress though so it’s not worth looking at.

0 Likes

#7

Yeah, I know what you mean. I had to take a break. It is so labor intensive to come up with a general YAMl language. The language is a bit too flexible when it comes to trying to highlight it. And everything can take on so many varying forms.

This gets tiring.
[pre=#141414]# map type multi | keyword
? !!str |- # comment 1
keyword

map type | multi | keyword

? !!str # comment 1
|- # comment 2
keyword

map | type | keyword

? # comment 1
!!str # comment 2
key:#w# or:d #comment 2

? !!str
33 #yes
:

map type keyword

? !!str keyword # comment 1

map | type | keyword

? # comment 1
!!str # comment 2
“keyword” # comment 3

map type keyword

? !!str ‘keyword’

map | type | keyword

  •         # comment 1
    
    !!str # comment 2
    keyword # comment 3

map type keyword

  • !!str keyword # comment 1

map | type | keyword

  •         # comment 1
    
    !!str # comment 2
    ‘value’ # comment 3

map | type | keyword

  •         # comment 1
    
    !!str # comment 2
    yes # comment 3

  • “name”: #wh# at # dd

“name”: !!regex (\t)#hello]
“name”: !!regex (\t) #hello][/pre]

0 Likes

#8

SerializedDataConverter has now replaced JsonPlistConverter in Package Control (though it does not right now include the discussed YAML tmLanguage file which is a separate side project that I will make available).

0 Likes

#9

Update so translation of PLIST date and data tags translate correctly between JSON, PLIST, and YAML.

See github.com/facelessuser/Seriali … r/issues/3 for more info.

0 Likes

#10

Can’t wait to have the better YAML.tmLanguage! mine looks horrible now when I convert from a complex plist

0 Likes

#11

I’ll post the old one I had this weekend; it is good enough for sublime stuff. The newer one is more solid, but I don’t have it complete enough to really be useful. I’ll be honest though, I don’t think the YAML tmLanguage will ever be perfect. It is such a hard language to highlight well with regex, but it will certainly be better than the default one.

Anyways, I don’t know when the new one will be done. I have to motivate myself to keep working on it :smile:, but I will post the current iteration I use for Sublime stuff.

Keep an eye out for FichteFoll’s project as well. I know he has taken it upon himself to produce a definitive package for working with YAML|PLIST|JSON. I don’t know how far out his project is, but maybe he will have the motivation and time to take his to a higher level.

I still have a couple of things I want to workout on this package in the conversion area; I keep flip flopping on how I want to handle some things.

0 Likes

#12

Update:

  • Better handling of timestamp and date objects
  • Make timestamp and date object detection during conversion optional
  • Make json binary backwards compatibility preservation of binary data optional
  • Give options of how to handle None objects when converting to plists: allow conversion to fail, strip them out, or set them to false
0 Likes