Skip to content

Commit 53cbfa7

Browse files
committed
Add README
1 parent b79d214 commit 53cbfa7

File tree

1 file changed

+143
-0
lines changed

1 file changed

+143
-0
lines changed

README.md

+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
# Introduction
2+
semantic-php is an experimental package for GNU Emacs aiming to improve the level of support for PHP in the [Semantic](http://cedet.sourceforge.net/semantic.shtml) framework. It contains a from-scratch LALR parser based on the PHP7 grammar, an implementation of the semantic API and a test suite.
3+
4+
The ultimate objective of semantic-php is to make the support for PHP in semantic on par with the support for C/C++.
5+
6+
# State of affairs
7+
This package is currently only useful for (elisp) developers. It's very much a work in progress.
8+
9+
The parser has not seen a lot of real-world testing but is an improvement on the existing parser in several ways. The real challenge though is not extracting information from source files but implementing the semantic API to do something useful with that information.
10+
11+
Semantic does a lot of smart things out-of-the-box and allows language implementors to override specific parts of the API to accomodate new or different behaviour. But although it offers this generic (language-neutral) API, semantic is biased towards the target languages it supports - most notably the first-class citizens: C/C++. And not all differences between PHP and the target languages can be overcome by simply implementing the provided overrides. This repository currently contains no major advances in that area. Yet.
12+
13+
Some specific examples of the difficulties described above are:
14+
15+
* namespaces without brace blocks are ubiquitous in PHP, but a completely new concept in Semantic. I've tried several approaches but all have their own disadvantage. I think we can find a satisfactory solution short-term, and ideally propose changes to semantic to allow implementing this cleanly.
16+
17+
* use statements have very different semantics (pun intended) compared to "using" and "namespace X = Y" in C++, using the c.el overrides for this is a pitfall
18+
19+
* namespaces in PHP are not hierarchical, simply splitting each identifier by namespace separator and then let semantic do its tricks will not work
20+
21+
* ...
22+
23+
# Plan de campagne
24+
25+
Milestone #1: implement namespaces without braces, use statements and name resolution rules
26+
27+
* document and discuss problems and possible solutions for each of these features
28+
* implement the best override or workaround for each feature
29+
* work with CEDET to discuss new overrides or find better implementations
30+
31+
When this is implemented, context parsing works without custom semanticdb backend for all single-file PHP sources or those that use require/include directives. For other sources (those that you're actually working on) ede-php-autoload must be used (or a backend ctags/phptags-like backend). I'd like to note that there are quicker routes to get some features working (like skipping context analysis, and using custom routines to resolve class names, etc) but I'm still very determined to leverage the semantic API to the fullest.
32+
33+
Milestone #2+:
34+
35+
* implement traits and trait precedence
36+
* extract type information from annotations
37+
* decide on what parser we'd like to ship in semantic-php (I'm open for any discussion; maybe my rewrite isn't the best and it's better to simply go for the java-based/wisent-php parser)
38+
* get lots of ideas in the issue tracker!
39+
40+
# Requirements
41+
* Emacs 24.4 or higher
42+
* [php-mode](https://github.com/ejmr/php-mode) (any version)
43+
44+
# Suggested packages
45+
* [ede-php-autoload](https://github.com/stevenremot/ede-php-autoload)
46+
* [auto-complete](http://auto-complete.org/)
47+
* ...
48+
49+
# Installation
50+
This package is not yet available in a package archive. To install it from source:
51+
52+
* clone this repository
53+
* run `make dist` to generate the parser and the autoload definitions
54+
* run `make test` to ensure everything works as intended
55+
56+
Then add semantic-php to your load path and load the autoload definitions:
57+
58+
```
59+
(add-to-list 'load-path "~/.emacs.d/custom/semantic-php")
60+
(load "~/.emacs.d/custom/semantic-php/loaddefs.el")
61+
```
62+
63+
Now when you enable semantic-mode in a php-mode buffer, semantic-php is automatically loaded.
64+
65+
# Related projects
66+
Several people have been working on similar projects, I'll list them in a nutshell.
67+
68+
* [wisent-php](http://sourceforge.net/p/cedet/git/ci/master/tree/contrib/wisent-php.el) is included in CEDET as a contributed package. It is not shipped wit Emacs. You'd have to install CEDET from source and enable the contrib packages. This version of wisent-php provides a PHP5-ish parser and does not implement the semantic API (so, limited context analysis). The parser is a modified copy of the wisent java parser. Don't use this.
69+
70+
* Steven Rémot [forked CEDET](https://bitbucket.org/stevenremot/cedet/) to improve on wisent-php and make better use of use-statements. See ede-php-autoload below.
71+
72+
* Steven Rémot also created [ede-php-autoload](https://github.com/stevenremot/ede-php-autoload) which is basically a composer.json parser that can find a file defining a given type name. It can be used in an unlimited number of ways, for example:
73+
74+
* Andrea Tursos [xref implementation](https://github.com/ejmr/php-mode/issues/256#issuecomment-114227890): Emacs 25 drops `find-tag` in favor of `xref`. This xref implementation uses ede-php-autoload to find the files defining a given tag. Not based on semantic.
75+
76+
* There's a version of [EDEP](https://github.com/jorissteyn/edep/tree/multiple-db-backends) that works with ede-php-autoload: It works. But don't use it.
77+
78+
* [EDEP](https://github.com/jorissteyn/edep) is a precursor to this repository. It does not implement the semantic API very well, but instead uses some tricks to allow source code navigation using [PHPTAGS](https://github.com/jorissteyn/phptags). As a result, navigation works well but context sensitive completion does not. The current master branches of the two repositories work well together. There will be no further development on EDEP.
79+
80+
# Configuration snippets
81+
You might also be interested in configuring auto-complete mode with semantic completions:
82+
83+
```
84+
(require 'auto-complete-config)
85+
(setq-default ac-sources '(ac-source-semantic))
86+
```
87+
88+
And to automatically enable semantic-mode in all php-mode buffers:
89+
90+
```
91+
(add-hook 'php-mode-hook #'semantic-mode)
92+
```
93+
94+
To use ede-php-autoload, check the projects readme. For example:
95+
96+
```
97+
(require 'ede)
98+
(global-ede-mode t)
99+
100+
(add-to-list 'load-path "~/.emacs.d/custom/ede-php-autoload")
101+
(require 'ede-php-autoload-mode)
102+
(add-hook 'php-mode-hook #'ede-php-autoload-mode)
103+
(ede-php-autoload-project "Symfony" :file "/path/to/project/using/composer/composer.json")
104+
```
105+
106+
For projects using ZF1-style require/include statements, use ede-cpp-root-project until ede-php-autoload can handle that as well:
107+
108+
```
109+
(ede-cpp-root-project "ZF1"
110+
:file "/path/to/old/school/project/composer.json"
111+
:include-path '("/library")
112+
:system-include-path '("/usr/share/php"))
113+
```
114+
115+
Note that the :file attribute in both ede projects need to point to an existing file, the file is not used in any way except to deduce the project root directory.
116+
117+
# Tests and utilities
118+
* Run `make test` in the edep source directory to invoke the test suite.
119+
* Run `make autoload` to generate the autoload definitions.
120+
* Run `make parser-create` to regenerate the parser from the wisent grammar.
121+
* Run `make parser-test PARSE_PATH=/path/to/lots/of/source/files` to feed arbitrary source files to the wisent parser.
122+
* Run `make compile` byte-compile the lisp source files.
123+
124+
# License
125+
Copyright 2014-2015 Joris Steyn
126+
127+
semantic-php is not part of GNU Emacs.
128+
129+
This file is free software; you can redistribute it and/or
130+
modify it under the terms of the GNU General Public License
131+
as published by the Free Software Foundation; either version 3
132+
of the License, or (at your option) any later version.
133+
134+
This file is distributed in the hope that it will be useful,
135+
but WITHOUT ANY WARRANTY; without even the implied warranty of
136+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
137+
GNU General Public License for more details.
138+
139+
You should have received a copy of the GNU General Public License
140+
along with this file; if not, write to the Free Software
141+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
142+
02110-1301, USA.
143+

0 commit comments

Comments
 (0)