How to implement a syntax highlighting for a proprietary language?


#1

Hi,

Could you tell how to implement a syntax highlighting for a proprietary language ?

I have a code that contains HTML .
It also contains another language.

I need more color in html, the language in question.

How to do ?


#2

Have you taken a look at the resources in the FAQ?


#3

For what you want to do, you want to make a language package that refers to language-html in its grammar file. I can’t give you more specific details unless you share more about the features of this mysterious proprietary language, but a good example is PHP.

I’ve pored over the documentation and written up a template for grammar files with comments that explain the various fields.


#4

Here are the tags I need to add syntax highlighting besides html :slight_smile:

[EMV INCLUDE][EMV /INCLUDE]
[EMV TEXTPART][EMV /TEXTPART]
[EMV DYN][EMV /DYN]
[EMV IF][EMV /IF]
[EMV THEN][EMV /THEN]


#5

Is there ever going to be HTML or other code inside any of those tags? What file extension do you use?


#6

I have lost a tag :
[EMV ELSE][EMV /ELSE]

There will only HTML with these tags.

I use no extension.
I just need to color the html code and my own and then I copy Atom and I paste into another application


#7

But will there be HTML within the tags?

Also, you have an if statement. How is the condition written?


#8

This is an example :

        <html>
          <head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            <title>My Sample HTML</title>
          </head>
          <body>
            <img src="" width="600" height="100"/>
            <table width="600" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td>
                  <font size="2" face="Arial">Dear [EMV DYN]FIRSTNAME[EMV /DYN] [EMV DYN]LASTNAME[EMV /DYN],Thank you for subscribing to MyDate.You are subscribed with the Email address: [EMV DYN]EMAIL[EMV /DYN]
                    <font size="2" face="Arial">Let us know if you have any question.My Date Customer Service.</font>
                    [EMV IF](RS_VARIABLE = NULL][EMV THEN]This is a test[EMV /THEN][EMV /IF]
              <table align="center" width="550" border="0" cellspacing="0" cellpadding="0" style="border-collapse:collapse;">
                  </td>
                </tr>
              </table>[EMV CONTENT]1[EMV /CONTENT]
              <font size="2" face="Arial">Let us know if you have any question.My Date Customer Service.</body>
            </html>
          </body>

#9

There absolutely can’t be any ambiguity about how it’s supposed to read, because we can’t make a syntax highlighter if there’s uncertainty. That means that you need to proofread thoroughly and not leave anything out.

  1. You didn’t mention anything about variables. How are they named? Are they always in all caps? Is NULL a string or a special value?

  2. Is the variable wrapped in () or []?


#10

All tags start and end start with all the beginnings and end tags begin with [ and ends with ] .

Examples:
[ EMV DYN ] [ EMV / DYN ]
[ EMV IF] [ EMV / IF]

The tags of the languages ​​are always capitalized .
The variables are present in brackets and in capital letters, but I can not you list them. They are created as you go.

The variable wrapped in () .

NULL is to say " empty "
Variables can take to value numbers , text, a string


#11

You are now including spaces around everything. You weren’t before. Is [ EMV DYN ][ EMV / DYN ] valid?

The variables are present in brackets and in capital letters, but I can not you list them. They are created as you go.

How do you create a variable?

The variable wrapped in () .

So is it [EMV IF](VARIABLE = 1)[EMV THEN][EMV /THEN][EMV /IF] or [EMV IF (VARIABLE = 1)][EMV THEN][EMV /THEN][EMV /IF]? There’s a typo in the example you posted and you are not explaining it to me.

NULL is to say " empty "

Is it case-sensitive?

Variables can take to value numbers , text, a string

Can you do math with them?


#12

1- Sorry, it’s a bad copy and past. There is no space around.
Example : [EMV DYN] [EMV /DYN]
2-
2a- First case: Variables are create on a third part application. For condition, when just after “(”, there is a variable.
Example : (RG_TREB = 1)
“RG_TREB” is a variable who must be colored
2b- Second case: To show value of variable, i use “[EMV DYN]RS_BRO[EMV /DYN]”.
On this case, “RS_BRO” is a variable who must be colored
2c- Third case : When we have “[EMV INCLUDE]10578[EMV /INCLUDE]” we must color “10578” in another color . To summarize, you have to color what is between [EMV INCLUDE][EMV /INCLUDE] of another color.

3- There is two example for the illustration :slight_smile:

[EMV IF](RG_TREB = 1)[EMV THEN]This is a test[EMV /THEN][EMV /IF]

[EMV IF](RS_BROF = “DamnedScholar”)[EMV THEN]My name is [EMV DYN]RS_BROF[EMV /DYN][EMV /THEN][EMV /IF]

4- NULL is not case-sensitive
5- It’s not possible to do math with them


#13

Okay, check this out. It should match everything you’ve told me. I included the extra file extension .emv for easy testing (so that I didn’t have to manually reset the grammar every time I changed anything), and you can see how it turned out by looking at test.emv. I have an annotated grammar template that explains each of the components, and you can check out the PHP grammar for another example of a language that sits on top of HTML.


#14

Thank you very much but I don’t understand how to set up the new language ? Can you give me the procedure for installation? This language he will also have the html together for coloring ?


#15

Pick one of two ways:

  1. If you have a specific directory for git repositories, git clone the repo, enter it, and (if you’re on Windows, use PowerShell or git-bash for this) type apm link. Reload Atom.

  2. Make a folder in .atom/packages and download the files into that folder. Reload Atom.

Yes. Take a look at the grammar file and you can see the include statement that invokes HTML.


#16

It’s almost perfect. But two tags do not work for syntax highlighting .
If I typed:
[ EMV THEN ] [ EMV / THEN ]
or
[ EMV ELSE ] [ EMV / ELSE ]
coloring does not work.
Furthermore, if I remove a “]” at the end , and I try to enter again with the "Alt Gr " + “]” , the hook will not turn


#17

That’s on purpose. “Then” and “else” instructions only show up inside of “if” instructions. Why would you type either of those by themselves?

Furthermore, if I remove a “]” at the end , and I try to enter again with the "Alt Gr " + “]” , the hook will not turn

If you need help regarding key presses, you need to share what keyboard you use. That’s not a fault of the grammar.


#18

You’re right. I have find an issue here : https://github.com/atom/atom-keymap/issues/35

I will read it .

Thank you very much!


#19

Okay, so I wrote up a snippets file to work around your keyboard issue. Just put that in language-emv/snippets and it will load alongside the grammar file. Then you can type emv and the autocomplete window will show you your options. Type emvdyn and press Tab and you’ll see it expand automatically. emvif automatically includes the variable and the “then” tags, and you can insert the “else” tags if you need them.


#20

Just updated the snippets file because I forgot to add in tab stops.