LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-11-2006, 02:27 PM   #1
stormrider_may
Member
 
Registered: Sep 2005
Distribution: Debian
Posts: 304

Rep: Reputation: 30
Syntax highlight, how they make it?


Hi, i don't if this is the right forum to post but here we go.

I'm trying to make (actually start making) a php editor. I wanna know how can i insert all php funcions (all of them) into my editor.
For example, quanta highlights php funcions and explains it, but the programmer didn't inserted it in a "manual" way, right?
 
Old 05-11-2006, 02:33 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
don't get what you mean, but a code editor is just a text editor that has extra functionality in it.. there's no magic way anything is actually "done"... just coded to do it. you might want to possibly look at the scintilla code engine for a customizable code edit engine.
 
Old 05-11-2006, 02:56 PM   #3
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
I'd guess that the language syntax and functions are stored in a file. The program will read this file in and store the data in a data structure (array...) Then when the user starts to type a function name it will search along the array (would be good to store it in alphabetical order) and as it has a match it can display all the possible functions to allow the user to select the most suitable function. Once selected additional information can be displayed.

So you are right in that each function (syntax rule) is not manually added to the program, rather it will be in a structured file that describes the language but the program will have to read in the file and operate on the contents of the language file.
 
Old 05-11-2006, 03:05 PM   #4
stormrider_may
Member
 
Registered: Sep 2005
Distribution: Debian
Posts: 304

Original Poster
Rep: Reputation: 30
Do you know where can i find a file that contains all php functions?

Thanks for the answer.
 
Old 05-11-2006, 03:31 PM   #5
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
At least one syntax-highlighting editor, nedit, uses customizable regular expressions to detect programming language constructs. These are visible in each users' nedit.rc file. The use of regular expressions is probably a natural way to perform syntax parsing, since many language grammars are defined in terms of regular expressions in lex parsers.

--- rod.
 
Old 05-11-2006, 03:41 PM   #6
stormrider_may
Member
 
Registered: Sep 2005
Distribution: Debian
Posts: 304

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by theNbomr
At least one syntax-highlighting editor, nedit, uses customizable regular expressions to detect programming language constructs. These are visible in each users' nedit.rc file. The use of regular expressions is probably a natural way to perform syntax parsing, since many language grammars are defined in terms of regular expressions in lex parsers.

--- rod.
A friend tould me that, but my editor is especific to php, so i'm trying to insert all php functions in my program.
Does php.net offers a file where i can have all functions?

Serious, this seen to be harder than i tought it would be
 
Old 05-11-2006, 04:26 PM   #7
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Well you could try the php manual...
Appendixes > Function Index
 
Old 05-11-2006, 04:54 PM   #8
mrcheeks
Senior Member
 
Registered: Mar 2004
Location: far enough
Distribution: OS X 10.6.7
Posts: 1,690

Rep: Reputation: 52
Usually to perform syntax highlighting you use a lexer.
*You listen to the user input text and you parse it and a portion of text already typed in the editor.
*After parsing the text you create tokens which correspond to for example a function name, a variable, etc.
*When you have the tokens, you select the color to apply to tokens.
 
Old 05-11-2006, 05:40 PM   #9
AngryLlama
Member
 
Registered: Sep 2004
Location: /dev/urandom
Distribution: Gentoo
Posts: 171

Rep: Reputation: 31
VIM color codes PHP just fine. look at php.vim (usually stored is /usr/share/vim/syntax/php.vim ... Something like that

It will give you a list of all the function names. It also shows you how it handles constructs like arrays, switches, etc..

Take a look at indent/php.vim for some clues on auto-indention.

You can find documents explaining how to write these files (and conversely, how to read them). Regardless, it should be a good starting spot for program. Why are you trying to re-invent the wheel though?

Last edited by AngryLlama; 05-11-2006 at 05:41 PM.
 
Old 05-11-2006, 08:36 PM   #10
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Quote:
Originally Posted by stormrider_may
A friend tould me that, but my editor is especific to php, so i'm trying to insert all php functions in my program.
Does php.net offers a file where i can have all functions?

Serious, this seen to be harder than i tought it would be

But, the point was to do it the same way nedit does it. Use a lexical parser generator like lex (flex, in the linux world) to generate a parser to parse the source code. That will allow you to tokenize the text, and having done so, apply syntax related colors to it. You may have to perform somne level of grammatical analysis, in order to determine from context, what each token represents. When done this way, your editor can determine from the context what tokens are function names. That way, the functions you write yourself will appear in the same color code as built-in function names.

--- rod.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
vim syntax highlight fails after debian upgrade darknails Linux - Software 7 05-19-2009 04:11 AM
How to make own highlight scheme in vim? kornerr Linux - General 2 01-04-2006 08:39 PM
Emacs Syntax highlight UltraSoul Linux - Software 1 07-11-2005 09:19 AM
xterm under GNOME not syntax-highlight. yangsongx Slackware 3 03-24-2005 07:49 AM
how make emacs highlight ? black Linux - Software 2 09-29-2002 01:11 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration