From cd6db5009170a89340e9f9f6ea3b8f28a0141f13 Mon Sep 17 00:00:00 2001 From: mkslanc Date: Sat, 28 Jan 2023 13:19:13 +0400 Subject: [PATCH 1/3] add PhpService (only validation) --- package-lock.json | 21 + packages/ace-linters/services/php/lib/php.js | 1536 +++++++++++++++++ .../ace-linters/services/php/php-service.ts | 45 + .../ace-linters/types/language-service.d.ts | 7 +- packages/demo/webworker-lsp/demo.ts | 5 +- .../webworker-lsp/docs-example/php-example.js | 21 + packages/demo/webworker-lsp/webworker.ts | 11 +- 7 files changed, 1639 insertions(+), 7 deletions(-) create mode 100644 packages/ace-linters/services/php/lib/php.js create mode 100644 packages/ace-linters/services/php/php-service.ts create mode 100644 packages/demo/webworker-lsp/docs-example/php-example.js diff --git a/package-lock.json b/package-lock.json index 147453d8..613e1472 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,6 +26,27 @@ "webpack-dev-server": "latest" } }, + "D:/AppServ/www/intelephense": { + "version": "0.8.8", + "extraneous": true, + "license": "ISC", + "dependencies": { + "fs-extra": "^5.0.0", + "JSONStream": "^1.3.2", + "php7parser": "^1.0.8", + "vscode-languageserver-types": "^3.5.0" + }, + "devDependencies": { + "@types/chai": "^4.1.2", + "@types/fs-extra": "^5.0.0", + "@types/mocha": "^2.2.48", + "@types/node": "^7.0.54", + "chai": "^4.1.2", + "mocha": "^4.1.0", + "ts-node": "^3.3.0", + "typescript": "^2.7.1" + } + }, "node_modules/@ace-linters/demo": { "resolved": "packages/demo", "link": true diff --git a/packages/ace-linters/services/php/lib/php.js b/packages/ace-linters/services/php/lib/php.js new file mode 100644 index 00000000..78715491 --- /dev/null +++ b/packages/ace-linters/services/php/lib/php.js @@ -0,0 +1,1536 @@ +/* + php.js 0.1.0 + Copyright (c) 2013 Niklas von Hertzen + + Released under MIT License + + This file contains: + - [var PHP = {Constants:{}};] + - src/modules/tokenizer/constants.js + - src/parser/lexer.js + - src/parser/parser.js + - src/parser/yyn.js + - src/parser/yyn_stmt.js + - src/parser/yyn_expr.js + - src/parser/yyn_scalar.js +*/ + + +var PHP = {Constants: {}}; + +PHP.Constants.T_THROW = 317; +PHP.Constants.T_INCLUDE = 272; +PHP.Constants.T_INCLUDE_ONCE = 273; +PHP.Constants.T_EVAL = 274; +PHP.Constants.T_REQUIRE = 275; +PHP.Constants.T_REQUIRE_ONCE = 276; +PHP.Constants.T_LOGICAL_OR = 277; +PHP.Constants.T_LOGICAL_XOR = 278; +PHP.Constants.T_LOGICAL_AND = 279; +PHP.Constants.T_PRINT = 280; +PHP.Constants.T_YIELD = 281; +PHP.Constants.T_DOUBLE_ARROW = 386; +PHP.Constants.T_YIELD_FROM = 282; +PHP.Constants.T_PLUS_EQUAL = 352; +PHP.Constants.T_MINUS_EQUAL = 353; +PHP.Constants.T_MUL_EQUAL = 354; +PHP.Constants.T_DIV_EQUAL = 355; +PHP.Constants.T_CONCAT_EQUAL = 356; +PHP.Constants.T_MOD_EQUAL = 357; +PHP.Constants.T_AND_EQUAL = 358; +PHP.Constants.T_OR_EQUAL = 359; +PHP.Constants.T_XOR_EQUAL = 360; +PHP.Constants.T_SL_EQUAL = 361; +PHP.Constants.T_SR_EQUAL = 362; +PHP.Constants.T_POW_EQUAL = 402; +PHP.Constants.T_COALESCE_EQUAL = 363; +PHP.Constants.T_COALESCE = 400; +PHP.Constants.T_BOOLEAN_OR = 364; +PHP.Constants.T_BOOLEAN_AND = 365; +PHP.Constants.T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG = 404; +PHP.Constants.T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG = 403; +PHP.Constants.T_IS_EQUAL = 366; +PHP.Constants.T_IS_NOT_EQUAL = 367; +PHP.Constants.T_IS_IDENTICAL = 368; +PHP.Constants.T_IS_NOT_IDENTICAL = 369; +PHP.Constants.T_SPACESHIP = 372; +PHP.Constants.T_IS_SMALLER_OR_EQUAL = 370; +PHP.Constants.T_IS_GREATER_OR_EQUAL = 371; +PHP.Constants.T_SL = 373; +PHP.Constants.T_SR = 374; +PHP.Constants.T_INSTANCEOF = 283; +PHP.Constants.T_INC = 375; +PHP.Constants.T_DEC = 376; +PHP.Constants.T_INT_CAST = 377; +PHP.Constants.T_DOUBLE_CAST = 378; +PHP.Constants.T_STRING_CAST = 379; +PHP.Constants.T_ARRAY_CAST = 380; +PHP.Constants.T_OBJECT_CAST = 381; +PHP.Constants.T_BOOL_CAST = 382; +PHP.Constants.T_UNSET_CAST = 383; +PHP.Constants.T_POW = 401; +PHP.Constants.T_NEW = 284; +PHP.Constants.T_CLONE = 285; +PHP.Constants.T_EXIT = 286; +PHP.Constants.T_IF = 287; +PHP.Constants.T_ELSEIF = 288; +PHP.Constants.T_ELSE = 289; +PHP.Constants.T_ENDIF = 290; +PHP.Constants.T_LNUMBER = 260; +PHP.Constants.T_DNUMBER = 261; +PHP.Constants.T_STRING = 262; +PHP.Constants.T_STRING_VARNAME = 270; +PHP.Constants.T_VARIABLE = 266; +PHP.Constants.T_NUM_STRING = 271; +PHP.Constants.T_INLINE_HTML = 267; +PHP.Constants.T_ENCAPSED_AND_WHITESPACE = 268; +PHP.Constants.T_CONSTANT_ENCAPSED_STRING = 269; +PHP.Constants.T_ECHO = 291; +PHP.Constants.T_DO = 292; +PHP.Constants.T_WHILE = 293; +PHP.Constants.T_ENDWHILE = 294; +PHP.Constants.T_FOR = 295; +PHP.Constants.T_ENDFOR = 296; +PHP.Constants.T_FOREACH = 297; +PHP.Constants.T_ENDFOREACH = 298; +PHP.Constants.T_DECLARE = 299; +PHP.Constants.T_ENDDECLARE = 300; +PHP.Constants.T_AS = 301; +PHP.Constants.T_SWITCH = 302; +PHP.Constants.T_MATCH = 306; +PHP.Constants.T_ENDSWITCH = 303; +PHP.Constants.T_CASE = 304; +PHP.Constants.T_DEFAULT = 305; +PHP.Constants.T_BREAK = 307; +PHP.Constants.T_CONTINUE = 308; +PHP.Constants.T_GOTO = 309; +PHP.Constants.T_FUNCTION = 310; +PHP.Constants.T_FN = 311; +PHP.Constants.T_CONST = 312; +PHP.Constants.T_RETURN = 313; +PHP.Constants.T_TRY = 314; +PHP.Constants.T_CATCH = 315; +PHP.Constants.T_FINALLY = 316; +PHP.Constants.T_THROW = 317; +PHP.Constants.T_USE = 318; +PHP.Constants.T_INSTEADOF = 319; +PHP.Constants.T_GLOBAL = 320; +PHP.Constants.T_STATIC = 321; +PHP.Constants.T_ABSTRACT = 322; +PHP.Constants.T_FINAL = 323; +PHP.Constants.T_PRIVATE = 324; +PHP.Constants.T_PROTECTED = 325; +PHP.Constants.T_PUBLIC = 326; +PHP.Constants.T_READONLY = 327; +PHP.Constants.T_VAR = 328; +PHP.Constants.T_UNSET = 329; +PHP.Constants.T_ISSET = 330; +PHP.Constants.T_EMPTY = 331; +PHP.Constants.T_HALT_COMPILER = 332; +PHP.Constants.T_CLASS = 333; +PHP.Constants.T_TRAIT = 334; +PHP.Constants.T_INTERFACE = 335; +PHP.Constants.T_ENUM = 336; +PHP.Constants.T_EXTENDS = 337; +PHP.Constants.T_IMPLEMENTS = 338; +PHP.Constants.T_OBJECT_OPERATOR = 384; +PHP.Constants.T_NULLSAFE_OBJECT_OPERATOR = 385; +PHP.Constants.T_DOUBLE_ARROW = 386; +PHP.Constants.T_LIST = 340; +PHP.Constants.T_ARRAY = 341; +PHP.Constants.T_CALLABLE = 342; +PHP.Constants.T_CLASS_C = 346; +PHP.Constants.T_TRAIT_C = 347; +PHP.Constants.T_METHOD_C = 348; +PHP.Constants.T_FUNC_C = 349; +PHP.Constants.T_LINE = 343; +PHP.Constants.T_FILE = 344; +PHP.Constants.T_START_HEREDOC = 393; +PHP.Constants.T_END_HEREDOC = 394; +PHP.Constants.T_DOLLAR_OPEN_CURLY_BRACES = 395; +PHP.Constants.T_CURLY_OPEN = 396; +PHP.Constants.T_PAAMAYIM_NEKUDOTAYIM = 397; +PHP.Constants.T_NAMESPACE = 339; +PHP.Constants.T_NS_C = 350; +PHP.Constants.T_DIR = 345; +PHP.Constants.T_NS_SEPARATOR = 398; +PHP.Constants.T_ELLIPSIS = 399; +PHP.Constants.T_NAME_FULLY_QUALIFIED = 263; +PHP.Constants.T_NAME_QUALIFIED = 265; +PHP.Constants.T_NAME_RELATIVE = 264; +PHP.Constants.T_ATTRIBUTE = 351; +PHP.Constants.T_ENUM = 336; +PHP.Constants.T_BAD_CHARACTER = 405; +PHP.Constants.T_COMMENT = 387; +PHP.Constants.T_DOC_COMMENT = 388; +PHP.Constants.T_OPEN_TAG = 389; +PHP.Constants.T_OPEN_TAG_WITH_ECHO = 390; +PHP.Constants.T_CLOSE_TAG = 391; +PHP.Constants.T_WHITESPACE = 392; + +PHP.Lexer = function (src, ini) { + var heredoc, heredocEndAllowed, + + stateStack = ['INITIAL'], stackPos = 0, swapState = function (state) { + stateStack[stackPos] = state; + }, pushState = function (state) { + stateStack[++stackPos] = state; + }, popState = function () { + --stackPos; + }, + + shortOpenTag = ini === undefined || /^(on|true|1)$/i.test(ini.short_open_tag), openTag = shortOpenTag ? /^(\<\?php(?:\r\n|[ \t\r\n])|<\?|\