public class QQ
extends java.lang.Object
To use the class, invoke one of the parseT
methods to create a
Node
of type T
.
Each parseT
method takes a format string as its first argument
and some additional Object
arguments. Each pattern in the
format string is matched with its corresponding Object
.
The format string may contain the following patterns:
%s
matches String
(parsed as an identifier)
%T
matches Type
or TypeNode
%E
matches Expr
%S
matches Stmt
%D
matches ClassDecl
%M
matches ClassMember
%F
matches Formal
%LT
matches List<Type>
or List<TypeNode>
%LE
matches List<Expr>
%LS
matches List<Stmt>
%LD
matches List<ClassDecl>
%LM
matches List<ClassMember>
%LF
matches List<Formal>
For example:
Expr e; TypeNode t; Stmt s = qq.parseStmt("%T %s = new %T(%E);", t, "tmp", t, e);
Modifier and Type | Field and Description |
---|---|
protected static int |
DECL |
protected static int |
EXPR |
protected ExtensionInfo |
ext |
protected static int |
FILE |
protected static int |
MEMB |
protected Position |
pos |
protected static int |
STMT |
protected static int |
TYPE |
Constructor and Description |
---|
QQ(ExtensionInfo ext)
Create a new quasiquoter to create AST nodes of the given
language extension.
|
QQ(ExtensionInfo ext,
Position pos)
Create a new quasiquoter to create AST nodes of the given
language extension, using
pos for the position
of the nodes created. |
Modifier and Type | Method and Description |
---|---|
protected Lexer |
lexer(java.lang.String fmt,
Position pos,
java.lang.Object... subst)
Create a lexer that performs the substitutions in
subst . |
protected Node |
parse(int kind,
java.lang.String fmt,
java.lang.Object... subst)
Parse a string into an AST node of the given type,
applying substitutions.
|
ClassDecl |
parseDecl(java.lang.String fmt,
java.util.List<?> subst)
Parse a string into a
ClassDecl AST node,
applying substitutions. |
ClassDecl |
parseDecl(java.lang.String fmt,
java.lang.Object... os)
Parse a string into a
ClassDecl AST node,
applying substitutions. |
Expr |
parseExpr(java.lang.String fmt,
java.util.List<?> subst)
Parse a string into a
Expr AST node,
applying substitutions. |
Expr |
parseExpr(java.lang.String fmt,
java.lang.Object... os)
Parse a string into a
Expr AST node,
applying substitutions. |
SourceFile |
parseFile(java.lang.String fmt,
java.util.List<?> subst)
Parse a string into a
SourceFile AST node,
applying substitutions. |
SourceFile |
parseFile(java.lang.String fmt,
java.lang.Object... os)
Parse a string into a
SourceFile AST node,
applying substitutions. |
ClassMember |
parseMember(java.lang.String fmt,
java.util.List<?> subst)
Parse a string into a
ClassMember AST node,
applying substitutions. |
ClassMember |
parseMember(java.lang.String fmt,
java.lang.Object... os)
Parse a string into a
ClassMember AST node,
applying substitutions. |
protected QQParser |
parser(Lexer lexer,
TypeSystem ts,
NodeFactory nf,
ErrorQueue eq)
Create a quasiquoting parser.
|
Stmt |
parseStmt(java.lang.String fmt,
java.util.List<?> subst)
Parse a string into a
Stmt AST node,
applying substitutions. |
Stmt |
parseStmt(java.lang.String fmt,
java.lang.Object... os)
Parse a string into a
Stmt AST node,
applying substitutions. |
TypeNode |
parseType(java.lang.String fmt,
java.util.List<?> subst)
Parse a string into a
TypeNode AST node,
applying substitutions. |
TypeNode |
parseType(java.lang.String fmt,
java.lang.Object... os)
Parse a string into a
TypeNode AST node,
applying substitutions. |
protected Position |
type_position(TypeObject t)
Return a position for a type object.
|
protected ExtensionInfo ext
protected Position pos
protected static final int EXPR
protected static final int STMT
protected static final int TYPE
protected static final int MEMB
protected static final int DECL
protected static final int FILE
public QQ(ExtensionInfo ext)
public QQ(ExtensionInfo ext, Position pos)
pos
for the position
of the nodes created.public SourceFile parseFile(java.lang.String fmt, java.lang.Object... os)
SourceFile
AST node,
applying substitutions.public SourceFile parseFile(java.lang.String fmt, java.util.List<?> subst)
SourceFile
AST node,
applying substitutions.public ClassDecl parseDecl(java.lang.String fmt, java.lang.Object... os)
ClassDecl
AST node,
applying substitutions.public ClassDecl parseDecl(java.lang.String fmt, java.util.List<?> subst)
ClassDecl
AST node,
applying substitutions.public ClassMember parseMember(java.lang.String fmt, java.lang.Object... os)
ClassMember
AST node,
applying substitutions.public ClassMember parseMember(java.lang.String fmt, java.util.List<?> subst)
ClassMember
AST node,
applying substitutions.public Expr parseExpr(java.lang.String fmt, java.lang.Object... os)
Expr
AST node,
applying substitutions.public Expr parseExpr(java.lang.String fmt, java.util.List<?> subst)
Expr
AST node,
applying substitutions.public Stmt parseStmt(java.lang.String fmt, java.lang.Object... os)
Stmt
AST node,
applying substitutions.public Stmt parseStmt(java.lang.String fmt, java.util.List<?> subst)
Stmt
AST node,
applying substitutions.public TypeNode parseType(java.lang.String fmt, java.lang.Object... os)
TypeNode
AST node,
applying substitutions.public TypeNode parseType(java.lang.String fmt, java.util.List<?> subst)
TypeNode
AST node,
applying substitutions.protected Lexer lexer(java.lang.String fmt, Position pos, java.lang.Object... subst)
subst
.protected QQParser parser(Lexer lexer, TypeSystem ts, NodeFactory nf, ErrorQueue eq)
protected Position type_position(TypeObject t)
protected Node parse(int kind, java.lang.String fmt, java.lang.Object... subst)