diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..0e191b5 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,17 @@ +// A launch configuration that launches the extension inside a new window +// Use IntelliSense to learn about possible attributes. +// Hover to view descriptions of existing attributes. +// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Extension", + "type": "extensionHost", + "request": "launch", + "args": [ + "--extensionDevelopmentPath=${workspaceFolder}" + ] + } + ] +} \ No newline at end of file diff --git a/.vscodeignore b/.vscodeignore new file mode 100644 index 0000000..19bbe78 --- /dev/null +++ b/.vscodeignore @@ -0,0 +1,3 @@ +.vscode/** +.vscode-test/** +.gitignore diff --git a/language-configuration.json b/language-configuration.json new file mode 100644 index 0000000..3a75e1b --- /dev/null +++ b/language-configuration.json @@ -0,0 +1,25 @@ +{ + "comments": { + "lineComment": "//", + "blockComment": [ "/*", "*/" ] + }, + // Symbols used as brackets. + "brackets": [ + ["{", "}"], + ["[", "]"], + ["(", ")"] + ], + // Symbols that are auto closed when typing. + "autoClosingPairs": [ + ["{", "}"], + ["[", "]"], + ["(", ")"], + ["\"", "\""], + ], + // Symbols that can be used to surround a selection. + "surroundingPairs": [ + ["{", "}"], + ["(", ")"], + ["\"", "\""], + ] +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..ee80290 --- /dev/null +++ b/package.json @@ -0,0 +1,47 @@ +{ + "name": "pdl-language", + "displayName": "PDL", + "description": "Syntax highlighting for the Packet Description Language.", + "version": "0.1.0", + "engines": { + "vscode": "^1.52.0" + }, + "categories": [ + "Programming Languages" + ], + "keywords": [ + "PDL", + "Android" + ], + "publisher": "Google", + "repository": { + "type": "git", + "url": "https://github.com/google/pdl-language.git" + }, + "license": "Apache-2.0", + "contributes": { + "languages": [ + { + "id": "pdl", + "aliases": [ + "PDL", + "pdl" + ], + "extensions": [ + ".pdl" + ], + "configuration": "./language-configuration.json" + } + ], + "grammars": [ + { + "language": "pdl", + "scopeName": "source.pdl", + "path": "./syntaxes/pdl.tmLanguage.json" + } + ] + }, + "devDependencies": { + "js-yaml": "^3.14.1" + } +} \ No newline at end of file diff --git a/syntaxes/pdl.tmLanguage.YAML-tmLanguage b/syntaxes/pdl.tmLanguage.YAML-tmLanguage new file mode 100644 index 0000000..14eef95 --- /dev/null +++ b/syntaxes/pdl.tmLanguage.YAML-tmLanguage @@ -0,0 +1,237 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +$schema: 'https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json' +fileTypes: + - pdl +scopeName: source.pdl +name: PDL +foldingStartMarker: '\{\s*$' +foldingStopMarker: '^\s*\}' +patterns: + - include: '#main' +repository: + main: + patterns: + - include: '#comments' + - include: '#endianness' + - include: '#declaration' + - match: '([^\s])' + name: invalid.illegal.pdl + comments: + patterns: + - include: '#multi_line_comment' + - match: (//).* + name: comment.line.double-slash.pdl + captures: + '1': {name: punctuation.definition.comment.pdl} + endianness: + patterns: + - match: \b(little_endian_packets|big_endian_packets)\b + name: keyword.pdl + declaration: + patterns: + - name: meta.enum.pdl + begin: '(enum)\s+([a-zA-Z][a-zA-Z0-9_]*)\s*(:)\s*([0-9]+)\s*(\{)' + beginCaptures: + '1': {name: storage.type.enum.pdl} + '2': {name: entity.name.type.enum.pdl} + '3': {name: punctuation.separator.pdl} + '4': {name: constant.numeric.decimal.pdl} + '5': {name: punctuation.section.braces.begin.pdl} + end: '(\})' + endCaptures: + '1': {name: punctuation.section.braces.end.pdl} + patterns: + - include: '#enum_body' + - name: meta.enum.pdl + begin: '(enum)\s+([a-zA-Z][a-zA-Z0-9_]*)\s*(:)\s*(0[xX][0-9a-fA-F]+)\s*(\{)' + beginCaptures: + '1': {name: storage.type.enum.pdl} + '2': {name: entity.name.type.enum.pdl} + '3': {name: punctuation.separator.pdl} + '4': {name: constant.numeric.hex.pdl} + '5': {name: punctuation.section.braces.begin.pdl} + end: '(\})' + endCaptures: + '1': {name: punctuation.section.braces.end.pdl} + patterns: + - include: '#enum_body' + - name: meta.packet.pdl + begin: '(packet)\s+([a-zA-Z][a-zA-Z0-9_]*)\s*(\{)' + beginCaptures: + '1': {name: storage.type.packet.pdl} + '2': {name: entity.name.type.packet.pdl} + '3': {name: punctuation.section.braces.begin.pdl} + end: '(\})' + endCaptures: + '1': {name: punctuation.section.braces.end.pdl} + patterns: + - include: '#field_list' + - name: meta.packet.pdl + begin: '(packet)\s+([a-zA-Z][a-zA-Z0-9_]*)\s*(:)\s*([a-zA-Z][a-zA-Z0-9_]*)\s*(\{)' + beginCaptures: + '1': {name: storage.type.packet.pdl} + '2': {name: entity.name.type.packet.pdl} + '3': {name: punctuation.separator.pdl} + '4': {name: entity.name.type.packet.pdl} + '5': {name: punctuation.section.braces.begin.pdl} + end: '(\})' + endCaptures: + '1': {name: punctuation.section.braces.end.pdl} + patterns: + - include: '#field_list' + - name: meta.struct.pdl + begin: '(struct)\s+([a-zA-Z][a-zA-Z0-9_]*)\s*(\{)' + beginCaptures: + '1': {name: storage.type.struct.pdl} + '2': {name: entity.name.type.struct.pdl} + '3': {name: punctuation.section.braces.begin.pdl} + end: '(\})' + endCaptures: + '1': {name: punctuation.section.braces.end.pdl} + patterns: + - include: '#field_list' + - name: meta.struct.pdl + begin: '(struct)\s+([a-zA-Z][a-zA-Z0-9_]*)\s*(:)\s*([a-zA-Z][a-zA-Z0-9_]*)\s*(\{)' + beginCaptures: + '1': {name: storage.type.struct.pdl} + '2': {name: entity.name.type.struct.pdl} + '3': {name: punctuation.separator.pdl} + '4': {name: entity.name.type.struct.pdl} + '5': {name: punctuation.section.braces.begin.pdl} + end: '(\})' + endCaptures: + '1': {name: punctuation.section.braces.end.pdl} + patterns: + - include: '#field_list' + - name: meta.group.pdl + begin: '(group)\s+([a-zA-Z][a-zA-Z0-9_]*)\s*(\{)' + beginCaptures: + '1': {name: storage.type.group.pdl} + '2': {name: entity.name.type.group.pdl} + '3': {name: punctuation.section.braces.begin.pdl} + end: '(\})' + endCaptures: + '1': {name: punctuation.section.braces.end.pdl} + patterns: + - include: '#field_list' + - name: meta.checksum.pdl + match: '(checksum)\s+([a-zA-Z][a-zA-Z0-9_]*)\s*(:)\s*([0-9]+)\s*(")([^\"]*)(")' + captures: + '1': {name: storage.type.checksum.pdl} + '2': {name: entity.name.type.checksum.pdl} + '3': {name: punctuation.separator.pdl} + '4': {name: constant.numeric.decimal.pdl} + '5': {name: punctuation.definition.string.begin.aidl} + '6': {name: string.quoted.double.aidl} + '7': {name: punctuation.definition.string.end.aidl} + - name: meta.checksum.pdl + match: '(checksum)\s+([a-zA-Z][a-zA-Z0-9_]*)\s*(:)\s*(0[xX][0-9a-fA-F]+)\s*(")([^\"]*)(")' + captures: + '1': {name: storage.type.checksum.pdl} + '2': {name: entity.name.type.checksum.pdl} + '3': {name: punctuation.separator.pdl} + '4': {name: constant.numeric.hex.pdl} + '5': {name: punctuation.definition.string.begin.aidl} + '6': {name: string.quoted.double.aidl} + '7': {name: punctuation.definition.string.end.aidl} + enum_body: + patterns: + - include: '#comments' + - match: = + name: keyword.operator.assignment.pdl + - include: '#integer' + - match: , + name: punctuation.separator.pdl + - match: '[a-zA-Z][a-zA-Z0-9_]*' + name: entity.name.constant.ddl + field_list: + patterns: + - include: '#comments' + - match: ':' + name: punctuation.separator.pdl + - match: (\[)\s*(\+)\s*([0-9]+)(\]) # SIZE_MODIFIER + captures: + '1': {name: punctuation.pdl} + '2': {name: keyword.operator.arithmetic.pdl} + '3': {name: constant.numeric.decimal.pdl} + '4': {name: punctuation.pdl} + - match: (\[)([0-9]+)(\]) + captures: + '1': {name: punctuation.pdl} + '2': {name: constant.numeric.decimal.pdl} + '3': {name: punctuation.pdl} + - match: (\[)(0[xX][0-9a-fA-F]+)(\]) + captures: + '1': {name: punctuation.pdl} + '2': {name: constant.numeric.hex.pdl} + '3': {name: punctuation.pdl} + - begin: '(\{)' + beginCaptures: + '1': {name: punctuation.section.braces.begin.pdl} + end: '(\})' + endCaptures: + '1': {name: punctuation.section.braces.end.pdl} + patterns: + - include: '#constraint_list' + - match: '(_size_)\s*(\()\s*(_payload_|_body_)\s*(\))\s*(:)' + captures: + '1': {name: keyword.pdl} + '2': {name: punctuation.begin.pdl} + '3': {name: keyword.pdl} + '4': {name: punctuation.end.pdl} + '5': {name: punctuation.separator.pdl} + - match: '(_size_|_count_)\s*(\()\s*([a-zA-Z][a-zA-Z0-9_]*)\s*(\))\s*(:)' + captures: + '1': {name: keyword.pdl} + '2': {name: punctuation.begin.pdl} + '3': {name: entity.name.pdl} + '4': {name: punctuation.end.pdl} + '5': {name: punctuation.separator.pdl} + - match: '(_payload_)\s*(:)\s*(\[)\s*(\+)\s*([0-9]+)([\]])' + captures: + '1': {name: keyword.pdl} + '2': {name: punctuation.separator.pdl} + '3': {name: punctuation.begin.pdl} + '4': {name: keyword.operator.arithmetic.pdl} + '5': {name: constant.numeric.decimal.pdl} + '6': {name: punctuation.end.pdl} + - match: _body_ + name: keyword.pdl + - match: '[a-zA-Z][a-zA-Z0-9_]*' + name: entity.name.pdl + - include: '#integer' + integer: + patterns: + - match: '0[xX][0-9a-fA-F]+' + name: constant.numeric.hex.pdl + - match: '[0-9]+' + name: constant.numeric.decimal.pdl + multi_line_comment: + patterns: + - begin: (/\*\*) + beginCaptures: + '1': {name: punctuation.definition.comment.aidl} + name: comment.block.documentation.aidl + end: (\*/) + endCaptures: + '1': {name: punctuation.definition.comment.aidl} + - begin: (/\*) + beginCaptures: + '1': {name: punctuation.definition.comment.aidl} + name: comment.block.aidl + end: (\*/) + endCaptures: + '1': {name: punctuation.definition.comment.aidl} diff --git a/syntaxes/pdl.tmLanguage.json b/syntaxes/pdl.tmLanguage.json new file mode 100644 index 0000000..c0f6c4c --- /dev/null +++ b/syntaxes/pdl.tmLanguage.json @@ -0,0 +1,539 @@ +{ + "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json", + "fileTypes": [ + "pdl" + ], + "scopeName": "source.pdl", + "name": "PDL", + "foldingStartMarker": "\\{\\s*$", + "foldingStopMarker": "^\\s*\\}", + "patterns": [ + { + "include": "#main" + } + ], + "repository": { + "main": { + "patterns": [ + { + "include": "#comments" + }, + { + "include": "#endianness" + }, + { + "include": "#declaration" + }, + { + "match": "([^\\s])", + "name": "invalid.illegal.pdl" + } + ] + }, + "comments": { + "patterns": [ + { + "include": "#multi_line_comment" + }, + { + "match": "(//).*", + "name": "comment.line.double-slash.pdl", + "captures": { + "1": { + "name": "punctuation.definition.comment.pdl" + } + } + } + ] + }, + "endianness": { + "patterns": [ + { + "match": "\\b(little_endian_packets|big_endian_packets)\\b", + "name": "keyword.pdl" + } + ] + }, + "declaration": { + "patterns": [ + { + "name": "meta.enum.pdl", + "begin": "(enum)\\s+([a-zA-Z][a-zA-Z0-9_]*)\\s*(:)\\s*([0-9]+)\\s*(\\{)", + "beginCaptures": { + "1": { + "name": "storage.type.enum.pdl" + }, + "2": { + "name": "entity.name.type.enum.pdl" + }, + "3": { + "name": "punctuation.separator.pdl" + }, + "4": { + "name": "constant.numeric.decimal.pdl" + }, + "5": { + "name": "punctuation.section.braces.begin.pdl" + } + }, + "end": "(\\})", + "endCaptures": { + "1": { + "name": "punctuation.section.braces.end.pdl" + } + }, + "patterns": [ + { + "include": "#enum_body" + } + ] + }, + { + "name": "meta.enum.pdl", + "begin": "(enum)\\s+([a-zA-Z][a-zA-Z0-9_]*)\\s*(:)\\s*(0[xX][0-9a-fA-F]+)\\s*(\\{)", + "beginCaptures": { + "1": { + "name": "storage.type.enum.pdl" + }, + "2": { + "name": "entity.name.type.enum.pdl" + }, + "3": { + "name": "punctuation.separator.pdl" + }, + "4": { + "name": "constant.numeric.hex.pdl" + }, + "5": { + "name": "punctuation.section.braces.begin.pdl" + } + }, + "end": "(\\})", + "endCaptures": { + "1": { + "name": "punctuation.section.braces.end.pdl" + } + }, + "patterns": [ + { + "include": "#enum_body" + } + ] + }, + { + "name": "meta.packet.pdl", + "begin": "(packet)\\s+([a-zA-Z][a-zA-Z0-9_]*)\\s*(\\{)", + "beginCaptures": { + "1": { + "name": "storage.type.packet.pdl" + }, + "2": { + "name": "entity.name.type.packet.pdl" + }, + "3": { + "name": "punctuation.section.braces.begin.pdl" + } + }, + "end": "(\\})", + "endCaptures": { + "1": { + "name": "punctuation.section.braces.end.pdl" + } + }, + "patterns": [ + { + "include": "#field_list" + } + ] + }, + { + "name": "meta.packet.pdl", + "begin": "(packet)\\s+([a-zA-Z][a-zA-Z0-9_]*)\\s*(:)\\s*([a-zA-Z][a-zA-Z0-9_]*)\\s*(\\{)", + "beginCaptures": { + "1": { + "name": "storage.type.packet.pdl" + }, + "2": { + "name": "entity.name.type.packet.pdl" + }, + "3": { + "name": "punctuation.separator.pdl" + }, + "4": { + "name": "entity.name.type.packet.pdl" + }, + "5": { + "name": "punctuation.section.braces.begin.pdl" + } + }, + "end": "(\\})", + "endCaptures": { + "1": { + "name": "punctuation.section.braces.end.pdl" + } + }, + "patterns": [ + { + "include": "#field_list" + } + ] + }, + { + "name": "meta.struct.pdl", + "begin": "(struct)\\s+([a-zA-Z][a-zA-Z0-9_]*)\\s*(\\{)", + "beginCaptures": { + "1": { + "name": "storage.type.struct.pdl" + }, + "2": { + "name": "entity.name.type.struct.pdl" + }, + "3": { + "name": "punctuation.section.braces.begin.pdl" + } + }, + "end": "(\\})", + "endCaptures": { + "1": { + "name": "punctuation.section.braces.end.pdl" + } + }, + "patterns": [ + { + "include": "#field_list" + } + ] + }, + { + "name": "meta.struct.pdl", + "begin": "(struct)\\s+([a-zA-Z][a-zA-Z0-9_]*)\\s*(:)\\s*([a-zA-Z][a-zA-Z0-9_]*)\\s*(\\{)", + "beginCaptures": { + "1": { + "name": "storage.type.struct.pdl" + }, + "2": { + "name": "entity.name.type.struct.pdl" + }, + "3": { + "name": "punctuation.separator.pdl" + }, + "4": { + "name": "entity.name.type.struct.pdl" + }, + "5": { + "name": "punctuation.section.braces.begin.pdl" + } + }, + "end": "(\\})", + "endCaptures": { + "1": { + "name": "punctuation.section.braces.end.pdl" + } + }, + "patterns": [ + { + "include": "#field_list" + } + ] + }, + { + "name": "meta.group.pdl", + "begin": "(group)\\s+([a-zA-Z][a-zA-Z0-9_]*)\\s*(\\{)", + "beginCaptures": { + "1": { + "name": "storage.type.group.pdl" + }, + "2": { + "name": "entity.name.type.group.pdl" + }, + "3": { + "name": "punctuation.section.braces.begin.pdl" + } + }, + "end": "(\\})", + "endCaptures": { + "1": { + "name": "punctuation.section.braces.end.pdl" + } + }, + "patterns": [ + { + "include": "#field_list" + } + ] + }, + { + "name": "meta.checksum.pdl", + "match": "(checksum)\\s+([a-zA-Z][a-zA-Z0-9_]*)\\s*(:)\\s*([0-9]+)\\s*(\")([^\\\"]*)(\")", + "captures": { + "1": { + "name": "storage.type.checksum.pdl" + }, + "2": { + "name": "entity.name.type.checksum.pdl" + }, + "3": { + "name": "punctuation.separator.pdl" + }, + "4": { + "name": "constant.numeric.decimal.pdl" + }, + "5": { + "name": "punctuation.definition.string.begin.aidl" + }, + "6": { + "name": "string.quoted.double.aidl" + }, + "7": { + "name": "punctuation.definition.string.end.aidl" + } + } + }, + { + "name": "meta.checksum.pdl", + "match": "(checksum)\\s+([a-zA-Z][a-zA-Z0-9_]*)\\s*(:)\\s*(0[xX][0-9a-fA-F]+)\\s*(\")([^\\\"]*)(\")", + "captures": { + "1": { + "name": "storage.type.checksum.pdl" + }, + "2": { + "name": "entity.name.type.checksum.pdl" + }, + "3": { + "name": "punctuation.separator.pdl" + }, + "4": { + "name": "constant.numeric.hex.pdl" + }, + "5": { + "name": "punctuation.definition.string.begin.aidl" + }, + "6": { + "name": "string.quoted.double.aidl" + }, + "7": { + "name": "punctuation.definition.string.end.aidl" + } + } + } + ] + }, + "enum_body": { + "patterns": [ + { + "include": "#comments" + }, + { + "match": "=", + "name": "keyword.operator.assignment.pdl" + }, + { + "include": "#integer" + }, + { + "match": ",", + "name": "punctuation.separator.pdl" + }, + { + "match": "[a-zA-Z][a-zA-Z0-9_]*", + "name": "entity.name.constant.ddl" + } + ] + }, + "field_list": { + "patterns": [ + { + "include": "#comments" + }, + { + "match": ":", + "name": "punctuation.separator.pdl" + }, + { + "match": "(\\[)\\s*(\\+)\\s*([0-9]+)(\\])", + "captures": { + "1": { + "name": "punctuation.pdl" + }, + "2": { + "name": "keyword.operator.arithmetic.pdl" + }, + "3": { + "name": "constant.numeric.decimal.pdl" + }, + "4": { + "name": "punctuation.pdl" + } + } + }, + { + "match": "(\\[)([0-9]+)(\\])", + "captures": { + "1": { + "name": "punctuation.pdl" + }, + "2": { + "name": "constant.numeric.decimal.pdl" + }, + "3": { + "name": "punctuation.pdl" + } + } + }, + { + "match": "(\\[)(0[xX][0-9a-fA-F]+)(\\])", + "captures": { + "1": { + "name": "punctuation.pdl" + }, + "2": { + "name": "constant.numeric.hex.pdl" + }, + "3": { + "name": "punctuation.pdl" + } + } + }, + { + "begin": "(\\{)", + "beginCaptures": { + "1": { + "name": "punctuation.section.braces.begin.pdl" + } + }, + "end": "(\\})", + "endCaptures": { + "1": { + "name": "punctuation.section.braces.end.pdl" + } + }, + "patterns": [ + { + "include": "#constraint_list" + } + ] + }, + { + "match": "(_size_)\\s*(\\()\\s*(_payload_|_body_)\\s*(\\))\\s*(:)", + "captures": { + "1": { + "name": "keyword.pdl" + }, + "2": { + "name": "punctuation.begin.pdl" + }, + "3": { + "name": "keyword.pdl" + }, + "4": { + "name": "punctuation.end.pdl" + }, + "5": { + "name": "punctuation.separator.pdl" + } + } + }, + { + "match": "(_size_|_count_)\\s*(\\()\\s*([a-zA-Z][a-zA-Z0-9_]*)\\s*(\\))\\s*(:)", + "captures": { + "1": { + "name": "keyword.pdl" + }, + "2": { + "name": "punctuation.begin.pdl" + }, + "3": { + "name": "entity.name.pdl" + }, + "4": { + "name": "punctuation.end.pdl" + }, + "5": { + "name": "punctuation.separator.pdl" + } + } + }, + { + "match": "(_payload_)\\s*(:)\\s*(\\[)\\s*(\\+)\\s*([0-9]+)([\\]])", + "captures": { + "1": { + "name": "keyword.pdl" + }, + "2": { + "name": "punctuation.separator.pdl" + }, + "3": { + "name": "punctuation.begin.pdl" + }, + "4": { + "name": "keyword.operator.arithmetic.pdl" + }, + "5": { + "name": "constant.numeric.decimal.pdl" + }, + "6": { + "name": "punctuation.end.pdl" + } + } + }, + { + "match": "_body_", + "name": "keyword.pdl" + }, + { + "match": "[a-zA-Z][a-zA-Z0-9_]*", + "name": "entity.name.pdl" + }, + { + "include": "#integer" + } + ] + }, + "integer": { + "patterns": [ + { + "match": "0[xX][0-9a-fA-F]+", + "name": "constant.numeric.hex.pdl" + }, + { + "match": "[0-9]+", + "name": "constant.numeric.decimal.pdl" + } + ] + }, + "multi_line_comment": { + "patterns": [ + { + "begin": "(/\\*\\*)", + "beginCaptures": { + "1": { + "name": "punctuation.definition.comment.aidl" + } + }, + "name": "comment.block.documentation.aidl", + "end": "(\\*/)", + "endCaptures": { + "1": { + "name": "punctuation.definition.comment.aidl" + } + } + }, + { + "begin": "(/\\*)", + "beginCaptures": { + "1": { + "name": "punctuation.definition.comment.aidl" + } + }, + "name": "comment.block.aidl", + "end": "(\\*/)", + "endCaptures": { + "1": { + "name": "punctuation.definition.comment.aidl" + } + } + } + ] + } + } +} \ No newline at end of file