Skip to content

Commit

Permalink
Config and starting on grammar.
Browse files Browse the repository at this point in the history
  • Loading branch information
qwandor committed Jan 31, 2023
1 parent 2f2e6b4 commit 3336f9c
Show file tree
Hide file tree
Showing 6 changed files with 868 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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}"
]
}
]
}
3 changes: 3 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.vscode/**
.vscode-test/**
.gitignore
25 changes: 25 additions & 0 deletions language-configuration.json
Original file line number Diff line number Diff line change
@@ -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": [
["{", "}"],
["(", ")"],
["\"", "\""],
]
}
47 changes: 47 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
237 changes: 237 additions & 0 deletions syntaxes/pdl.tmLanguage.YAML-tmLanguage
Original file line number Diff line number Diff line change
@@ -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}
Loading

0 comments on commit 3336f9c

Please sign in to comment.