-
Notifications
You must be signed in to change notification settings - Fork 620
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
YAML: extract keys (with scope) for I18n Ruby Gem #3523
Comments
u-ctags has a Yaml parser based on libyaml. See https://github.com/universal-ctags/ctags/blob/master/parsers/yaml.c. I wonder if your ctags executable is linked to libyaml.
Even if your ctags executable is linked to libyaml, the yaml parser doesn't extract keys. You can implement what you want in two ways. B. extending the yaml parser to extract keys in a yaml file
I can give you more hints. |
Thanks for hints. I need to get into topic :) |
I think A approach is ok. This is specific functionality to grab full/partial paths, fitting into subparser. |
Ok. Could you tell me more about "I18n ruby gem"? |
I18n gem uses yaml files as source of translations. ---
en:
sequel:
errors:
or: "or" Then when general english is used in session, this ruby call will get text from it: I18n.t('sequel.errors.or') # will get "or" I'am thinking about approach to this, index from beggining or from certain level or both:
Key level indexing like in json is very simple, could be done the regexp way --regex-yaml=REGEX with |
Thank you for your explanation. I found more questions. A. I think https://github.com/svenfuchs/rails-i18n/blob/master/rails/locale/en.yml is a real example input file. Am I correct? If I'm correct, what string do you want to extract from
In this example, an array element is at the leaf. If an array is in the middle of the path like:
what kind of string do you expect ctags extracts? C. Other than having .yml as an extension, I think there is no rule for the file name. |
A. Yes, real life example.
B. When they are used in code with full form they appear as We could also encounter this syntax, so called "Flow" scalars
Scalar indicators: So in fact general capture line looks like this: This reference card will be useful later: https://yaml.org/refcard.html C. I agree. User could filter files by using Two questions: Thanks for helping me out. |
I have one idea, to take into account lines with colon. To get only matching this |
About A, my understanding is that we can ignore the array (or sequence in Yaml) regardless of the position in a YAML tree structure. About B I would like to confirm that you want to extract en:
key: >
Your long
string here.
command: |
echo "--- Install gems"
bundle install Am I correct?
Yes for both questions. |
https://github.com/ruby-i18n/i18n looks like the reference. |
A. yes |
Thank you. |
That's good name. |
Thank you. We have one critical limitation. In the command line, you must do like "ctags --languages=+I18NRubyGem ...". |
ok, no problem |
I found this need overhauling of yaml.c. |
It conflicts with idea of sub-parser? When I would choose this way? Instead of changing yaml.c ? |
Close universal-ctags#3523 Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Close universal-ctags#3523 Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Close universal-ctags#3523 Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Close universal-ctags#3523 Signed-off-by: Masatake YAMATO <yamato@redhat.com>
The overhaul was done. |
Very well done. I had to compile it on my own machine and it worked almost in all cases.
But I saw it in unit tests, propably I am missing some setting. |
Did you expect ctags emits tags for
No, you were not. The parser doesn't emit the last components are tags. After getting your reply, I will update the pull request. Thank you for your feedback. |
Hi, yes All "tails" would be welcome. |
Close universal-ctags#3523 Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Close universal-ctags#3523 Designed with @akemrir. Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Just checked newest changes. Very nice and explanatory documentation.
This worked for me without force. It may be useful for others? What do you think? |
That is understandable, but this puts other YAML-based parsers into chaos. This is the reason I confirmed #3523 (comment) . I'm wrong in English. So, if you know good sentences that balance between the limitations, avoiding chaos and usability, could you write them down here? I will merge them into my pull request. |
No, it's good. But it needs more detail. Not everyone will catchup like we do.
First one would do generic preparation, second will append to tags file. I am missing something from manual? About general usage? Secondly, if langmap for one yaml based parser is bad, should I do it this way?
|
Writing about -a option in the man page looks helpful.
These don't work at all. If they work, ctags may have a bug. |
Is there possibility to enable all parsers without specifying single? |
There is no possibility. YAML files using .yaml or .yml as file extensions are not self-descriptive. There is no heuristic for recognizing whether a .yaml file is for I18nRubyGem or not. |
Unlike XML, YAML is not self-descriptive. Only with the user's intervention, ctags can only do something useful for such input. |
ok, thanks for your time and explanation |
I found an excellent heuristic; a YAML file may be an I18nRubyGem file if the top-level entries are locale names. |
That sounds good. You mean ISO 3166-1 alpha-2? Can you validate locale names in base code this way? So more like \w{2,}(-\w{2,})?: |
I have found also this form ff-Latn-SN, but haven't seen it in real applications. |
Close universal-ctags#3523 Designed with @akemrir. Signed-off-by: Masatake YAMATO <yamato@redhat.com>
I implemented the heuristic. You don't have to specify --language-force=I18nRubyGem --languages=+I18nRubyGem to use the parser. I got a local list from
|
Close universal-ctags#3523 Designed with @akemrir. Signed-off-by: Masatake YAMATO <yamato@redhat.com>
hmm, ok maybe?
Or both. What do you think? |
Thank you. I will use * { ls /usr/share/locale/ | xargs -n 1 printf '"%s",\n';
* ls /usr/share/locale/ | sed 's/_/-/g' | xargs -n 1 printf '"%s",\n' } \
* | sort | uniq; echo 'NULL' |
Close universal-ctags#3523 Designed with @akemrir. Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Looks nice. |
Close universal-ctags#3523 Designed with Karol Jakusz-Gostomski <Karol Jakusz-Gostomski> Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Close universal-ctags#3523 Designed with Karol Jakusz-Gostomski <Karol Jakusz-Gostomski> Signed-off-by: Masatake YAMATO <yamato@redhat.com>
The name of the parser: Yaml
The command line you used to run ctags:
The content of input file:
The tags output you are not satisfied with:
The tags output you expect:
The version of ctags:
How do you get ctags binary:
Archlinux official repository
extra/ctags 1:5.9.20220828.0-1
I would have a map of keys paths from yaml file. This is for use with I18n ruby gem, for translations.
Then I could for example use it with vim to jump directly to translation and suggest path from vim addon.
Any hints to start off somewhere?
Maybe it would be similar to SASS?
The text was updated successfully, but these errors were encountered: