use of org.develnext.jphp.core.tokenizer.token.expr.CommaToken in project jphp by jphp-compiler.
the class FunctionGenerator method processArgument.
@SuppressWarnings("unchecked")
protected ArgumentStmtToken processArgument(ListIterator<Token> iterator) {
boolean isReference = false;
boolean isVariadic = false;
VariableExprToken variable = null;
ExprStmtToken value = null;
Token next = nextToken(iterator);
if (next instanceof CommaToken || isClosedBrace(next, BraceExprToken.Kind.SIMPLE))
return null;
NameToken hintTypeClass = null;
HintType hintType = null;
boolean optional = false;
if (next instanceof ValueIfElseToken) {
optional = true;
next = nextToken(iterator);
}
if (next instanceof SelfExprToken) {
if (analyzer.getClazz() == null) {
unexpectedToken(next);
}
if (!analyzer.getClazz().isTrait()) {
next = analyzer.getClazz().getName();
hintTypeClass = analyzer.getRealName((NameToken) next);
} else {
hintType = HintType.SELF;
}
next = nextToken(iterator);
} else if (next instanceof NameToken) {
String word = ((NameToken) next).getName().toLowerCase();
if (scalarTypeHints.contains(word)) {
hintType = HintType.of(word);
} else if (disallowScalarTypeHints.contains(word)) {
unexpectedToken(next, "valid type");
} else {
hintType = jphp_scalarTypeHints.contains(word) ? null : HintType.of(word);
if (hintType == null)
hintTypeClass = analyzer.getRealName((NameToken) next);
}
next = nextToken(iterator);
}
if (next instanceof AmpersandRefToken) {
isReference = true;
next = nextToken(iterator);
}
if (next instanceof ArgumentUnpackExprToken) {
isVariadic = true;
next = nextToken(iterator);
}
if (next instanceof VariableExprToken) {
variable = (VariableExprToken) next;
} else
unexpectedToken(next);
next = nextToken(iterator);
if (next instanceof AssignExprToken) {
if (isVariadic) {
unexpectedToken(next);
}
value = analyzer.generator(SimpleExprGenerator.class).getToken(nextToken(iterator), iterator, true, BraceExprToken.Kind.SIMPLE);
} else {
if (next instanceof CommaToken || isClosedBrace(next, BraceExprToken.Kind.SIMPLE)) {
if (next instanceof BraceExprToken) {
iterator.previous();
} else {
if (isVariadic) {
unexpectedToken(next);
}
}
} else
unexpectedToken(next);
}
ArgumentStmtToken argument = new ArgumentStmtToken(variable.getMeta());
argument.setName(variable);
argument.setHintType(hintType);
argument.setHintTypeClass(hintTypeClass);
argument.setReference(isReference);
argument.setVariadic(isVariadic);
argument.setValue(value);
argument.setOptional(optional);
if (argument.isReference() && argument.getValue() != null)
analyzer.getFunction().variable(argument.getName()).setUsed(true);
return argument;
}
use of org.develnext.jphp.core.tokenizer.token.expr.CommaToken in project jphp by jphp-compiler.
the class TokenizerTest method testBraces.
@Test
public void testBraces() throws IOException {
Tokenizer tokenizer = new Tokenizer(new Context(" :: ->foobar('a', 1, 3.0);"));
assertTrue(tokenizer.nextToken() instanceof StaticAccessExprToken);
assertTrue(tokenizer.nextToken() instanceof DynamicAccessExprToken);
assertTrue(tokenizer.nextToken() instanceof NameToken);
assertTrue(tokenizer.nextToken() instanceof BraceExprToken);
assertTrue(tokenizer.nextToken() instanceof StringExprToken);
assertTrue(tokenizer.nextToken() instanceof CommaToken);
assertTrue(tokenizer.nextToken() instanceof IntegerExprToken);
assertTrue(tokenizer.nextToken() instanceof CommaToken);
assertTrue(tokenizer.nextToken() instanceof DoubleExprToken);
assertTrue(tokenizer.nextToken() instanceof BraceExprToken);
assertTrue(tokenizer.nextToken() instanceof SemicolonToken);
}
use of org.develnext.jphp.core.tokenizer.token.expr.CommaToken in project jphp by jphp-compiler.
the class ClassGenerator method processProperty.
protected List<ClassVarStmtToken> processProperty(ClassStmtToken clazz, VariableExprToken current, List<Token> modifiers, ListIterator<Token> iterator) {
Token next = current;
Token prev = null;
Set<VariableExprToken> variables = new LinkedHashSet<VariableExprToken>();
List<ExprStmtToken> initValues = new ArrayList<>();
ExprStmtToken initValue = null;
List<ClassVarStmtToken> result = new ArrayList<ClassVarStmtToken>();
Modifier modifier = Modifier.PUBLIC;
boolean isStatic = false;
for (Token token : modifiers) {
if (token instanceof PrivateStmtToken)
modifier = Modifier.PRIVATE;
else if (token instanceof ProtectedStmtToken)
modifier = Modifier.PROTECTED;
else if (token instanceof StaticExprToken)
isStatic = true;
}
do {
if (next instanceof VariableExprToken) {
if (!variables.add((VariableExprToken) next)) {
throw new ParseException(Messages.ERR_IDENTIFIER_X_ALREADY_USED.fetch(next.getWord()), next.toTraceInfo(analyzer.getContext()));
}
initValues.add(null);
} else if (next instanceof CommaToken) {
if (!(prev instanceof VariableExprToken))
unexpectedToken(next);
} else if (next instanceof AssignExprToken) {
if (!(prev instanceof VariableExprToken))
unexpectedToken(next);
initValue = analyzer.generator(SimpleExprGenerator.class).getToken(nextToken(iterator), iterator, Separator.COMMA_OR_SEMICOLON, null);
initValues.set(initValues.size() - 1, initValue);
if (iterator.hasPrevious() && isBreak(iterator.previous())) {
iterator.next();
break;
}
if (iterator.hasNext()) {
iterator.next();
}
// break;
} else if (next instanceof SemicolonToken) {
if (!(prev instanceof VariableExprToken))
unexpectedToken(next);
break;
}
prev = next;
next = nextToken(iterator);
} while (true);
int i = 0;
for (VariableExprToken variable : variables) {
ClassVarStmtToken classVar = new ClassVarStmtToken(variable.getMeta());
classVar.setModifier(modifier);
classVar.setStatic(isStatic);
classVar.setValue(initValues.get(i));
classVar.setVariable(variable);
classVar.setClazz(clazz);
result.add(classVar);
i++;
}
return result;
}
use of org.develnext.jphp.core.tokenizer.token.expr.CommaToken in project jphp by jphp-compiler.
the class ClassGenerator method processImplements.
protected void processImplements(ClassStmtToken result, ListIterator<Token> iterator) {
checkUnexpectedEnd(iterator);
Token token = iterator.next();
if (token instanceof ImplementsStmtToken) {
if (result.isTrait())
unexpectedToken(token);
if (result.isInterface())
unexpectedToken(token, "extends");
_processImplements(token, result, iterator);
/*
ImplementsStmtToken implement = new ImplementsStmtToken(token.getMeta());
Token prev = null;
List<FulledNameToken> names = new ArrayList<FulledNameToken>();
do {
token = nextToken(iterator);
if (token instanceof NameToken){
names.add(analyzer.getRealName((NameToken)token));
} else if (token instanceof CommaToken){
if (!(prev instanceof NameToken))
unexpectedToken(token);
} else if (isOpenedBrace(token, BraceExprToken.Kind.BLOCK)){
iterator.previous();
break;
} else
unexpectedToken(token);
prev = token;
} while (true);
implement.setNames(names);
result.setImplement(implement);*/
} else
iterator.previous();
}
use of org.develnext.jphp.core.tokenizer.token.expr.CommaToken in project jphp by jphp-compiler.
the class ConstGenerator method getToken.
/*@SuppressWarnings("unchecked")
protected void processBody(ConstStmtToken result, ListIterator<Token> iterator){
Token current = nextToken(iterator);
if (!(current instanceof AssignExprToken))
unexpectedToken(current, "=");
ExprStmtToken value = analyzer.generator(SimpleExprGenerator.class).getToken(nextToken(iterator), iterator);
if (value == null)
unexpectedToken(nextToken(iterator));
result.setValue(value);
}*/
@Override
@SuppressWarnings("unchecked")
public ConstStmtToken getToken(Token current, ListIterator<Token> iterator) {
if (current instanceof ConstStmtToken) {
ConstStmtToken result = (ConstStmtToken) current;
Token prev = null;
if (analyzer.getClazz() == null)
result.setNamespace(analyzer.getNamespace());
while (true) {
Token next = analyzer.getClazz() == null ? nextToken(iterator) : nextTokenSensitive(iterator, ClassStmtToken.class);
if (next instanceof NameToken) {
if (next instanceof FulledNameToken && !((FulledNameToken) next).isProcessed(NamespaceUseStmtToken.UseType.CONSTANT))
unexpectedToken(next, TokenType.T_STRING);
Token token = nextToken(iterator);
if (!(token instanceof AssignExprToken))
unexpectedToken(token, "=");
ExprStmtToken value = analyzer.generator(SimpleExprGenerator.class).getToken(nextToken(iterator), iterator, Separator.COMMA_OR_SEMICOLON, null);
if (!isBreak(iterator.previous())) {
iterator.next();
}
if (value == null)
unexpectedToken(iterator.previous());
result.add((NameToken) next, value);
} else if (next instanceof CommaToken) {
if (prev instanceof CommaToken)
unexpectedToken(next);
prev = next;
} else if (isBreak(next)) {
break;
} else
unexpectedToken(next, TokenType.T_STRING);
}
return result;
}
return null;
}
Aggregations