Remove PHP (moved to monaco-languages)

This commit is contained in:
Alex Dima 2016-09-16 19:15:23 +02:00
parent 7923ecea82
commit a5298a8158
6 changed files with 9 additions and 2532 deletions

View file

@ -41,19 +41,10 @@ export interface ITokenizationCustomization {
getNestedMode?: (state:modes.IState, locator:IModeLocator) => modes.IMode;
getNestedModeInitialState?: (myState:modes.IState) => modes.IState;
/**
* Return null if the line does not leave the nested mode
*/
getLeavingNestedModeData?: (line:string, state:modes.IState) => ILeavingNestedModeData;
/**
* Callback for when leaving a nested mode and returning to the outer mode.
* @param myStateAfterNestedMode The outer mode's state that will begin to tokenize
* @param lastNestedModeState The nested mode's last state
*/
onReturningFromNestedMode?: (myStateAfterNestedMode:modes.IState, lastNestedModeState:modes.IState)=> void;
}
function isFunction(something) {
@ -68,9 +59,7 @@ export class TokenizationSupport implements modes.ITokenizationSupport, IDisposa
private defaults: {
enterNestedMode: boolean;
getNestedMode: boolean;
getNestedModeInitialState: boolean;
getLeavingNestedModeData: boolean;
onReturningFromNestedMode: boolean;
};
private supportsNestedModes:boolean;
@ -88,9 +77,7 @@ export class TokenizationSupport implements modes.ITokenizationSupport, IDisposa
this.defaults = {
enterNestedMode: !isFunction(customization.enterNestedMode),
getNestedMode: !isFunction(customization.getNestedMode),
getNestedModeInitialState: !isFunction(customization.getNestedModeInitialState),
getLeavingNestedModeData: !isFunction(customization.getLeavingNestedModeData),
onReturningFromNestedMode: !isFunction(customization.onReturningFromNestedMode)
};
this._embeddedModes = Object.create(null);
@ -183,7 +170,6 @@ export class TokenizationSupport implements modes.ITokenizationSupport, IDisposa
let bufferAfterNestedMode = leavingNestedModeData.bufferAfterNestedMode;
let myStateAfterNestedMode = leavingNestedModeData.stateAfterNestedMode;
myStateAfterNestedMode.setStateData(myStateBeforeNestedMode.getStateData());
this._onReturningFromNestedMode(myStateAfterNestedMode, nestedModeState);
return this._myTokenize(bufferAfterNestedMode, myStateAfterNestedMode, deltaOffset + nestedModeBuffer.length, stopAtOffset, prependTokens, prependModeTransitions);
}
@ -306,20 +292,17 @@ export class TokenizationSupport implements modes.ITokenizationSupport, IDisposa
}
private _getNestedModeInitialState(state:modes.IState): modes.IState {
if (this.defaults.getNestedModeInitialState) {
let nestedMode = this._getNestedMode(state);
if (nestedMode) {
let tokenizationSupport = modes.TokenizationRegistry.get(nestedMode.getId());
if (tokenizationSupport) {
let nestedModeState = tokenizationSupport.getInitialState();
nestedModeState.setStateData(state);
return nestedModeState;
}
let nestedMode = this._getNestedMode(state);
if (nestedMode) {
let tokenizationSupport = modes.TokenizationRegistry.get(nestedMode.getId());
if (tokenizationSupport) {
let nestedModeState = tokenizationSupport.getInitialState();
nestedModeState.setStateData(state);
return nestedModeState;
}
return new NullState(nestedMode ? nestedMode.getId() : NULL_MODE_ID, state);
}
return this.customization.getNestedModeInitialState(state);
return new NullState(nestedMode ? nestedMode.getId() : NULL_MODE_ID, state);
}
private _getLeavingNestedModeData(line:string, state:modes.IState): ILeavingNestedModeData {
@ -328,11 +311,4 @@ export class TokenizationSupport implements modes.ITokenizationSupport, IDisposa
}
return this.customization.getLeavingNestedModeData(line, state);
}
private _onReturningFromNestedMode(myStateAfterNestedMode:modes.IState, lastNestedModeState:modes.IState): void {
if (this.defaults.onReturningFromNestedMode) {
return null;
}
return this.customization.onReturningFromNestedMode(myStateAfterNestedMode, lastNestedModeState);
}
}

View file

@ -9,7 +9,6 @@ import 'vs/editor/browser/editor.all';
import 'vs/editor/contrib/quickOpen/browser/quickOutline';
import 'vs/editor/contrib/quickOpen/browser/gotoLine';
import 'vs/editor/contrib/quickOpen/browser/quickCommand';
import 'vs/languages/php/common/php.contribution';
import 'vs/languages/html/common/html.contribution';
import 'vs/languages/handlebars/common/handlebars.contribution';
import 'vs/languages/razor/common/razor.contribution';

View file

@ -49,9 +49,6 @@ exports.collectModules = function(args) {
.combine(worker)
.define('vs/languages/html/common/htmlWorker', ['vs/languages/lib/common/beautify-html']);
// ---- php -----------------------------------
common.define('vs/languages/php/common/php');
// ---- razor -----------------------------------
common.define('vs/languages/razor/common/razor', ['vs/languages/html/common/html'])
.combine(worker)

View file

@ -1,17 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import {ModesRegistry} from 'vs/editor/common/modes/modesRegistry';
ModesRegistry.registerCompatMode({
id: 'php',
extensions: ['.php', '.php4', '.php5', '.phtml', '.ctp'],
aliases: ['PHP', 'php'],
mimetypes: ['application/x-php'],
moduleId: 'vs/languages/php/common/php',
ctorName: 'PHPMode',
deps: ['text/html']
});

View file

@ -1,540 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import objects = require('vs/base/common/objects');
import Modes = require('vs/editor/common/modes');
import {CompatMode, isDigit, createWordRegExp} from 'vs/editor/common/modes/abstractMode';
import {AbstractState} from 'vs/editor/common/modes/abstractState';
import {IModeService} from 'vs/editor/common/services/modeService';
import {LanguageConfigurationRegistry, LanguageConfiguration} from 'vs/editor/common/modes/languageConfigurationRegistry';
import {TokenizationSupport, ILeavingNestedModeData, ITokenizationCustomization} from 'vs/editor/common/modes/supports/tokenizationSupport';
import {TextualSuggestSupport} from 'vs/editor/common/modes/supports/suggestSupport';
import {IEditorWorkerService} from 'vs/editor/common/services/editorWorkerService';
import {IConfigurationService} from 'vs/platform/configuration/common/configuration';
import {ICompatWorkerService} from 'vs/editor/common/services/compatWorkerService';
var brackets = (function() {
let bracketsSource = [
{ tokenType:'delimiter.bracket.php', open: '{', close: '}' },
{ tokenType:'delimiter.array.php', open: '[', close: ']' },
{ tokenType:'delimiter.parenthesis.php', open: '(', close: ')' }
];
let MAP: {
[text:string]:{
tokenType: string;
}
} = Object.create(null);
for (let i = 0; i < bracketsSource.length; i++) {
let bracket = bracketsSource[i];
MAP[bracket.open] = {
tokenType: bracket.tokenType
};
MAP[bracket.close] = {
tokenType: bracket.tokenType
};
}
return {
stringIsBracket: (text:string): boolean => {
return !!MAP[text];
},
tokenTypeFromString: (text:string): string => {
return MAP[text].tokenType;
}
};
})();
var delimiters = '+-*%&|^~!=<>(){}[]/?;:.,@';
var separators = '+-*/%&|^~!=<>(){}[]"\'\\/?;:.,#';
var whitespace = '\t ';
var isKeyword = objects.createKeywordMatcher([
'abstract', 'and', 'array', 'as', 'break',
'callable', 'case', 'catch', 'cfunction', 'class', 'clone',
'const', 'continue', 'declare', 'default', 'do',
'else', 'elseif', 'enddeclare', 'endfor', 'endforeach',
'endif', 'endswitch', 'endwhile', 'extends', 'false', 'final',
'for', 'foreach', 'function', 'global', 'goto',
'if', 'implements', 'interface', 'instanceof', 'insteadof',
'namespace', 'new', 'null', 'object', 'old_function', 'or', 'private',
'protected', 'public', 'resource', 'static', 'switch', 'throw', 'trait',
'try', 'true', 'use', 'var', 'while', 'xor',
'die', 'echo', 'empty', 'exit', 'eval',
'include', 'include_once', 'isset', 'list', 'require',
'require_once', 'return', 'print', 'unset', 'yield',
'__construct'
]);
var isCompileTimeConstant = objects.createKeywordMatcher([
'__CLASS__',
'__DIR__',
'__FILE__',
'__LINE__',
'__NAMESPACE__',
'__METHOD__',
'__FUNCTION__',
'__TRAIT__'
]);
var isPreDefinedVariable = objects.createKeywordMatcher([
'$GLOBALS',
'$_SERVER',
'$_GET',
'$_POST',
'$_FILES',
'$_REQUEST',
'$_SESSION',
'$_ENV',
'$_COOKIE',
'$php_errormsg',
'$HTTP_RAW_POST_DATA',
'$http_response_header',
'$argc',
'$argv'
]);
var isDelimiter = (character:string) => {
return delimiters.indexOf(character) > -1;
};
var isVariable = (character:string) => {
return (character[0] === '$');
};
export abstract class PHPState extends AbstractState {
private name:string;
private whitespaceTokenType:string;
public parent:Modes.IState;
constructor(modeId:string, name:string, parent:Modes.IState, whitespaceTokenType:string='') {
super(modeId);
this.name = name;
this.parent = parent;
this.whitespaceTokenType = whitespaceTokenType;
}
public equals(other:Modes.IState):boolean {
if (other instanceof PHPState) {
return (
super.equals(other) &&
this.name === other.name &&
this.whitespaceTokenType === other.whitespaceTokenType &&
AbstractState.safeEquals(this.parent, other.parent)
);
}
return false;
}
public tokenize(stream:Modes.IStream):Modes.ITokenizationResult {
stream.setTokenRules(separators, whitespace);
if (stream.skipWhitespace().length > 0) {
return { type: this.whitespaceTokenType };
}
return this.stateTokenize(stream);
}
public stateTokenize(stream:Modes.IStream):Modes.ITokenizationResult {
throw new Error('To be implemented');
}
}
export class PHPString extends PHPState {
private delimiter:string;
private isAtBeginning:boolean;
constructor(modeId:string, parent:Modes.IState, delimiter:string, isAtBeginning:boolean=true) {
super(modeId, 'string', parent, 'string.php');
this.delimiter = delimiter;
this.isAtBeginning = isAtBeginning;
}
public makeClone():AbstractState {
return new PHPString(this.getModeId(), AbstractState.safeClone(this.parent), this.delimiter, this.isAtBeginning);
}
public equals(other:Modes.IState):boolean {
if (other instanceof PHPString) {
return (
super.equals(other) &&
this.delimiter === other.delimiter &&
this.isAtBeginning === other.isAtBeginning
);
}
return false;
}
public tokenize(stream:Modes.IStream):Modes.ITokenizationResult {
var readChars = this.isAtBeginning ? 1 : 0;
this.isAtBeginning = false;
while (!stream.eos()) {
var c = stream.next();
if (c === '\\') {
if (readChars === 0) {
if (stream.eos()) {
return { type: 'string.php', nextState: this.parent };
} else {
stream.next();
}
} else {
stream.goBack(1);
return { type: 'string.php' };
}
} else if (c === this.delimiter) {
return { type: 'string.php' , nextState: this.parent };
}
readChars += 1;
}
return { type: 'string.php' };
}
}
export class PHPNumber extends PHPState {
private firstDigit:string;
constructor(modeId:string, parent:Modes.IState, firstDigit:string) {
super(modeId, 'number', parent);
this.firstDigit = firstDigit;
}
public makeClone():AbstractState {
return new PHPNumber(this.getModeId(), AbstractState.safeClone(this.parent), this.firstDigit);
}
public equals(other:Modes.IState):boolean {
if (other instanceof PHPNumber) {
return (
super.equals(other) &&
this.firstDigit === other.firstDigit
);
}
return false;
}
public tokenize(stream:Modes.IStream):Modes.ITokenizationResult {
var character = this.firstDigit;
var base = 10, isDecimal = false, isExponent = false;
if (character === '0' && !stream.eos()) {
character = stream.peek();
if (character.toLowerCase() === 'x') { base = 16; }
else if (character.toLowerCase() === 'b') { base = 2; }
else if (character === '.') { base = 10; }
else if (isDigit(character, 8)) { base = 8; }
else {
return { type: 'number.php', nextState: this.parent };
}
stream.next();
}
while (!stream.eos()) {
character = stream.peek();
if (isDigit(character,base)) {
stream.next();
} else if (base === 10) {
if (character === '.' && !isExponent && !isDecimal) {
isDecimal = true;
stream.next();
} else if (character === 'e' && !isExponent) {
isExponent = true;
stream.next();
if (!stream.eos() && stream.peek() === '-') {
stream.next();
}
} else {
break;
}
} else if (base === 8 && isDigit(character,10)) {
base = 10;
stream.next();
} else {
break;
}
}
var tokenType = 'number';
if (base === 16) {
tokenType += '.hex';
} else if (base === 8) {
tokenType += '.octal';
} else if (base === 2) {
tokenType += '.binary';
}
return { type: tokenType + '.php', nextState: this.parent };
}
}
export class PHPLineComment extends PHPState {
constructor(modeId:string, parent:Modes.IState) {
super(modeId, 'comment', parent, 'comment.php');
}
public makeClone():AbstractState {
return new PHPDocComment(this.getModeId(), AbstractState.safeClone(this.parent));
}
public equals(other:Modes.IState):boolean {
if (other instanceof PHPLineComment) {
return (
super.equals(other)
);
}
return false;
}
public tokenize(stream:Modes.IStream):Modes.ITokenizationResult {
while (!stream.eos()) {
var token = stream.next();
if (token === '?' && !stream.eos() && stream.peek() === '>') {
stream.goBack(1);
return { type: 'comment.php', nextState: this.parent};
}
}
return { type: 'comment.php', nextState: this.parent };
}
}
export class PHPDocComment extends PHPState {
constructor(modeId:string, parent:Modes.IState) {
super(modeId, 'comment', parent, 'comment.php');
}
public makeClone():AbstractState {
return new PHPDocComment(this.getModeId(), AbstractState.safeClone(this.parent));
}
public equals(other:Modes.IState):boolean {
if (other instanceof PHPDocComment) {
return (
super.equals(other)
);
}
return false;
}
public tokenize(stream:Modes.IStream):Modes.ITokenizationResult {
while (!stream.eos()) {
var token = stream.next();
if (token === '*' && !stream.eos() && !stream.peekWhitespace() && stream.peek() === '/') {
stream.next();
return { type: 'comment.php', nextState: this.parent};
}
}
return { type: 'comment.php' };
}
}
export class PHPStatement extends PHPState {
constructor(modeId:string, parent:Modes.IState) {
super(modeId, 'expression', parent);
}
public makeClone():AbstractState {
return new PHPStatement(this.getModeId(), AbstractState.safeClone(this.parent));
}
public equals(other:Modes.IState):boolean {
if (other instanceof PHPStatement) {
return (
super.equals(other)
);
}
return false;
}
public stateTokenize(stream:Modes.IStream):Modes.ITokenizationResult {
if (isDigit(stream.peek(), 10)) {
return { nextState: new PHPNumber(this.getModeId(), this, stream.next()) };
}
if (stream.advanceIfString('?>').length) {
return { type: 'metatag.php', nextState: this.parent };
}
var token = stream.nextToken();
if (isKeyword(token.toString().toLowerCase())) {
return { type: 'keyword.php' };
} else if (isCompileTimeConstant(token)) {
return { type: 'constant.php' };
} else if (isPreDefinedVariable(token)) {
return { type: 'variable.predefined.php' };
} else if (isVariable(token)) {
return { type: 'variable.php' };
} else if (token === '/') {
if (!stream.eos() && !stream.peekWhitespace()) {
switch(stream.peekToken()) {
case '/':
return { nextState: new PHPLineComment(this.getModeId(), this) };
case '*':
stream.nextToken();
return { nextState: new PHPDocComment(this.getModeId(), this) };
}
}
} else if (token === '#') {
return { nextState: new PHPLineComment(this.getModeId(), this) };
} else if (token === '"' || token === '\'') {
return { nextState: new PHPString(this.getModeId(), this, token) };
} else if (brackets.stringIsBracket(token)) {
return {
type: brackets.tokenTypeFromString(token)
};
} else if (isDelimiter(token)) {
return { type: 'delimiter.php' };
}
return { type: '' };
}
}
export class PHPPlain extends PHPState {
constructor(modeId:string, parent:Modes.IState) {
super(modeId, 'plain', parent);
}
public makeClone():AbstractState {
return new PHPPlain(this.getModeId(), AbstractState.safeClone(this.parent));
}
public equals(other:Modes.IState):boolean {
if (other instanceof PHPPlain) {
return (
super.equals(other)
);
}
return false;
}
public stateTokenize(stream:Modes.IStream):Modes.ITokenizationResult {
if (stream.advanceIfStringCaseInsensitive('<?php').length ||
stream.advanceIfString('<?=').length || stream.advanceIfString('<%=').length ||
stream.advanceIfString('<?').length || stream.advanceIfString('<%').length) {
return {
type: 'metatag.php',
nextState: new PHPStatement(this.getModeId(), new PHPEnterHTMLState(this.getModeId(), this.parent))
};
}
stream.next();
return { type: '' };
}
}
export class PHPEnterHTMLState extends PHPState {
constructor(modeId:string, parent:Modes.IState) {
super(modeId, 'enterHTML', parent);
}
public makeClone():AbstractState {
return new PHPEnterHTMLState(this.getModeId(), AbstractState.safeClone(this.parent));
}
public equals(other:Modes.IState):boolean {
if (other instanceof PHPEnterHTMLState) {
return (
super.equals(other)
);
}
return false;
}
}
export class PHPMode extends CompatMode implements ITokenizationCustomization {
public static LANG_CONFIG:LanguageConfiguration = {
wordPattern: createWordRegExp('$_'),
comments: {
lineComment: '//',
blockComment: ['/*', '*/']
},
brackets: [
['{', '}'],
['[', ']'],
['(', ')']
],
autoClosingPairs: [
{ open: '{', close: '}', notIn: ['string.php'] },
{ open: '[', close: ']', notIn: ['string.php'] },
{ open: '(', close: ')', notIn: ['string.php'] },
{ open: '"', close: '"', notIn: ['string.php'] },
{ open: '\'', close: '\'', notIn: ['string.php'] }
]
};
private _modeService:IModeService;
constructor(
descriptor:Modes.IModeDescriptor,
@IModeService modeService: IModeService,
@IConfigurationService configurationService: IConfigurationService,
@IEditorWorkerService editorWorkerService: IEditorWorkerService,
@ICompatWorkerService compatWorkerService: ICompatWorkerService
) {
super(descriptor.id, compatWorkerService);
this._modeService = modeService;
LanguageConfigurationRegistry.register(this.getId(), PHPMode.LANG_CONFIG);
Modes.TokenizationRegistry.register(this.getId(), new TokenizationSupport(this._modeService, this.getId(), this, true));
if (editorWorkerService) {
Modes.SuggestRegistry.register(this.getId(), new TextualSuggestSupport(editorWorkerService, configurationService), true);
}
}
public getInitialState():Modes.IState {
// Because AbstractMode doesn't allow the initial state to immediately enter a nested
// mode, we will enter a nested mode ourselves
var htmlMode = this._modeService.getMode('text/html');
var htmlState:Modes.IState = Modes.TokenizationRegistry.get(htmlMode.getId()).getInitialState();
htmlState.setStateData(new PHPEnterHTMLState(this.getId(), null));
return htmlState;
}
public enterNestedMode(state:Modes.IState):boolean {
return state instanceof PHPEnterHTMLState;
}
public getNestedModeInitialState(myState:Modes.IState): Modes.IState {
// Recall previous HTML state, that was saved in .parent, and carried over by the PHP states
// Also, prevent a .clone() endless loop by clearing the .parent pointer
// (the result will have its stateData point to myState)
var result = (<PHPState>myState).parent;
(<PHPState>myState).parent = null;
return result;
}
public getLeavingNestedModeData(line:string, state:Modes.IState): ILeavingNestedModeData {
// Leave HTML if <? is found on a line
var match:any = /<\?/i.exec(line);
if (match !== null) {
return {
nestedModeBuffer: line.substring(0, match.index),
bufferAfterNestedMode: line.substring(match.index),
stateAfterNestedMode: new PHPPlain(this.getId(), null)
};
}
return null;
}
public onReturningFromNestedMode(myStateAfterNestedMode:Modes.IState, lastNestedModeState:Modes.IState): void {
// Record in .parent the last HTML state before we entered into PHP
// The PHP states will take care of passing .parent along
// such that when we enter HTML again, we can recover the HTML state from .parent
(<PHPPlain>myStateAfterNestedMode).parent = lastNestedModeState;
}
}

File diff suppressed because it is too large Load diff