-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add PHP language #52
Merged
Merged
Changes from 4 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
bb95dad
added tree-sitter-php
urbit-pilled b1493d1
fix CONTRIBUTING.md link
urbit-pilled 4a5c70f
add tree-sitter-python to lsp and target_language
urbit-pilled 7aacc80
added tree-sitter-php to resources
urbit-pilled a8f3731
added wasm
urbit-pilled 1f1a15d
add metavariable to grammar (initial)
urbit-pilled fcc3fc7
udpated tree-sitter-gritql submodule
urbit-pilled b6ac729
initial php tests working now
urbit-pilled ae56041
updated node-types and grammar.js
urbit-pilled 0229548
fix conflicting metavariable prefix and php variable prefix
urbit-pilled a379303
deleted c bindings
urbit-pilled 3d442ec
updated tree-sitter grammar with metavariable prefix change
urbit-pilled 48f5a27
updated tests
urbit-pilled eace2a4
updated gritql to accept ^ as prefix
urbit-pilled d5c1201
updated php with php_only as default
urbit-pilled 197575d
took a lot of debugging to find this
urbit-pilled 0a8d0fc
added php to patterns_directory
urbit-pilled f009c77
Merge branch 'main' into main
urbit-pilled bc91a14
fix merge
urbit-pilled 4a5c69f
remove yaml snapshot basic_php test
urbit-pilled a3c0e4f
added 2 more php tests
urbit-pilled 9acad21
idk about these snapshots
urbit-pilled 2225d9a
fixed tests
urbit-pilled 8b4dba9
restore the parse_correct_variable_ranges snapshots
urbit-pilled 6c98c81
merge with main
urbit-pilled 55ff702
revert php grammar changes so that semicolons are required in snippet
urbit-pilled 8c77c49
Merge branch 'main' into main
urbit-pilled 9f4f125
added tests
urbit-pilled fc90e44
updated php grammar with new fields and placed more grit_metavariables
urbit-pilled cbf8081
added tests
urbit-pilled 16f4d8a
Merge pull request #1 from urbit-pilled/add_tests
urbit-pilled c432a14
fixed array support
urbit-pilled 8a54196
updated php resources
urbit-pilled 066da65
updated tree-sitter-gritql submodule
urbit-pilled b0870fb
merge with remote main
urbit-pilled 17d80bc
fix conflicts
urbit-pilled c631247
updated edit_grammars.mjs
urbit-pilled c469d93
edit_grammar.mjs GNU compatibility issue fixed and changed php->metav…
urbit-pilled 6fedda7
removed grammar conflict, using precedence instead
urbit-pilled 27ea566
updated php grammar
urbit-pilled df1a576
regenerating php files
urbit-pilled fd4e1d6
removed named_child_count == 1 and added more grammar fields
urbit-pilled File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use std::sync::OnceLock; | ||
|
||
use crate::language::{fields_for_nodes, Field, Language, SortId, TSLanguage}; | ||
|
||
static NODE_TYPES_STRING: &str = include_str!("../../../resources/node-types/php-node-types.json"); | ||
|
||
static NODE_TYPES: OnceLock<Vec<Vec<Field>>> = OnceLock::new(); | ||
static LANGUAGE: OnceLock<TSLanguage> = OnceLock::new(); | ||
|
||
#[cfg(not(feature = "builtin-parser"))] | ||
fn language() -> TSLanguage { | ||
unimplemented!( | ||
"tree-sitter parser must be initialized before use when [builtin-parser] is off." | ||
) | ||
} | ||
#[cfg(feature = "builtin-parser")] | ||
fn language() -> TSLanguage { | ||
tree_sitter_php::language_php().into() | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct Php { | ||
node_types: &'static [Vec<Field>], | ||
metavariable_sort: SortId, | ||
language: &'static TSLanguage, | ||
} | ||
|
||
impl Php { | ||
pub(crate) fn new(lang: Option<TSLanguage>) -> Self { | ||
let language = LANGUAGE.get_or_init(|| lang.unwrap_or_else(language)); | ||
let node_types = NODE_TYPES.get_or_init(|| fields_for_nodes(language, NODE_TYPES_STRING)); | ||
let metavariable_sort = language.id_for_node_kind("grit_metavariable", true); | ||
Self { | ||
node_types, | ||
metavariable_sort, | ||
language, | ||
} | ||
} | ||
pub(crate) fn is_initialized() -> bool { | ||
LANGUAGE.get().is_some() | ||
} | ||
} | ||
|
||
impl Language for Php { | ||
fn get_ts_language(&self) -> &TSLanguage { | ||
self.language | ||
} | ||
|
||
fn comment_prefix(&self) -> &'static str { | ||
"//" | ||
} | ||
|
||
fn language_name(&self) -> &'static str { | ||
"Php" | ||
} | ||
fn snippet_context_strings(&self) -> &[(&'static str, &'static str)] { | ||
&[("", "")] | ||
} | ||
|
||
fn node_types(&self) -> &[Vec<Field>] { | ||
self.node_types | ||
} | ||
|
||
fn metavariable_sort(&self) -> SortId { | ||
self.metavariable_sort | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be updated to use the
comment_prefix
method from the Language trait instead of redefining it here.