What kind of syntax is this (yaml, ini, ...)? - syntax

Could anybody help me figure out the syntax of the code below?
"AddonInfo"
{
"name" "Addon name"
"version" "Current Version"
"up_date" "Date of update"
"author_name" "Addon's Author"
"author_email" ""
"info" "Addon's Info"
"override" "0"
}

It's a Half-Life 2 (to be specific, garrys mod) Configuration File. I think it's only used by the source engine.
Edit:
A simple regexp to convert to JSON:
config_str.gsub(/(")\s*"(.*?)"/, '\1: "\2",').gsub(/(".*?")\s*{/, '\1: {')
Where gsub is the function for global replacement.

Probably just a custom configuration file used by whatever system you're currently looking at?
JSON would have colons as Josh has pointed out

Related

Atom Editor Syntax Highlighting for ini files as Java Properties

I am using Atom 1.33.0 on MacOS X 10.13 High Sierra
To configure atom to recognize files with the extension ".ini" as Java Properties and apply the appropriate syntax highlighter I checked the following links:
GitHub Atom: How to apply a particular syntax highlighting to some files based on name
https://discuss.atom.io/t/how-do-i-make-atom-recognize-a-file-with-extension-x-as-language-y/26539
https://flight-manual.atom.io/using-atom/sections/basic-customization/#finding-a-languages-scope-name
https://stackoverflow.com/a/51321435/6204861
https://discuss.atom.io/t/using-customfiletypes-to-change-the-language-for-html/40230
and assumed that the following config.cson would work:
"*":
core:
telemetryConsent: "no"
themes: [
"atom-light-ui"
"atom-light-syntax"
]
customFileTypes:
'source.Java Properties': [
'ini'
]
...
unfortunately this does not have the desired effect.
To find the correct name i opened an example Java Properties ".ini" file as "Plain Text". Then I changed the syntax highlighting manually to "Java Properties" by clicking in the bottom right corner. Then I pressed Alt-CMD-P which showed:
So "source.java-properties" should be the correct name.
I modified config.cson accordingly to:
"*":
core:
telemetryConsent: "no"
themes: [
"atom-light-ui"
"atom-light-syntax"
]
customFileTypes:
'source.java-properties': [
'ini'
]
And still it does not work.
What needs to be changed to make it work?
the coffeescript parser seems to be very picky about details
The following config.cson works:
"*":
core:
customFileTypes:
"source.java-properties": [
"ini"
]
disabledPackages: [
"welcome"
]
...

Bash: Add languages to Chromium

Is it possibe to use Bash to add languages to Chromium? That is, do the equivalent of going to Settings - Advanced - Languages in the Chromium GUI, activate the languages you want, and then activate spell-checking for the same languages? Had a look at this, but there doesn't seem to be anything that fits the bill.
Figured it out. The best way seems to be to add a Python block to read and manipulate the Preferences-file using the JSON library. Before you do anything, you need to get your bearings in the Preferences-file. What are the relevant elements that you need to change?
If you go to Preferences in the Chromium GUI, you can see that there are two relevant settings:
1) Languages:
2) Dictionaries (for spell check):
These can be found in the Preferences-file by pretty-printing the file in the terminal (improving it with pygmentize) or saving a pretty-printed output to a file:
less Preferences | python -m json.tool | pygmentize -g
or
~/.config/chromium/Default$ less Preferences | python -m json.tool >> ~/Documents/output.txt
Searching through the file for language settings, you will find two relevant elements:
"intl": {
"accept_languages": "en-US,en,nb,fr-FR,gl,de,gr,pt-PT,es-ES,sv"
},
and
"spellcheck": {
"dictionaries": [
"en-US",
"nb",
"de",
"gr",
"pt-PT",
"es-ES",
"sv"
],
"dictionary": ""
}
Before you do anything else, it is wise to backup the Preferences-file... Next,you can alter the language settings by adding the following python-block to the bash script:
python - << EOF
import json
import os
data = json.load(open(os.path.expanduser("~/.config/chromium/Default/Preferences"), 'r'))
data['intl'] = {"accept_languages": "en-US,en,nb,fr-FR,gl,de,pt-PT,es-ES,sv"}
data['spellcheck'] = {"dictionaries":["en-US","nb","de","pt-PT","es-ES","sv"],"dictionary":""}
with open(os.path.expanduser('~/.config/chromium/Default/Preferences'), 'w') as outfile:
json.dump(data, outfile)
EOF
In this case, the script will remove Greek from the available languages and the spellchecker. Note that in order to add languages, you need to know the language code accepted by Chromium.
You can find more on reading and writing JSON here and here, and more on how to include Python scripts in bash scripts here.

How to use YAML files with Vagrant?

I'm trying to improve my YAML file for my Vagrant project. According to this post, if I have something like this:
en:
site_name: "Site Name"
static_pages:
company:
description: ! '%{site_name} is an online system'
I should be able to print "Site Name is an online system", but I don't know how to use it inside my Vagrantfile.
I tried so far but I couldn't print it out properly, just this:
%{site_name} is an online system
This is how I'm using it:
require 'yaml'
set = YAML.load_file(ENV['DEVOPS_HOME'] + '/vagrant/server/settings.yml')
puts set['en']['static_pages']['company']['description']
as they say in the answer of the post
and then call in the appropriate view with the site name as a parameter
so you don't get directly after you load the yaml file the expected string, you need to match the parameter. one way you could work this in your Vagrantfile is
require 'yaml'
set = YAML.load_file(ENV['DEVOPS_HOME'] + '/vagrant/server/settings.yml')
str = set['en']['static_pages']['company']['description']
arg = {:site_name=> set['en']['site_name']}
p str % arg
will print out "Site Name is an online system"
The other way would be to use the answer from mudasobwa which is also detailed in the original post you reference
You might want to use YAML aliases to achieve this functionality:
en:
site_name: &site_name "Site Name" # declaring alias
static_pages:
company:
description:
- *site_name # reference
- "is an online system"
And later on:
puts set['en']['static_pages']['company']['description'].join(' ')

How to define default syntax on files without extension on Sublime Text 2?

I've read many posts dealing with this problem, but none has an answer to my question.
As said in the title, I would like to define a default syntax for all files which have no extension. In my case I would like to use the Shell syntax.
I've tried "View/Syntax/Open all with current extension as..." but for all files, I have to make again the manipulation.
I've tried the package "applySyntax" but it not seem to work with this configuration:
{
"name": "ShellScript/Shell-Unix-Generic",
"rules": [
{"file_name": "PRE_*$"}
]
}
All my files start with "PRE_[something]", someone know how to resolve this problem?
Thx!
I've found a Gist with a plugin to set the syntax based on the file name, I've modified it a bit to match files starting with PRE_:
import sublime_plugin
import os
class DetectFileTypeCommand(sublime_plugin.EventListener):
def on_load(self, view):
filename = view.file_name()
if not filename: # buffer has never been saved
return
name = os.path.basename(filename)
if name.startswith("PRE_"):
set_syntax(view, "Shell-Unix-Generic", "ShellScript")
def set_syntax(view, syntax, path=None):
if path is None:
path = syntax
view.settings().set('syntax', 'Packages/'+ path + '/' + syntax + '.tmLanguage')
print "Switched syntax to: " + syntax
You can go to Preferences->Browse Packages, and save it there ending with .py, I recommend creating a directory for it (e.g. DetectFileType/detect_file_type.py).

Best replacement for GCC #ident

I used to set this at top of my source files to be able to grep -a "ID :" on my binaries :
#ident "\\n$# ID : my_library.o v1.3 (25/08/07)#$\\n"
However, this is deprecated in GCC 4.3.3. Any suggestions ?
I came through __attributes__(section()), but not sure if this will get stripped, and anyway, I was guessing there was a more straightforward way.
Thank you
The #ident directive (as well as #sccs) was undeprecated, so you should just keep it!
(see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41632)

Resources