Skip to content

Commit

Permalink
Merge pull request #160 from ahmedash95/update-php
Browse files Browse the repository at this point in the history
Update php to v0.22.4
  • Loading branch information
smacker authored May 10, 2024
2 parents 8ba0365 + 679e829 commit 04d6b33
Show file tree
Hide file tree
Showing 11 changed files with 135,407 additions and 60,394 deletions.
9 changes: 5 additions & 4 deletions _automation/grammars.json
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,11 @@
"url": "https://github.com/tree-sitter/tree-sitter-php",
"files": [
"parser.c",
"scanner.cc"
"scanner.c",
"scanner.h"
],
"reference": "v0.19.0",
"revision": "3ef0d5c253affe4b7fb46d9505db6df143db565a",
"reference": "v0.22.4",
"revision": "58054be104db0809ea6f119514a4d904f95e5b5c",
"updateBasedOn": "tag"
},
{
Expand Down Expand Up @@ -322,4 +323,4 @@
"revision": "6129a83eeec7d6070b1c0567ec7ce3509ead607c",
"updateBasedOn": "tag"
}
]
]
40 changes: 40 additions & 0 deletions _automation/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ func (s *UpdateService) downloadGrammar(ctx context.Context, g *Grammar) {
s.downloadTypescript(ctx, g)
case "yaml":
s.downloadYaml(ctx, g)
case "php":
s.downloadPhp(ctx, g)
default:
s.defaultGrammarDownload(ctx, g)
}
Expand Down Expand Up @@ -323,6 +325,44 @@ func (s *UpdateService) writeGrammarsFile(ctx context.Context) {
}
}

func (s *UpdateService) downloadPhp(ctx context.Context, g *Grammar) {
fileMapping := map[string]string{
"parser.c": "php/src/parser.c",
"scanner.c": "php/src/scanner.c",
"scanner.h": "common/scanner.h",
}

url := g.ContentURL()

treeSitterFiles := []string{"parser.h", "array.h", "alloc.h"}

for _, f := range treeSitterFiles {
s.downloadFile(
ctx,
fmt.Sprintf("%s/%s/php/src/tree_sitter/%s", url, g.Revision, f),
fmt.Sprintf("%s/tree_sitter/%s", g.Language, f),
nil,
)
}

for _, f := range g.Files {
fp, ok := fileMapping[f]
if !ok {
logAndExit(getLogger(ctx), "mapping for file not found", "file", f)
}

s.downloadFile(
ctx,
fmt.Sprintf("%s/%s/%s", url, g.Revision, fp),
fmt.Sprintf("%s/%s", g.Language, f),
map[string]string{
`<tree_sitter/parser.h>`: `"parser.h"`,
`"../../common/scanner.h"`: `"scanner.h"`,
},
)
}
}

// ocaml is special since its folder structure is different from the other ones
func (s *UpdateService) downloadOcaml(ctx context.Context, g *Grammar) {
fileMapping := map[string]string{
Expand Down
Loading

0 comments on commit 04d6b33

Please sign in to comment.