public interface TokenFactory
A factory for producing all the objects under the control of the token
module. These includes instances of the following types (and their subtypes):
-
Method Summary
Modifier and TypeMethodDescriptioncharacterToken(CivlcToken token) executionCharacter(ExecutionCharacter.CharacterKind kind, int codePoint, char[] characters) getCivlcTokenSourceByTokens(List<? extends org.antlr.runtime.Token> tokens, Formation formation) creates a CivlC Token Source based on a give list of tokens (not necessarily CivlC token).getEmptyTokenSubsequence(CivlcTokenSource originalSource) getTokenSubsequence(CivlcTokenSource fullSource, CivlcToken startToken, CivlcToken stopToken) join(Source source, CivlcToken token) Computes a minimalSourcecontaining the given source and token.Computes a minimalSourcecontaining the two given sources.newBuiltinMacroExpansion(CivlcToken macroToken) Returns a new built-in macro expansion formation object.newCivlcToken(int type, String text, Formation formation, CivlcToken.TokenVocabulary tokenVocab) newCivlcToken(org.antlr.runtime.CharStream input, int type, int channel, int start, int stop, Formation formation, int line, int charPositionInLine, CivlcToken.TokenVocabulary tokenVocab) newCivlcToken(org.antlr.runtime.Token token, Formation formation, CivlcToken.TokenVocabulary tokenVocab) newConcatenation(List<CivlcToken> tokens) A formation of a token by either (1) concatenating 0 or more tokens using the preprocessor "##" operator, or (2) concatenating 1 or more string literal tokens immediately after preprocessing.newFunctionMacro(org.antlr.runtime.tree.Tree definitionNode, SourceFile file) newInclusion(SourceFile file) Inclusion record for original source file.newInclusion(SourceFile file, CivlcToken includeToken) newMacroExpansion(CivlcToken startToken, Macro macro, int index) Returns a standard macro expansion formation object.newObjectMacro(org.antlr.runtime.tree.Tree definitionNode, SourceFile file) newSource(CivlcToken token) Returns aSourceconsisting of a singleToken.newSource(CivlcToken first, CivlcToken last) newStringification(FunctionMacro macro, int index, List<CivlcToken> argument) Formation of a string literal token through the use of the preprocessor "#" operator during the application of a function-like macro.newStringToken(CivlcToken token) newStringToken(List<CivlcToken> tokens) Constructs a new string literal token (instance ofStringToken) by concatenating a list of string literal tokens.newSyntaxException(UnsourcedException e, CivlcToken token) newSyntaxException(UnsourcedException e, Source source) newSyntaxException(String message, CivlcToken token) newSyntaxException(String message, Source source) newSystemFormation(String identifier) Creates a new formation which represents some code added by the system itself, as opposed to code that emanated from an actual source file.newTransformFormation(String transformerName, String method) newUnsourcedException(String message)
-
Method Details
-
newMacroExpansion
Returns a standard macro expansion formation object. This is a formation that represents a token created through the process of macro expansion.- Parameters:
startToken- the token within the macro application expression that led to the formation of the new token; this could be either the macro name itself or a token from one of the argumentsmacro- theMacroobject given an abstraction represnetation of the macroindex- the index of the replacement token (numbered from 0) in the macro replacement list that led to the final token- Returns:
- a new formation incorporating the specified values
-
newBuiltinMacroExpansion
Returns a new built-in macro expansion formation object. This represents a token formed by expanding one of the predefined object macros such as "__FILE__" or "__LINE__".- Parameters:
macroToken- the original token, such as "__FILE__" or "__LINE__" that is being expanded- Returns:
- a new Formation object representing the expansion of such a macro
-
newStringification
Formation of a string literal token through the use of the preprocessor "#" operator during the application of a function-like macro.- Parameters:
macro- the function-like macro being appliedindex- the index of the replacement token (numbered from 0) in the macro replacement list involved in the formation of the new token; this replacement token will necessarily be a parameter immediately following a "#" tokenargument- the sequence of non-whitespace tokens comprising the argument in the macro invocation- Returns:
- a new formation incorporating specified values
-
newConcatenation
A formation of a token by either (1) concatenating 0 or more tokens using the preprocessor "##" operator, or (2) concatenating 1 or more string literal tokens immediately after preprocessing.- Parameters:
tokens- list of tokens to concatenate; should not include whitespace
-
newInclusion
Inclusion record for original source file.- Parameters:
file- the file which was included, which should be the original source file (the root of the inclusion tree)- Returns:
- a new inclusion record
-
newInclusion
-
newSystemFormation
Creates a new formation which represents some code added by the system itself, as opposed to code that emanated from an actual source file. The identifier should be a short string indicating what part of the system created the code. Examples: "The CIVL-MPI Transformer". The identifier will be used to form a "fake"File, which will be used to form aSourceFile, and that is what will be returned by the formation'sFormation.getLastFile()method.- Parameters:
identifier- short string indicating what part of the system created this code; used in messages- Returns:
- a new system formation object
-
newTransformFormation
-
newCivlcToken
CivlcToken newCivlcToken(org.antlr.runtime.Token token, Formation formation, CivlcToken.TokenVocabulary tokenVocab) -
newCivlcToken
CivlcToken newCivlcToken(int type, String text, Formation formation, CivlcToken.TokenVocabulary tokenVocab) -
newCivlcToken
CivlcToken newCivlcToken(org.antlr.runtime.CharStream input, int type, int channel, int start, int stop, Formation formation, int line, int charPositionInLine, CivlcToken.TokenVocabulary tokenVocab) - Parameters:
input- the character stream from which this token was formedtype- the type of the new token, which is a unique integer ID assigned to each category of token by the lexer, e.g., IDENTIFIERchannel- all tokens go to the parser (unless skip() is called in that rule) on a particular "channel". The parser tunes to a particular channel so that whitespace etc... can go to the parser on a "hidden" channel.start- the char position into the input buffer where this token startsstop- the char position into the input buffer where this token stopsformation- the object specifying the complete history on how this token came to existline- the line number on which the token occurscharPositionInLine- the index of the first character of the token in the line in which it occurs. Indexes start at 0 for first character in line.tokenVocab- the lexical vocabulary used bythisinvalid input: '<'- Returns:
- a new instance of
CivlcTokenwith fields as specified above
-
executionCharacter
ExecutionCharacter executionCharacter(ExecutionCharacter.CharacterKind kind, int codePoint, char[] characters) -
characterToken
- Throws:
SyntaxException
-
newStringToken
- Throws:
SyntaxException
-
newStringToken
Constructs a new string literal token (instance ofStringToken) by concatenating a list of string literal tokens. According to the C Standard, after preprocessing, adjacent string literal tokens are concatenated. (They may be separated by white space, which is ignored.)- Parameters:
tokens- sequence of non-null string literal tokens- Returns:
- a single token obtained by concatenating the given ones
- Throws:
SyntaxException- if the new string cannot be formed for some reason
-
newSource
Returns aSourceconsisting of a singleToken.- Parameters:
token- a non-nullToken- Returns:
- a
Sourceconsisting of the single given token
-
newSource
- Parameters:
first- a non-nullTokenlast- a non-nullTokenfrom the same token sequence asfirst- Returns:
- a
Sourcecomprising allTokens fromfirsttolast, inclusive
-
join
Computes a minimalSourcecontaining the given source and token. The given source and token must come from the same token sequence. This is useful when you want to increase a source by one token.- Parameters:
source- a non-nullSourcetoken- a non-nullTokenfrom the same token sequence assource- Returns:
- a minimal
Sourcecontaining the given source and token
-
join
Computes a minimalSourcecontaining the two given sources. -
newSyntaxException
-
newSyntaxException
-
newSyntaxException
-
newSyntaxException
-
newUnsourcedException
-
newObjectMacro
-
newFunctionMacro
-
getTokenSubsequence
CivlcTokenSequence getTokenSubsequence(CivlcTokenSource fullSource, CivlcToken startToken, CivlcToken stopToken) -
getEmptyTokenSubsequence
-
getCivlcTokenSourceByTokens
CivlcTokenSource getCivlcTokenSourceByTokens(List<? extends org.antlr.runtime.Token> tokens, Formation formation) creates a CivlC Token Source based on a give list of tokens (not necessarily CivlC token). All given tokens will be transformed to CivlC tokens if they are not CivlC tokens, using the given formation.- Parameters:
tokens- the list of tokensformation- the formation to be used when transforming the given tokens- Returns:
- a CivlC token source wrapping the given list of tokens
-
newFileIndexer
FileIndexer newFileIndexer()
-