Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Split PHP grammar into separate HTML and PHP portions
Browse files Browse the repository at this point in the history
Fixes #182
  • Loading branch information
Wliu authored and Wliu committed Oct 19, 2017
1 parent 28fb4f8 commit 01e7722
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 123 deletions.
93 changes: 93 additions & 0 deletions grammars/html.cson
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# This grammar file is responsible for including the actual PHP grammar
# by capturing <?php ?> tags
'scopeName': 'text.html.php'
'name': 'PHP'
'fileTypes': [
'aw'
'ctp'
'inc'
'install'
'module'
'php'
'php_cs'
'php3'
'php4'
'php5'
'phpt'
'phtml'
'profile'
]
'firstLineMatch': '''(?x)
# Hashbang
^\\#!.*(?:\\s|\\/)
php\\d?
(?:$|\\s)
|
# Modeline
(?i:
# Emacs
-\\*-(?:\\s*(?=[^:;\\s]+\\s*-\\*-)|(?:.*?[;\\s]|(?<=-\\*-))mode\\s*:\\s*)
php
(?=[\\s;]|(?<![-*])-\\*-).*?-\\*-
|
# Vim
(?:(?:\\s|^)vi(?:m[<=>]?\\d+|m)?|\\sex)(?=:(?=\\s*set?\\s[^\\n:]+:)|:(?!\\s*set?\\s))(?:(?:\\s|\\s*:\\s*)\\w*(?:\\s*=(?:[^\\n\\\\\\s]|\\\\.)*)?)*[\\s:](?:filetype|ft|syntax)\\s*=
(?:php|phtml)
(?=\\s|:|$)
)
'''
'foldingStartMarker': '(/\\*|\\{\\s*$|<<<HTML)'
'foldingStopMarker': '(\\*/|^\\s*\\}|^HTML;)'
'injections':
'text.html.php - (meta.embedded | meta.tag), L:text.html.php meta.tag, L:source.js.embedded.html':
'patterns': [
{
'include': '#php-tag'
}
]
'patterns': [
{
'include': 'text.html.basic'
}
{
'include': '#php-tag'
}
]
'repository':
'php-tag':
'patterns': [
{
'begin': '<\\?(?i:php|=)?(?![^?]*\\?>)'
'beginCaptures':
'0':
'name': 'punctuation.section.embedded.begin.php'
'end': '\\?>'
'endCaptures':
'0':
'name': 'punctuation.section.embedded.end.php'
'name': 'meta.embedded.block.php'
'contentName': 'source.php'
'patterns': [
{
'include': 'source.php'
}
]
}
{
'begin': '<\\?(?i:php|=)?'
'beginCaptures':
'0':
'name': 'punctuation.section.embedded.begin.php'
'end': '\\?>'
'endCaptures':
'0':
'name': 'punctuation.section.embedded.end.php'
'name': 'meta.embedded.line.php'
'contentName': 'source.php'
'patterns': [
{
'include': 'source.php'
}
]
}
]
143 changes: 22 additions & 121 deletions grammars/php.cson
Original file line number Diff line number Diff line change
@@ -1,107 +1,8 @@
'scopeName': 'text.html.php'
'name': 'PHP'
'fileTypes': [
'aw'
'ctp'
'inc'
'install'
'module'
'php'
'php_cs'
'php3'
'php4'
'php5'
'phpt'
'phtml'
'profile'
'theme'
]
'firstLineMatch': '''(?x)
# Hashbang
^\\#!.*(?:\\s|\\/)
php\\d?
(?:$|\\s)
|
# Modeline
(?i:
# Emacs
-\\*-(?:\\s*(?=[^:;\\s]+\\s*-\\*-)|(?:.*?[;\\s]|(?<=-\\*-))mode\\s*:\\s*)
php
(?=[\\s;]|(?<![-*])-\\*-).*?-\\*-
|
# Vim
(?:(?:\\s|^)vi(?:m[<=>]?\\d+|m)?|\\sex)(?=:(?=\\s*set?\\s[^\\n:]+:)|:(?!\\s*set?\\s))(?:(?:\\s|\\s*:\\s*)\\w*(?:\\s*=(?:[^\\n\\\\\\s]|\\\\.)*)?)*[\\s:](?:filetype|ft|syntax)\\s*=
(?:php|phtml)
(?=\\s|:|$)
)
'''
'foldingStartMarker': '(/\\*|\\{\\s*$|<<<HTML)'
'foldingStopMarker': '(\\*/|^\\s*\\}|^HTML;)'
'injections':
'text.html.php - (meta.embedded | meta.tag), L:text.html.php meta.tag, L:source.js.embedded.html':
'patterns': [
{
'begin': '<\\?(?i:php|=)?(?![^?]*\\?>)'
'beginCaptures':
'0':
'name': 'punctuation.section.embedded.begin.php'
'contentName': 'source.php'
'end': '(\\?)>'
'endCaptures':
'0':
'name': 'punctuation.section.embedded.end.php'
'1':
'name': 'source.php'
'name': 'meta.embedded.block.php'
'patterns': [
{
'include': '#language'
}
]
}
{
'begin': '<\\?(?i:php|=)?'
'beginCaptures':
'0':
'name': 'punctuation.section.embedded.begin.php'
'end': '>'
'endCaptures':
'0':
'name': 'punctuation.section.embedded.end.php'
'name': 'meta.embedded.line.php'
'patterns': [
{
'captures':
'1':
'name': 'source.php'
'2':
'name': 'punctuation.section.embedded.end.php'
'3':
'name': 'source.php'
'match': '\\G(\\s*)((\\?))(?=>)'
'name': 'meta.special.empty-tag.php'
}
{
'begin': '\\G'
'contentName': 'source.php'
'end': '(\\?)(?=>)'
'endCaptures':
'0':
'name': 'punctuation.section.embedded.end.php'
'1':
'name': 'source.php'
'patterns': [
{
'include': '#language'
}
]
}
]
}
]
# Actual PHP grammar
'scopeName': 'source.php'
'patterns': [
{
'include': 'text.html.basic'
'include': '#language'
}
]
'repository':
Expand Down Expand Up @@ -606,7 +507,7 @@
'end': '(?=,|\\)|/[/*]|\\#)'
'patterns': [
{
'include': '#language'
'include': '$self'
}
]
}
Expand Down Expand Up @@ -695,7 +596,7 @@
'name': 'meta.function-call.php'
'patterns': [
{
'include': '#language'
'include': '$self'
}
]
}
Expand Down Expand Up @@ -728,7 +629,7 @@
'name': 'meta.function-call.php'
'patterns': [
{
'include': '#language'
'include': '$self'
}
]
}
Expand Down Expand Up @@ -1271,8 +1172,8 @@
}
]
'interpolation':
# http://www.php.net/manual/en/language.types.string.php#language.types.string.parsing
# http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.double
# http://www.php.net/manual/en/language.types.string.php$self.types.string.parsing
# http://www.php.net/manual/en/language.types.string.php$self.types.string.syntax.double
'patterns': [
{
'match': '\\\\[0-7]{1,3}'
Expand Down Expand Up @@ -1301,7 +1202,7 @@
'name': 'punctuation.definition.variable.php'
'patterns': [
{
'include': '#language'
'include': '$self'
}
]
}
Expand Down Expand Up @@ -1417,7 +1318,7 @@
'name': 'punctuation.definition.namespace.end.bracket.curly.php'
'patterns': [
{
'include': '#language'
'include': '$self'
}
]
}
Expand Down Expand Up @@ -1613,7 +1514,7 @@
'contentName': 'meta.class.body.php'
'patterns': [
{
'include': '#language'
'include': '$self'
}
]
}
Expand Down Expand Up @@ -1644,7 +1545,7 @@
'name': 'meta.include.php'
'patterns': [
{
'include': '#language'
'include': '$self'
}
]
}
Expand Down Expand Up @@ -1827,7 +1728,7 @@
'name': 'meta.array.php'
'patterns': [
{
'include': '#language'
'include': '$self'
}
]
}
Expand Down Expand Up @@ -1969,7 +1870,7 @@
'name': 'punctuation.definition.end.bracket.curly.php'
'patterns': [
{
'include': '#language'
'include': '$self'
}
]
}
Expand All @@ -1984,7 +1885,7 @@
'name': 'punctuation.section.array.end.php'
'patterns': [
{
'include': '#language'
'include': '$self'
}
]
}
Expand All @@ -1999,7 +1900,7 @@
'name': 'punctuation.definition.end.bracket.round.php'
'patterns': [
{
'include': '#language'
'include': '$self'
}
]
}
Expand Down Expand Up @@ -2075,7 +1976,7 @@
'name': 'punctuation.definition.variable.php'
'patterns': [
{
'include': '#language'
'include': '$self'
}
]
}
Expand All @@ -2095,7 +1996,7 @@
'name': 'meta.method-call.php'
'patterns': [
{
'include': '#language'
'include': '$self'
}
]
}
Expand Down Expand Up @@ -2420,7 +2321,7 @@
'name': 'meta.method-call.static.php'
'patterns': [
{
'include': '#language'
'include': '$self'
}
]
}
Expand Down Expand Up @@ -3541,7 +3442,7 @@
'name': 'punctuation.definition.switch-expression.end.bracket.round.php'
'patterns': [
{
'include': '#language'
'include': '$self'
}
]
}
Expand All @@ -3553,7 +3454,7 @@
'end': '(?=}|\\?>)'
'patterns': [
{
'include': '#language'
'include': '$self'
}
]
}
Expand Down Expand Up @@ -3688,7 +3589,7 @@
'name': 'punctuation.definition.variable.php'
'patterns': [
{
'include': '#language'
'include': '$self'
}
]
}
Expand Down
Loading

0 comments on commit 01e7722

Please sign in to comment.