Sublime Forum

New Syntax does not shown on the Syntax Extension Droplist

#1

Hi All,

I have created a syntax for the Pine script (Used in TradingView). Whenever there is a file named with extension “.pine”, the syntax on the file works great. However if I try to find the syntax “Pine” from the Syntax Extension Droplist (i.e. Bottom Right corner of Sublime editor), the syntax “Pine” does not exist.

Why?

Please find my pine.syblime-syntax file as follow, which is stored in the User folder (same as other new developer syntax are saved).

%YAML 1.2
---
name: Pine
file_extensions:
  - pine
scope: source.pine

variables:
    identifier_regex: '[a-zA-Z_][a-zA-Z0-9_]*'

contexts:
  main:
    - match: //.*
      scope: comment.pine

  #constants

    - match: \b(true|false)\b
      scope: constant.language.pine

    - match: \b(bool|float|integer|string)\b
      scope: constant.language.pine

    - match: \b(time|timenow|year|month|weekofyear|dayofmonth|dayofweek|hour|minute|second|interval|isdaily|isdwm|isintraday|ismonthly|isweekly)\b
      scope: constant.language.pine

    - match: \b(open|high|low|close|volume|na|period|tikerid|source|symbol)\b
      scope: constant.language.pine

    - match: \b(accdist|area|areabr|hl(2|c3)|ohlc4)\b
      scope: constant.language.pine

    - match: \badjustment\.(dividends|none|splits)\b
      scope: constant.language.pine

    - match: \b(monday|tuesday|wednesday|thursday|friday|saturday|sunday|dayofweek)\b
      scope: constant.language.pine

    - match: \b(line|stepline|histogram|cross[^\(]|area|columns|circles)\b
      scope: constant.language.pine

    - match: \b(solid|dotted|dashed)\b
      scope: constant.language.pine

    - match: \b(session|session.(extended|regular))\b
      scope: constant.language.pine

    - match: \bscale.(left|none|right)\b
      scope: constant.language.pine

    - match: \bbarmerge\.(gaps_(off|on)|lookahead_(off|on))\b
      scope: constant.language.pine

    - match: \bbarstate\.is(confirmed|first|history|last|new|realtime)\b
      scope: constant.language.pine

    - match: \bcurrency\.(AUD|CAD|CHF|EUR|GBP|HKD|JPY|NOK|NONE|NZD|RUB|SEK|SGD|TRY|USD|ZAR)\b
      scope: constant.language.pine

    - match: \blocation\.(abovebar|belowbar|top|bottom|absolute)\b
      scope: constant.language.pine

    - match: \bshape\.(x(cross)?|(triangle|arrow|label)(up|down)|flag|circle|square|diamond)\b
      scope: constant.language.pine

    - match: \bsize\.(auto|huge|large|normal|small|tiny)\b
      scope: constant.language.pine

    - match: \bstrategy\.(cash|closedtrades|commission\.(cash_per_contract|cash_per_order|percent)|direction\.(all|long|short)|equity|eventrades|fixed|grossloss|grossprofit|initial_capital|long|losstrades|max_contracts_held_all|max_contracts_held_long|max_contracts_held_short|max_drawdown|netprofit|oca\.(cancel|none|reduce)|openprofit|opentrades|percent_of_equity|position_avg_price|position_entry_name|position_size|short|wintrades)\b
      scope: constant.language.pine

    - match: \bsyminfo\.(mintick|pointvalue|prefix|root|session|timezone)\b
      scope: constant.language.pine

    - match: \b(aqua|black|silver|gray|white|maroon|red|purple|fuchsia|green|lime|olive|yellow|navy|blue|teal|orange)\b
      scope: constant.language.pine

    - match: '#[a-fA-F0-9]{6}'
      scope: support.constant.pine

    - match: '\b([0-9]+)\b'
      scope: constant.numeric.pine

  # strings

    - match: ''''
      push: single-quoted-string
    - match: '"'
      push: double-quoted-string

  # operators

    - match: (\-|\+|\*|/|%)
      scope: keyword.operator.arithmetic.pine
    - match: (==|!=|<=|>=|<|>|\:=)
      scope: keyword.operator.comparison.pine
    - match: (\?|\:)
      scope: keyword.operator.ternary.pine
    - match: \b(and|or|not)\b
      scope: keyword.operator.logical.pine
    - match: "="
      scope: keyword.operator.assignment.pine

  # functions

    - match: '\b(alertcondition|a(bs|cos|lma|sin|tan|tr|vg)|bar(color|since)|bgcolor|cci|ceil|change|cog|color|correlation|cos|cross(over|under)?|cum|dayof(month|week)|dev|(e|s)ma|exp|falling|fill|fixnan|floor|heikinashi|highest(bars)?|hline|iff|input|kagi|linebreak|linreg|log(10)?|lowest(bars)?|macd|m(ax|in)|minute|mom|month|n(a|z)|offset|percentile_linear_(interpolation|nearest_rank)|percentrank|pivot(high|low)|plot(arrow|bar|candle|char|shape|figure)?|pow|renko|rising|r(ma|oc|si)|round|sar|second|security|sign|sin|sqrt|stdev|stoch|strategy|strategy\.(cancel|cancel_all|close|close_all|entry|exit|order)|study|sum|swma|tan|tickerid|time(stamp)?|tostring|tr|tsi|valuewhen|variance|v(wap|wma)|weekofyear|wma|year|{{identifier_regex}})(?=\()'
      captures:
        1: support.function.pine

    - match: '{{identifier_regex}}\s*(?=:?\=)'
      scope: variable.parameter.pine

    - match: ('({{identifier_regex}})\(.*\)\s(=>)\s'|if|else)
      captures:
        1: entity.name.function
        2: keyword.operator.assignment.pine

  single-quoted-string:
    - meta_scope: string.quoted.single.pine
    - match: \\.
      scope: constant.character.escape.pine
    - match: ''''
      pop: true

  double-quoted-string:
    - meta_scope: string.quoted.double.pine
    - match: \\.
      scope: constant.character.escape.pine
    - match: '"'
      pop: true

0 Likes

#2

Can you please format your syntax properly by surrounding the content using triple (```) backslashes ?

Example

%YAML 1.2
---
file_extensions:
  - chinese
scope: source.chinese

contexts:
  main:
    - match: '\{(.*?)\}'
      scope: region.redish
0 Likes

#3

Absolutely! Apology! Just reformatted!

Thank you so much!

0 Likes

#4

I don’t see anything wrong with it. The syntax works on .pine files and I can find it in View -> Syntax as well. Did not make any changes to the syntax as well. Used it as provided.

0 Likes

#5

(1) The syntax works on .pine files ==> Yes, I got this works too.

(2) I can find it in View -> Syntax as well. ==> No, mine sublime didn’t show “Pine” in View>Syntax.

So strange, why is that? I restarted my macbook and still cannot see it.

Machine: Macbook Pro 15" 2015 (Intel)
OS: MacOS 10.15.7
Version: Build 4126

0 Likes

#6

If you store your syntax in your User folder and there’s more than one syntax in that folder, they’ll all show up in the Syntax list under the User package. So, if you previously had only 1, now that you added a second one that would cause both it and the previous one to “jump” locations in the menu.

Not sure if that’s what happening to you here, but something to check into.

0 Likes

#7

After re-install Sublime and do it all over again, it works now!

Thank you!

0 Likes