Java Doc for Syntax.java in  » IDE-Netbeans » editor » org » netbeans » editor » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » editor » org.netbeans.editor 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.netbeans.editor.Syntax

All known Subclasses:   org.netbeans.editor.ext.plain.PlainSyntax,  org.netbeans.editor.ext.MultiSyntax,
Syntax
public class Syntax (Code)
Lexical analyzer that works on a given text buffer. It allows to sequentially parse a given character buffer by calling nextToken() that returns the token-ids. After the token is found by calling the nextToken method, the getTokenOffset() method can be used to get the starting offset of the current token in the buffer. The getTokenLength() gives the length of the current token. The heart of the analyzer is the parseToken() method which parses the text and returns the token-id of the last token found. The parseToken() method is called from the nextToken(). It operates with two important variables. The offset variable identifies the currently scanned character in the buffer. The tokenOffset is the begining of the current token. The state variable that identifies the current internal state of the analyzer is set accordingly when the characters are parsed. If the parseToken() recognizes a token, it returns its ID and the tokenOffset is its begining in the buffer and offset - tokenOffset is its length. When the token is processed the value of tokenOffset is set to be the same as current value of the offset and the parsing continues. Internal states are the integer constants used internally by analyzer. They are assigned to the state variable to express that the analyzer has moved from one state to another. They are usually numbered starting from zero but they don't have to. The only reserved value is -1 which is reserved for the INIT state - the initial internal state of the analyzer. There is also the support for defining the persistent info about the current state of the analyzer. This info can be later used to restore the parsing from some particular state instead of parsing from the begining of the buffer. This feature is very useful if there are the modifications performed in the document. The info is stored in the StateInfo interface with the BaseStateInfo as the basic implementation. It enables to get and set the two important values from the persistent point of view. The first one is the value of the state variable. The other one is the difference offset - tokenOffset which is called pre-scan. The particular analyzer can define additional values important for the persistent storage. The createStateInfo() can be overriden to create custom state-info and loadState() and storeState() can be overriden to get/set the additional values. The load() method sets the buffer to be parsed. There is a special parameter in the load() method called position that allows a relation of the character buffer passed to the load() method and the position of the buffer's data in the document. For this extended functionality the document must be passed to the constructor of the lexical analyzer at some level.
author:
   Miloslav Metelka
version:
   1.00

Inner Class :public interface StateInfo
Inner Class :public static class BaseStateInfo implements StateInfo

Field Summary
final public static  intDIFFERENT_STATE
    
final public static  intEQUAL_STATE
    
final public static  intINIT
    
protected  charbuffer
    
protected  booleanlastBuffer
     Setting this flag to true means that there are currently no more buffers available so that analyzer should return all the tokens including those whose successful scanning would be otherwise left for later when the next buffer will be available.
protected  intoffset
    
protected  intstate
     Internal state of the lexical analyzer.
protected  intstopOffset
     On which offset in the buffer scanning should stop.
protected  intstopPosition
     The position in the document that logically corresponds to the stopOffset value.
protected  TokenIDsupposedTokenID
     This variable can be populated by the parseToken() method in case the user types an errorneous construction but it's clear what correct token he meant to write. For example if the user writes a single '0x' it's an errorneous construct but it's clear that the user wants to enter the hexa-number.
protected  TokenContextPathtokenContextPath
     Path from which the found token-id comes from. The TokenContext.getContextPath() can be used to get the path.
protected  inttokenLength
    
protected  inttokenOffset
    


Method Summary
public  intcompareState(StateInfo stateInfo)
    
public  StateInfocreateStateInfo()
    
public  char[]getBuffer()
    
public  intgetOffset()
    
public  intgetPreScan()
     Get the pre-scan which is a number of characters between offset and tokenOffset.
public  StringgetStateName(int stateNumber)
     Get state name as string.
public  TokenIDgetSupposedTokenID()
    
public  TokenContextPathgetTokenContextPath()
     Get the token-context-path of the returned token.
public  intgetTokenLength()
     Get length of token in scanned buffer.
public  intgetTokenOffset()
     Get start of token in scanned buffer.
public  voidload(StateInfo stateInfo, char buffer, int offset, int len, boolean lastBuffer, int stopPosition)
     Load the state from syntax mark into analyzer.
public  voidloadInitState()
     Initialize the analyzer when scanning from the begining of the document or when the state stored in syntax mark is null for some reason or to explicitly reset the analyzer to the initial state.
public  voidloadState(StateInfo stateInfo)
     Load valid mark state into the analyzer.
public  TokenIDnextToken()
     Function that should be called externally to scan the text.
protected  TokenIDparseToken()
     This is core function of analyzer and it returns either the token-id or null to indicate that the end of buffer was found. The function scans the active character and does one or more of the following actions: 1.
public  voidrelocate(char buffer, int offset, int len, boolean lastBuffer, int stopPosition)
     Relocate scanning to another buffer. This is used to continue scanning after previously reported EOT.
public  voidreset()
    
public  voidstoreState(StateInfo stateInfo)
     Store state of this analyzer into given mark state.
public  StringtoString()
    

Field Detail
DIFFERENT_STATE
final public static int DIFFERENT_STATE(Code)
Is the state of analyzer different from given state info?



EQUAL_STATE
final public static int EQUAL_STATE(Code)
Is the state of analyzer equal to a given state info?



INIT
final public static int INIT(Code)
Initial internal state of the analyzer



buffer
protected char buffer(Code)
Text buffer to scan



lastBuffer
protected boolean lastBuffer(Code)
Setting this flag to true means that there are currently no more buffers available so that analyzer should return all the tokens including those whose successful scanning would be otherwise left for later when the next buffer will be available. Setting this flag to true ensures that all the characters in the current buffer will be processed. The lexical analyzer should on one hand process all the characters but on the other hand it should "save" its context. For example if the scanner finds the unclosed comment at the end of the buffer it should return the comment token but stay in the "being in comment" internal state.



offset
protected int offset(Code)
Current offset in the buffer



state
protected int state(Code)
Internal state of the lexical analyzer. At the begining it's set to INIT value but it is changed by parseToken() as the characters are processed one by one.



stopOffset
protected int stopOffset(Code)
On which offset in the buffer scanning should stop.



stopPosition
protected int stopPosition(Code)
The position in the document that logically corresponds to the stopOffset value. If there's no relation to the document, it's -1. The reason why the relation to the document's data is expressed through the stopOffset to stopPosition relation is because the stopOffset is the only offset that doesn't change rapidly in the operation of the lexical analyzer.



supposedTokenID
protected TokenID supposedTokenID(Code)
This variable can be populated by the parseToken() method in case the user types an errorneous construction but it's clear what correct token he meant to write. For example if the user writes a single '0x' it's an errorneous construct but it's clear that the user wants to enter the hexa-number. In this situation the parseToken() should report error, but it should also set the supposedTokenID to the hexa-number token. This information is used while drawing the text. If the caret stand inside or around such token, it calls the getSupposedTokenID() after calling the nextToken() and if it's non-null it uses it instead of the original token.



tokenContextPath
protected TokenContextPath tokenContextPath(Code)
Path from which the found token-id comes from. The TokenContext.getContextPath() can be used to get the path. If the lexical analyzer doesn't use any children token-contexts it can assign the path in the constructor.



tokenLength
protected int tokenLength(Code)
This variable is the length of the token that was found



tokenOffset
protected int tokenOffset(Code)
Offset holding the begining of the current token





Method Detail
compareState
public int compareState(StateInfo stateInfo)(Code)
Compare state of this analyzer to given state info



createStateInfo
public StateInfo createStateInfo()(Code)
Create state info appropriate for particular analyzer



getBuffer
public char[] getBuffer()(Code)
Get the current buffer



getOffset
public int getOffset()(Code)
Get the current scanning offset



getPreScan
public int getPreScan()(Code)
Get the pre-scan which is a number of characters between offset and tokenOffset. If there's no more characters in the current buffer, the analyzer returns EOT, but it can be in a state when there are already some characters parsed at the end of the current buffer but the token is still incomplete and it cannot be returned yet. The pre-scan value helps to determine how many characters from the end of the current buffer should be present at the begining of the next buffer so that the current incomplete token can be returned as the first token when parsing the next buffer.



getStateName
public String getStateName(int stateNumber)(Code)
Get state name as string. It can be used for debugging purposes by developer of new syntax analyzer. The states that this function recognizes can include all constants used in analyzer so that it can be used everywhere in analyzer to convert numbers to more practical strings.



getSupposedTokenID
public TokenID getSupposedTokenID()(Code)



getTokenContextPath
public TokenContextPath getTokenContextPath()(Code)
Get the token-context-path of the returned token.



getTokenLength
public int getTokenLength()(Code)
Get length of token in scanned buffer.



getTokenOffset
public int getTokenOffset()(Code)
Get start of token in scanned buffer.



load
public void load(StateInfo stateInfo, char buffer, int offset, int len, boolean lastBuffer, int stopPosition)(Code)
Load the state from syntax mark into analyzer. This method is used when
Parameters:
  stateInfo - info about the state of the lexical analyzer to load.It can be null to indicate there's no previous state so the analyzerstarts from its initial state.
Parameters:
  buffer - buffer that will be scanned
Parameters:
  offset - offset of the first character that will be scanned
Parameters:
  len - length of the area to be scanned
Parameters:
  lastBuffer - whether this is the last buffer in the document. All the tokenswill be returned including the last possibly incomplete one. If the datacome from the document, the simple rule for this parameteris (doc.getLength() == stop-position) where stop-positionis the position corresponding to the (offset + len) in the bufferthat comes from the document data.
Parameters:
  stopPosition - position in the document that corresponds to (offset + len) offsetin the provided buffer. It has only sense if the data in the buffer come from the document.It helps in writing the advanced analyzers that need to interact with some other datain the document than only those provided in the character buffer.If there is no relation to the document data, the stopPosition parametermust be filled with -1 which means an invalid value.The stop-position is passed (instead of start-position) because it doesn'tchange through the analyzer operation. It corresponds to the stopOffsetthat also doesn't change through the analyzer operation so anybuffer-offset can be transferred to position by computingstopPosition + buffer-offset - stopOffsetwhere stopOffset is the instance variable that is assignedto offset + len in the body of relocate().



loadInitState
public void loadInitState()(Code)
Initialize the analyzer when scanning from the begining of the document or when the state stored in syntax mark is null for some reason or to explicitly reset the analyzer to the initial state. The offsets must not be touched by this method.



loadState
public void loadState(StateInfo stateInfo)(Code)
Load valid mark state into the analyzer. Offsets are already initialized when this method is called. This method must get the state from the mark and set it to the analyzer. Then it must decrease tokenOffset by the preScan stored in the mark state.
Parameters:
  markState - mark state to be loaded into syntax. It must be non-null value.



nextToken
public TokenID nextToken()(Code)
Function that should be called externally to scan the text. It manages the call to parseToken() and cares about the proper setting of the offsets. It can be extended to support any custom debugging required.



parseToken
protected TokenID parseToken()(Code)
This is core function of analyzer and it returns either the token-id or null to indicate that the end of buffer was found. The function scans the active character and does one or more of the following actions: 1. change internal analyzer state 2. set the token-context-path and return token-id 3. adjust current position to signal different end of token; the character that offset points to is not included in the token



relocate
public void relocate(char buffer, int offset, int len, boolean lastBuffer, int stopPosition)(Code)
Relocate scanning to another buffer. This is used to continue scanning after previously reported EOT. Relocation delta between current offset and the requested offset is computed and all the offsets are relocated. If there's a non-zero preScan in the analyzer, it is a caller's responsibility to provide all the preScan characters in the relocation buffer.
Parameters:
  buffer - next buffer where the scan will continue.
Parameters:
  offset - offset where the scan will continue.It's not decremented by the current preScan.
Parameters:
  len - length of the area to be scanned.It's not extended by the current preScan.
Parameters:
  lastBuffer - whether this is the last buffer in the document. All the tokenswill be returned including the last possibly incomplete one. If the datacome from the document, the simple rule for this parameteris (doc.getLength() == stop-position) where stop-positionis the position corresponding to the (offset + len) in the bufferthat comes from the document data.
Parameters:
  stopPosition - position in the document that corresponds to (offset + len) offsetin the provided buffer. It has only sense if the data in the buffer come from the document.It helps in writing the advanced analyzers that need to interact with some other datain the document than only those provided in the character buffer.If there is no relation to the document data, the stopPosition parametermust be filled with -1 which means an invalid value.The stop-position is passed (instead of start-position) because it doesn'tchange through the analyzer operation. It corresponds to the stopOffsetthat also doesn't change through the analyzer operation so anybuffer-offset can be transferred to position by computingstopPosition + buffer-offset - stopOffsetwhere stopOffset is the instance variable that is assignedto offset + len in the body of relocate().



reset
public void reset()(Code)



storeState
public void storeState(StateInfo stateInfo)(Code)
Store state of this analyzer into given mark state.



toString
public String toString()(Code)
Syntax information as String



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.