Sublime Forum

Html script regex? js syntax don't load! help needed

#1

Hi,
i’m developing a syntax highlighting for jstl and i’m rewriting html syntax for implementig it with nested tags and more visual effects.

I’m blocked with this part of regex that broke the syntax:

  - include: '#tag-stuff'
  - contentName: source.js.embedded.html
    begin: (?<!</(?:[sS][cC][rR][iI][pP][tT]))(>)
    end: (</)((?i:script))

this part of code brokes the regex when i have this particular case:

<script type="text/javascript">
    <c:set var="" value=""></c:set>
</script>

the particular case that brokes is this </ char combination

how i can rewrite the regex to bypass this problem?

there the complete code:
jstl YAML file

interested line are from 92 to 118, if i remove them it works correctly but i lose javascript support…


EDIT 1:

ended code from suggestions:

- name: meta.tag.script.html
  begin: (?<=(<)([sS][cC][rR][iI][pP][tT]))([^\/].+?)(>)
  end: (<\/)([sS][cC][rR][iI][pP][tT])()(>)
  captures:
  '1': {name: punctuation.definition.tag.begin.html}
  '2': {name: punctuation.definition.tag.html}
  '4': {name: punctuation.definition.tag.end.html}
  patterns:
  - include: '#tag-stuff'
  - contentName: source.js.embedded.html
    match: (?<=(>))([\S\s]*)(?=(<\/))
    patterns:
  - include: source.js

now the last thing with this code is to understand because it don’t load the javascript source.js syntax…

0 Likes

#2

Looks like you have an unescaped delimiter.

/ is used to group the RegEx pattern & add flags.

Change it to \/ to send a literal forward-slash.

0 Likes

#3

I ended up playing around with some patterns. Here a few that might be relevant for you:

##Tag Start

##Tag End

##Multi-Line Content

##Inline Content

0 Likes

#4

Thanks a lot i’ve ended with this code:

`- name: meta.tag.script.html
begin: (?<=(<)([sS][cC][rR][iI][pP][tT]))([^/].+?)(>)
end: (</)([sS][cC][rR][iI][pP][tT])()(>)
captures:
‘1’: {name: punctuation.definition.tag.begin.html}
‘2’: {name: punctuation.definition.tag.html}
‘4’: {name: punctuation.definition.tag.end.html}
patterns:

  • include: ‘#tag-stuff
  • contentName: source.js.embedded.html
    match: (?<=(>))([\S\s]*)(?=(</))
    patterns:
    • include: source.js`

now the last thing with this code is to understand because it don’t load the javascript source.js syntax…

0 Likes

#5

Not too sure about that, I haven’t worked with syntaxes yet.


Any reason you use ([sS][cC][rR][iI][pP][tT]) ?

You can also use the (?i): modifier to disable case sensitivity for your pattern.

For example:

(?<=(<)([sS][cC][rR][iI][pP][tT]))([^\/].+?)(>)
could be condensed to:
(?<=(<)(?i)(script))([^\/].+?)(>)

###Demo

0 Likes

#6

FYI, .tmLanguage files don’t use delimiters for regular expressions.

0 Likes

#7

@wbond

Ohh, I was unaware of this ( haven’t worked with them yet ).

Does that render any of the above examples incorrect?


I’m assuming this is only in reference to the / character? In which case, an escape shouldn’t affect anything. ( I think? )


I usually just escape all symbols in my RegEx to make transription between languages as seamless as possible.

I use these single & double escaped sets to match symbols ( depending on implementation ). I avoid .* if possible, since I also use some miscellaneous ASCII characters to enhance section & comment visibility.

\\\{\}\[\]\(\)\*\|\^\-\$\.\+\?\/\\'\\"\:\!\&\`\,\@\=\#\%\;\~\_\<\>

\\\\\\{\\}\\[\\]\\(\\)\\*\\|\\^\\-\\$\\.\\+\\?\\/\\\'\\\"\\:\\!\\&\\`\\,\\@\\=\\#\\%\\;\\~\\_\\<\\>
0 Likes

#8

Ok i think i have resolved it!
At the end i add two of my include syntax definition right before including the js external syntax, this in the original not modified syntax.

patterns:

- include: ‘#jstl
- include: ‘#jstl-variable

  • include: source.js

Thanks to all!

0 Likes