repo_name stringlengths 7 104 | file_path stringlengths 13 198 | context stringlengths 67 7.15k | import_statement stringlengths 16 4.43k | code stringlengths 40 6.98k | prompt stringlengths 227 8.27k | next_line stringlengths 8 795 |
|---|---|---|---|---|---|---|
Avarel/Kaiper | Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/parslets/flow/ReturnParser.java | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/flow/ReturnExpr.java
// public class ReturnExpr extends Single {
// private final Single expr;
//
// public ReturnExpr(Position position, Single expr) {
// super(position);
// this.expr = expr;
// }
//
// public Single getExpr() {
// return expr;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// expr.ast("return", builder, indent, true);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/value/NullNode.java
// public class NullNode extends Single {
// public static final NullNode VALUE = new NullNode();
//
// private NullNode() {
// super(null);
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/lexer/TokenType.java
// public enum TokenType {
// // PAIRS
// LEFT_PAREN,
// RIGHT_PAREN,
//
// LEFT_BRACKET,
// RIGHT_BRACKET,
//
// LEFT_BRACE,
// RIGHT_BRACE,
//
// OPTIONAL_ASSIGN,
// ELVIS,
//
// // ASSIGNMENT
// ASSIGN,
//
// // TYPES
// INT,
// NUMBER,
// BOOLEAN,
// FUNCTION,
// STRING,
// ATOM,
//
// // ARITHMETIC
// PLUS,
// MINUS,
// ASTERISK,
// SLASH,
// BACKSLASH,
// CARET,
// PERCENT,
//
// // RELATIONAL
// EQUALS,
// NOT_EQUAL,
// GT,
// GTE,
// LT,
// LTE,
// OR,
// AND,
//
// // BOOLEAN
// AMPERSAND,
// VERTICAL_BAR,
//
// // MISC
// REST,
// RANGE_TO,
// PIPE_FORWARD,
// PIPE_BACKWARD,
// SHIFT_RIGHT,
// SHIFT_LEFT,
// ARROW,
// TILDE,
// BANG,
// QUESTION,
// COLON,
// COMMA,
// DOT,
//
// UNDERSCORE,
//
// // SCRIPT
// MODULE,
// TYPE,
// IDENTIFIER,
// NULL,
// LET,
// RETURN,
// IF,
// ELSE,
// FOR,
//
// LINE,
// EOF,
// }
| import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.ast.flow.ReturnExpr;
import xyz.avarel.kaiper.ast.value.NullNode;
import xyz.avarel.kaiper.exceptions.SyntaxException;
import xyz.avarel.kaiper.lexer.Token;
import xyz.avarel.kaiper.lexer.TokenType;
import xyz.avarel.kaiper.parser.KaiperParser;
import xyz.avarel.kaiper.parser.PrefixParser; | /*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.parser.parslets.flow;
public class ReturnParser implements PrefixParser {
@Override
public Expr parse(KaiperParser parser, Token token) {
if (!parser.getParserFlags().allowControlFlows()) {
throw new SyntaxException("Control flows are disabled");
}
Single expr;
if (parser.nextIsAny(TokenType.LINE, TokenType.RIGHT_BRACE)) { | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/flow/ReturnExpr.java
// public class ReturnExpr extends Single {
// private final Single expr;
//
// public ReturnExpr(Position position, Single expr) {
// super(position);
// this.expr = expr;
// }
//
// public Single getExpr() {
// return expr;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// expr.ast("return", builder, indent, true);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/value/NullNode.java
// public class NullNode extends Single {
// public static final NullNode VALUE = new NullNode();
//
// private NullNode() {
// super(null);
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/lexer/TokenType.java
// public enum TokenType {
// // PAIRS
// LEFT_PAREN,
// RIGHT_PAREN,
//
// LEFT_BRACKET,
// RIGHT_BRACKET,
//
// LEFT_BRACE,
// RIGHT_BRACE,
//
// OPTIONAL_ASSIGN,
// ELVIS,
//
// // ASSIGNMENT
// ASSIGN,
//
// // TYPES
// INT,
// NUMBER,
// BOOLEAN,
// FUNCTION,
// STRING,
// ATOM,
//
// // ARITHMETIC
// PLUS,
// MINUS,
// ASTERISK,
// SLASH,
// BACKSLASH,
// CARET,
// PERCENT,
//
// // RELATIONAL
// EQUALS,
// NOT_EQUAL,
// GT,
// GTE,
// LT,
// LTE,
// OR,
// AND,
//
// // BOOLEAN
// AMPERSAND,
// VERTICAL_BAR,
//
// // MISC
// REST,
// RANGE_TO,
// PIPE_FORWARD,
// PIPE_BACKWARD,
// SHIFT_RIGHT,
// SHIFT_LEFT,
// ARROW,
// TILDE,
// BANG,
// QUESTION,
// COLON,
// COMMA,
// DOT,
//
// UNDERSCORE,
//
// // SCRIPT
// MODULE,
// TYPE,
// IDENTIFIER,
// NULL,
// LET,
// RETURN,
// IF,
// ELSE,
// FOR,
//
// LINE,
// EOF,
// }
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/parslets/flow/ReturnParser.java
import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.ast.flow.ReturnExpr;
import xyz.avarel.kaiper.ast.value.NullNode;
import xyz.avarel.kaiper.exceptions.SyntaxException;
import xyz.avarel.kaiper.lexer.Token;
import xyz.avarel.kaiper.lexer.TokenType;
import xyz.avarel.kaiper.parser.KaiperParser;
import xyz.avarel.kaiper.parser.PrefixParser;
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.parser.parslets.flow;
public class ReturnParser implements PrefixParser {
@Override
public Expr parse(KaiperParser parser, Token token) {
if (!parser.getParserFlags().allowControlFlows()) {
throw new SyntaxException("Control flows are disabled");
}
Single expr;
if (parser.nextIsAny(TokenType.LINE, TokenType.RIGHT_BRACE)) { | expr = NullNode.VALUE; |
Avarel/Kaiper | Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/parslets/flow/ReturnParser.java | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/flow/ReturnExpr.java
// public class ReturnExpr extends Single {
// private final Single expr;
//
// public ReturnExpr(Position position, Single expr) {
// super(position);
// this.expr = expr;
// }
//
// public Single getExpr() {
// return expr;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// expr.ast("return", builder, indent, true);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/value/NullNode.java
// public class NullNode extends Single {
// public static final NullNode VALUE = new NullNode();
//
// private NullNode() {
// super(null);
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/lexer/TokenType.java
// public enum TokenType {
// // PAIRS
// LEFT_PAREN,
// RIGHT_PAREN,
//
// LEFT_BRACKET,
// RIGHT_BRACKET,
//
// LEFT_BRACE,
// RIGHT_BRACE,
//
// OPTIONAL_ASSIGN,
// ELVIS,
//
// // ASSIGNMENT
// ASSIGN,
//
// // TYPES
// INT,
// NUMBER,
// BOOLEAN,
// FUNCTION,
// STRING,
// ATOM,
//
// // ARITHMETIC
// PLUS,
// MINUS,
// ASTERISK,
// SLASH,
// BACKSLASH,
// CARET,
// PERCENT,
//
// // RELATIONAL
// EQUALS,
// NOT_EQUAL,
// GT,
// GTE,
// LT,
// LTE,
// OR,
// AND,
//
// // BOOLEAN
// AMPERSAND,
// VERTICAL_BAR,
//
// // MISC
// REST,
// RANGE_TO,
// PIPE_FORWARD,
// PIPE_BACKWARD,
// SHIFT_RIGHT,
// SHIFT_LEFT,
// ARROW,
// TILDE,
// BANG,
// QUESTION,
// COLON,
// COMMA,
// DOT,
//
// UNDERSCORE,
//
// // SCRIPT
// MODULE,
// TYPE,
// IDENTIFIER,
// NULL,
// LET,
// RETURN,
// IF,
// ELSE,
// FOR,
//
// LINE,
// EOF,
// }
| import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.ast.flow.ReturnExpr;
import xyz.avarel.kaiper.ast.value.NullNode;
import xyz.avarel.kaiper.exceptions.SyntaxException;
import xyz.avarel.kaiper.lexer.Token;
import xyz.avarel.kaiper.lexer.TokenType;
import xyz.avarel.kaiper.parser.KaiperParser;
import xyz.avarel.kaiper.parser.PrefixParser; | /*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.parser.parslets.flow;
public class ReturnParser implements PrefixParser {
@Override
public Expr parse(KaiperParser parser, Token token) {
if (!parser.getParserFlags().allowControlFlows()) {
throw new SyntaxException("Control flows are disabled");
}
Single expr;
if (parser.nextIsAny(TokenType.LINE, TokenType.RIGHT_BRACE)) {
expr = NullNode.VALUE;
} else {
expr = parser.parseSingle();
} | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/flow/ReturnExpr.java
// public class ReturnExpr extends Single {
// private final Single expr;
//
// public ReturnExpr(Position position, Single expr) {
// super(position);
// this.expr = expr;
// }
//
// public Single getExpr() {
// return expr;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// expr.ast("return", builder, indent, true);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/value/NullNode.java
// public class NullNode extends Single {
// public static final NullNode VALUE = new NullNode();
//
// private NullNode() {
// super(null);
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/lexer/TokenType.java
// public enum TokenType {
// // PAIRS
// LEFT_PAREN,
// RIGHT_PAREN,
//
// LEFT_BRACKET,
// RIGHT_BRACKET,
//
// LEFT_BRACE,
// RIGHT_BRACE,
//
// OPTIONAL_ASSIGN,
// ELVIS,
//
// // ASSIGNMENT
// ASSIGN,
//
// // TYPES
// INT,
// NUMBER,
// BOOLEAN,
// FUNCTION,
// STRING,
// ATOM,
//
// // ARITHMETIC
// PLUS,
// MINUS,
// ASTERISK,
// SLASH,
// BACKSLASH,
// CARET,
// PERCENT,
//
// // RELATIONAL
// EQUALS,
// NOT_EQUAL,
// GT,
// GTE,
// LT,
// LTE,
// OR,
// AND,
//
// // BOOLEAN
// AMPERSAND,
// VERTICAL_BAR,
//
// // MISC
// REST,
// RANGE_TO,
// PIPE_FORWARD,
// PIPE_BACKWARD,
// SHIFT_RIGHT,
// SHIFT_LEFT,
// ARROW,
// TILDE,
// BANG,
// QUESTION,
// COLON,
// COMMA,
// DOT,
//
// UNDERSCORE,
//
// // SCRIPT
// MODULE,
// TYPE,
// IDENTIFIER,
// NULL,
// LET,
// RETURN,
// IF,
// ELSE,
// FOR,
//
// LINE,
// EOF,
// }
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/parslets/flow/ReturnParser.java
import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.ast.flow.ReturnExpr;
import xyz.avarel.kaiper.ast.value.NullNode;
import xyz.avarel.kaiper.exceptions.SyntaxException;
import xyz.avarel.kaiper.lexer.Token;
import xyz.avarel.kaiper.lexer.TokenType;
import xyz.avarel.kaiper.parser.KaiperParser;
import xyz.avarel.kaiper.parser.PrefixParser;
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.parser.parslets.flow;
public class ReturnParser implements PrefixParser {
@Override
public Expr parse(KaiperParser parser, Token token) {
if (!parser.getParserFlags().allowControlFlows()) {
throw new SyntaxException("Control flows are disabled");
}
Single expr;
if (parser.nextIsAny(TokenType.LINE, TokenType.RIGHT_BRACE)) {
expr = NullNode.VALUE;
} else {
expr = parser.parseSingle();
} | return new ReturnExpr(token.getPosition(), expr); |
Avarel/Kaiper | Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/collections/GetOperation.java | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/ExprVisitor.java
// public interface ExprVisitor<R, C> {
// R visit(Statements expr, C scope);
//
// R visit(FunctionNode expr, C scope);
//
// R visit(Identifier expr, C scope);
//
// R visit(Invocation expr, C scope);
//
// R visit(BinaryOperation expr, C scope);
//
// R visit(UnaryOperation expr, C scope);
//
// R visit(RangeNode expr, C scope);
//
// R visit(ArrayNode expr, C scope);
//
// R visit(SliceOperation expr, C scope);
//
// R visit(AssignmentExpr expr, C scope);
//
// R visit(GetOperation expr, C scope);
//
// R visit(SetOperation expr, C scope);
//
// R visit(ReturnExpr expr, C scope);
//
// R visit(ConditionalExpr expr, C scope);
//
// R visit(ForEachExpr expr, C scope);
//
// R visit(DictionaryNode expr, C scope);
//
// R visit(NullNode expr, C scope);
//
// R visit(IntNode expr, C scope);
//
// R visit(DecimalNode expr, C scope);
//
// R visit(BooleanNode expr, C scope);
//
// R visit(StringNode expr, C scope);
//
// R visit(DeclarationExpr expr, C scope);
//
// R visit(ModuleNode expr, C scope);
//
// R visit(TypeNode expr, C scope);
//
// R visit(WhileExpr expr, C scope);
// }
| import xyz.avarel.kaiper.ast.ExprVisitor;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.lexer.Position; | /*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.ast.collections;
public class GetOperation extends Single {
private final Single left;
private final Single key;
public GetOperation(Position position, Single left, Single key) {
super(position);
this.left = left;
this.key = key;
}
public Single getLeft() {
return left;
}
public Single getKey() {
return key;
}
@Override | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/ExprVisitor.java
// public interface ExprVisitor<R, C> {
// R visit(Statements expr, C scope);
//
// R visit(FunctionNode expr, C scope);
//
// R visit(Identifier expr, C scope);
//
// R visit(Invocation expr, C scope);
//
// R visit(BinaryOperation expr, C scope);
//
// R visit(UnaryOperation expr, C scope);
//
// R visit(RangeNode expr, C scope);
//
// R visit(ArrayNode expr, C scope);
//
// R visit(SliceOperation expr, C scope);
//
// R visit(AssignmentExpr expr, C scope);
//
// R visit(GetOperation expr, C scope);
//
// R visit(SetOperation expr, C scope);
//
// R visit(ReturnExpr expr, C scope);
//
// R visit(ConditionalExpr expr, C scope);
//
// R visit(ForEachExpr expr, C scope);
//
// R visit(DictionaryNode expr, C scope);
//
// R visit(NullNode expr, C scope);
//
// R visit(IntNode expr, C scope);
//
// R visit(DecimalNode expr, C scope);
//
// R visit(BooleanNode expr, C scope);
//
// R visit(StringNode expr, C scope);
//
// R visit(DeclarationExpr expr, C scope);
//
// R visit(ModuleNode expr, C scope);
//
// R visit(TypeNode expr, C scope);
//
// R visit(WhileExpr expr, C scope);
// }
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/collections/GetOperation.java
import xyz.avarel.kaiper.ast.ExprVisitor;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.lexer.Position;
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.ast.collections;
public class GetOperation extends Single {
private final Single left;
private final Single key;
public GetOperation(Position position, Single left, Single key) {
super(position);
this.left = left;
this.key = key;
}
public Single getLeft() {
return left;
}
public Single getKey() {
return key;
}
@Override | public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) { |
Avarel/Kaiper | Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/flow/ConditionalExpr.java | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/ExprVisitor.java
// public interface ExprVisitor<R, C> {
// R visit(Statements expr, C scope);
//
// R visit(FunctionNode expr, C scope);
//
// R visit(Identifier expr, C scope);
//
// R visit(Invocation expr, C scope);
//
// R visit(BinaryOperation expr, C scope);
//
// R visit(UnaryOperation expr, C scope);
//
// R visit(RangeNode expr, C scope);
//
// R visit(ArrayNode expr, C scope);
//
// R visit(SliceOperation expr, C scope);
//
// R visit(AssignmentExpr expr, C scope);
//
// R visit(GetOperation expr, C scope);
//
// R visit(SetOperation expr, C scope);
//
// R visit(ReturnExpr expr, C scope);
//
// R visit(ConditionalExpr expr, C scope);
//
// R visit(ForEachExpr expr, C scope);
//
// R visit(DictionaryNode expr, C scope);
//
// R visit(NullNode expr, C scope);
//
// R visit(IntNode expr, C scope);
//
// R visit(DecimalNode expr, C scope);
//
// R visit(BooleanNode expr, C scope);
//
// R visit(StringNode expr, C scope);
//
// R visit(DeclarationExpr expr, C scope);
//
// R visit(ModuleNode expr, C scope);
//
// R visit(TypeNode expr, C scope);
//
// R visit(WhileExpr expr, C scope);
// }
| import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.ExprVisitor;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.lexer.Position; | /*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.ast.flow;
public class ConditionalExpr extends Single {
private final Single condition;
private final Expr ifBranch;
private final Expr elseBranch;
public ConditionalExpr(Position position, Single condition, Expr ifBranch, Expr elseBranch) {
super(position);
this.condition = condition;
this.ifBranch = ifBranch;
this.elseBranch = elseBranch;
}
public Single getCondition() {
return condition;
}
public Expr getIfBranch() {
return ifBranch;
}
public Expr getElseBranch() {
return elseBranch;
}
@Override | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/ExprVisitor.java
// public interface ExprVisitor<R, C> {
// R visit(Statements expr, C scope);
//
// R visit(FunctionNode expr, C scope);
//
// R visit(Identifier expr, C scope);
//
// R visit(Invocation expr, C scope);
//
// R visit(BinaryOperation expr, C scope);
//
// R visit(UnaryOperation expr, C scope);
//
// R visit(RangeNode expr, C scope);
//
// R visit(ArrayNode expr, C scope);
//
// R visit(SliceOperation expr, C scope);
//
// R visit(AssignmentExpr expr, C scope);
//
// R visit(GetOperation expr, C scope);
//
// R visit(SetOperation expr, C scope);
//
// R visit(ReturnExpr expr, C scope);
//
// R visit(ConditionalExpr expr, C scope);
//
// R visit(ForEachExpr expr, C scope);
//
// R visit(DictionaryNode expr, C scope);
//
// R visit(NullNode expr, C scope);
//
// R visit(IntNode expr, C scope);
//
// R visit(DecimalNode expr, C scope);
//
// R visit(BooleanNode expr, C scope);
//
// R visit(StringNode expr, C scope);
//
// R visit(DeclarationExpr expr, C scope);
//
// R visit(ModuleNode expr, C scope);
//
// R visit(TypeNode expr, C scope);
//
// R visit(WhileExpr expr, C scope);
// }
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/flow/ConditionalExpr.java
import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.ExprVisitor;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.lexer.Position;
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.ast.flow;
public class ConditionalExpr extends Single {
private final Single condition;
private final Expr ifBranch;
private final Expr elseBranch;
public ConditionalExpr(Position position, Single condition, Expr ifBranch, Expr elseBranch) {
super(position);
this.condition = condition;
this.ifBranch = ifBranch;
this.elseBranch = elseBranch;
}
public Single getCondition() {
return condition;
}
public Expr getIfBranch() {
return ifBranch;
}
public Expr getElseBranch() {
return elseBranch;
}
@Override | public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) { |
Avarel/Kaiper | Kaiper-VM/src/main/java/xyz/avarel/kaiper/vm/GlobalVisitorSettings.java | // Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/exceptions/ComputeException.java
// public class ComputeException extends KaiperException {
// public ComputeException(String msg) {
// super(msg);
// }
//
// public ComputeException(String s, Throwable throwable) {
// super(s, throwable);
// }
//
// public ComputeException(Throwable throwable) {
// super(throwable);
// }
// }
| import xyz.avarel.kaiper.exceptions.ComputeException; | /*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.vm;
public class GlobalVisitorSettings {
public static int ITERATION_LIMIT = -1;
public static int SIZE_LIMIT = -1;
public static long MILLISECONDS_LIMIT = -1;
public static void checkIterationLimit(int iter) {
if (ITERATION_LIMIT != -1 && iter > ITERATION_LIMIT) { | // Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/exceptions/ComputeException.java
// public class ComputeException extends KaiperException {
// public ComputeException(String msg) {
// super(msg);
// }
//
// public ComputeException(String s, Throwable throwable) {
// super(s, throwable);
// }
//
// public ComputeException(Throwable throwable) {
// super(throwable);
// }
// }
// Path: Kaiper-VM/src/main/java/xyz/avarel/kaiper/vm/GlobalVisitorSettings.java
import xyz.avarel.kaiper.exceptions.ComputeException;
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.vm;
public class GlobalVisitorSettings {
public static int ITERATION_LIMIT = -1;
public static int SIZE_LIMIT = -1;
public static long MILLISECONDS_LIMIT = -1;
public static void checkIterationLimit(int iter) {
if (ITERATION_LIMIT != -1 && iter > ITERATION_LIMIT) { | throw new ComputeException("Iteration limit"); |
Avarel/Kaiper | Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/flow/ReturnExpr.java | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/ExprVisitor.java
// public interface ExprVisitor<R, C> {
// R visit(Statements expr, C scope);
//
// R visit(FunctionNode expr, C scope);
//
// R visit(Identifier expr, C scope);
//
// R visit(Invocation expr, C scope);
//
// R visit(BinaryOperation expr, C scope);
//
// R visit(UnaryOperation expr, C scope);
//
// R visit(RangeNode expr, C scope);
//
// R visit(ArrayNode expr, C scope);
//
// R visit(SliceOperation expr, C scope);
//
// R visit(AssignmentExpr expr, C scope);
//
// R visit(GetOperation expr, C scope);
//
// R visit(SetOperation expr, C scope);
//
// R visit(ReturnExpr expr, C scope);
//
// R visit(ConditionalExpr expr, C scope);
//
// R visit(ForEachExpr expr, C scope);
//
// R visit(DictionaryNode expr, C scope);
//
// R visit(NullNode expr, C scope);
//
// R visit(IntNode expr, C scope);
//
// R visit(DecimalNode expr, C scope);
//
// R visit(BooleanNode expr, C scope);
//
// R visit(StringNode expr, C scope);
//
// R visit(DeclarationExpr expr, C scope);
//
// R visit(ModuleNode expr, C scope);
//
// R visit(TypeNode expr, C scope);
//
// R visit(WhileExpr expr, C scope);
// }
| import xyz.avarel.kaiper.ast.ExprVisitor;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.lexer.Position; | /*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.ast.flow;
public class ReturnExpr extends Single {
private final Single expr;
public ReturnExpr(Position position, Single expr) {
super(position);
this.expr = expr;
}
public Single getExpr() {
return expr;
}
@Override | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/ExprVisitor.java
// public interface ExprVisitor<R, C> {
// R visit(Statements expr, C scope);
//
// R visit(FunctionNode expr, C scope);
//
// R visit(Identifier expr, C scope);
//
// R visit(Invocation expr, C scope);
//
// R visit(BinaryOperation expr, C scope);
//
// R visit(UnaryOperation expr, C scope);
//
// R visit(RangeNode expr, C scope);
//
// R visit(ArrayNode expr, C scope);
//
// R visit(SliceOperation expr, C scope);
//
// R visit(AssignmentExpr expr, C scope);
//
// R visit(GetOperation expr, C scope);
//
// R visit(SetOperation expr, C scope);
//
// R visit(ReturnExpr expr, C scope);
//
// R visit(ConditionalExpr expr, C scope);
//
// R visit(ForEachExpr expr, C scope);
//
// R visit(DictionaryNode expr, C scope);
//
// R visit(NullNode expr, C scope);
//
// R visit(IntNode expr, C scope);
//
// R visit(DecimalNode expr, C scope);
//
// R visit(BooleanNode expr, C scope);
//
// R visit(StringNode expr, C scope);
//
// R visit(DeclarationExpr expr, C scope);
//
// R visit(ModuleNode expr, C scope);
//
// R visit(TypeNode expr, C scope);
//
// R visit(WhileExpr expr, C scope);
// }
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/flow/ReturnExpr.java
import xyz.avarel.kaiper.ast.ExprVisitor;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.lexer.Position;
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.ast.flow;
public class ReturnExpr extends Single {
private final Single expr;
public ReturnExpr(Position position, Single expr) {
super(position);
this.expr = expr;
}
public Single getExpr() {
return expr;
}
@Override | public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) { |
Avarel/Kaiper | Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/parslets/functional/PipeForwardParser.java | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/functions/FunctionNode.java
// public class FunctionNode extends Single {
// private final String name;
// private final List<ParameterData> parameters;
// private final Expr expr;
//
// public FunctionNode(Position position, List<ParameterData> parameters, Expr expr) {
// this(position, null, parameters, expr);
// }
//
// public FunctionNode(Position position, String name, List<ParameterData> parameters, Expr expr) {
// super(position);
// this.name = name;
// this.parameters = parameters;
// this.expr = expr;
// }
//
// public String getName() {
// return name;
// }
//
// public List<ParameterData> getParameterExprs() {
// return parameters;
// }
//
// public Expr getExpr() {
// return expr;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// builder.append(indent).append(isTail ? "└── " : "├── ")
// .append("func").append(name != null ? " " + name : "")
// .append('(')
// .append(getParameterExprs().stream().map(Object::toString)
// .collect(Collectors.joining(", ")))
// .append(')');
//
// builder.append('\n');
// expr.ast(builder, indent + (isTail ? " " : "│ "), true);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/invocation/Invocation.java
// public class Invocation extends Single {
// private final Single left;
// private final List<Single> arguments;
//
// public Invocation(Position position, Single left, List<Single> arguments) {
// super(position);
// this.left = left;
// this.arguments = arguments;
// }
//
// public Single getLeft() {
// return left;
// }
//
// public List<Single> getArguments() {
// return arguments;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// builder.append(indent).append(isTail ? "└── " : "├── ").append("invoke");
//
// builder.append('\n');
// left.ast("target", builder, indent + (isTail ? " " : "│ "), false);
//
// builder.append('\n');
// if (arguments.isEmpty()) {
// builder.append(indent).append(isTail ? " " : "│ ").append("└── ").append("*");
// } else {
// for (int i = 0; i < arguments.size() - 1; i++) {
// arguments.get(i).ast(builder, indent + (isTail ? " " : "│ "), false);
// builder.append('\n');
// }
// if (arguments.size() > 0) {
// arguments.get(arguments.size() - 1).ast(builder, indent + (isTail ? " " : "│ "), true);
// }
// }
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/BinaryParser.java
// public abstract class BinaryParser implements InfixParser {
// private final int precedence;
// private final boolean leftAssoc;
//
// public BinaryParser(int precedence) {
// this(precedence, true);
// }
//
// public BinaryParser(int precedence, boolean leftAssoc) {
// this.precedence = precedence;
// this.leftAssoc = leftAssoc;
// }
//
// @Override
// public Expr parse(KaiperParser parser, Expr left, Token token) {
// if (!(left instanceof Single)) {
// throw new SyntaxException("Internal compiler error", token.getPosition());
// }
// return parse(parser, (Single) left, token);
// }
//
// public abstract Expr parse(KaiperParser parser, Single left, Token token);
//
// @Override
// public int getPrecedence() {
// return precedence;
// }
//
// public boolean isLeftAssoc() {
// return leftAssoc;
// }
// }
| import xyz.avarel.kaiper.Precedence;
import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.ast.functions.FunctionNode;
import xyz.avarel.kaiper.ast.invocation.Invocation;
import xyz.avarel.kaiper.ast.variables.Identifier;
import xyz.avarel.kaiper.exceptions.SyntaxException;
import xyz.avarel.kaiper.lexer.Token;
import xyz.avarel.kaiper.parser.BinaryParser;
import xyz.avarel.kaiper.parser.KaiperParser;
import java.util.Collections; | /*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.parser.parslets.functional;
public class PipeForwardParser extends BinaryParser {
public PipeForwardParser() {
super(Precedence.INFIX);
}
@Override
public Expr parse(KaiperParser parser, Single left, Token token) {
if (!parser.getParserFlags().allowInvocation()) {
throw new SyntaxException("Function invocation are disabled");
}
Single right = parser.parseSingle(getPrecedence());
| // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/functions/FunctionNode.java
// public class FunctionNode extends Single {
// private final String name;
// private final List<ParameterData> parameters;
// private final Expr expr;
//
// public FunctionNode(Position position, List<ParameterData> parameters, Expr expr) {
// this(position, null, parameters, expr);
// }
//
// public FunctionNode(Position position, String name, List<ParameterData> parameters, Expr expr) {
// super(position);
// this.name = name;
// this.parameters = parameters;
// this.expr = expr;
// }
//
// public String getName() {
// return name;
// }
//
// public List<ParameterData> getParameterExprs() {
// return parameters;
// }
//
// public Expr getExpr() {
// return expr;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// builder.append(indent).append(isTail ? "└── " : "├── ")
// .append("func").append(name != null ? " " + name : "")
// .append('(')
// .append(getParameterExprs().stream().map(Object::toString)
// .collect(Collectors.joining(", ")))
// .append(')');
//
// builder.append('\n');
// expr.ast(builder, indent + (isTail ? " " : "│ "), true);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/invocation/Invocation.java
// public class Invocation extends Single {
// private final Single left;
// private final List<Single> arguments;
//
// public Invocation(Position position, Single left, List<Single> arguments) {
// super(position);
// this.left = left;
// this.arguments = arguments;
// }
//
// public Single getLeft() {
// return left;
// }
//
// public List<Single> getArguments() {
// return arguments;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// builder.append(indent).append(isTail ? "└── " : "├── ").append("invoke");
//
// builder.append('\n');
// left.ast("target", builder, indent + (isTail ? " " : "│ "), false);
//
// builder.append('\n');
// if (arguments.isEmpty()) {
// builder.append(indent).append(isTail ? " " : "│ ").append("└── ").append("*");
// } else {
// for (int i = 0; i < arguments.size() - 1; i++) {
// arguments.get(i).ast(builder, indent + (isTail ? " " : "│ "), false);
// builder.append('\n');
// }
// if (arguments.size() > 0) {
// arguments.get(arguments.size() - 1).ast(builder, indent + (isTail ? " " : "│ "), true);
// }
// }
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/BinaryParser.java
// public abstract class BinaryParser implements InfixParser {
// private final int precedence;
// private final boolean leftAssoc;
//
// public BinaryParser(int precedence) {
// this(precedence, true);
// }
//
// public BinaryParser(int precedence, boolean leftAssoc) {
// this.precedence = precedence;
// this.leftAssoc = leftAssoc;
// }
//
// @Override
// public Expr parse(KaiperParser parser, Expr left, Token token) {
// if (!(left instanceof Single)) {
// throw new SyntaxException("Internal compiler error", token.getPosition());
// }
// return parse(parser, (Single) left, token);
// }
//
// public abstract Expr parse(KaiperParser parser, Single left, Token token);
//
// @Override
// public int getPrecedence() {
// return precedence;
// }
//
// public boolean isLeftAssoc() {
// return leftAssoc;
// }
// }
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/parslets/functional/PipeForwardParser.java
import xyz.avarel.kaiper.Precedence;
import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.ast.functions.FunctionNode;
import xyz.avarel.kaiper.ast.invocation.Invocation;
import xyz.avarel.kaiper.ast.variables.Identifier;
import xyz.avarel.kaiper.exceptions.SyntaxException;
import xyz.avarel.kaiper.lexer.Token;
import xyz.avarel.kaiper.parser.BinaryParser;
import xyz.avarel.kaiper.parser.KaiperParser;
import java.util.Collections;
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.parser.parslets.functional;
public class PipeForwardParser extends BinaryParser {
public PipeForwardParser() {
super(Precedence.INFIX);
}
@Override
public Expr parse(KaiperParser parser, Single left, Token token) {
if (!parser.getParserFlags().allowInvocation()) {
throw new SyntaxException("Function invocation are disabled");
}
Single right = parser.parseSingle(getPrecedence());
| if (right instanceof Invocation) { |
Avarel/Kaiper | Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/parslets/functional/PipeForwardParser.java | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/functions/FunctionNode.java
// public class FunctionNode extends Single {
// private final String name;
// private final List<ParameterData> parameters;
// private final Expr expr;
//
// public FunctionNode(Position position, List<ParameterData> parameters, Expr expr) {
// this(position, null, parameters, expr);
// }
//
// public FunctionNode(Position position, String name, List<ParameterData> parameters, Expr expr) {
// super(position);
// this.name = name;
// this.parameters = parameters;
// this.expr = expr;
// }
//
// public String getName() {
// return name;
// }
//
// public List<ParameterData> getParameterExprs() {
// return parameters;
// }
//
// public Expr getExpr() {
// return expr;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// builder.append(indent).append(isTail ? "└── " : "├── ")
// .append("func").append(name != null ? " " + name : "")
// .append('(')
// .append(getParameterExprs().stream().map(Object::toString)
// .collect(Collectors.joining(", ")))
// .append(')');
//
// builder.append('\n');
// expr.ast(builder, indent + (isTail ? " " : "│ "), true);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/invocation/Invocation.java
// public class Invocation extends Single {
// private final Single left;
// private final List<Single> arguments;
//
// public Invocation(Position position, Single left, List<Single> arguments) {
// super(position);
// this.left = left;
// this.arguments = arguments;
// }
//
// public Single getLeft() {
// return left;
// }
//
// public List<Single> getArguments() {
// return arguments;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// builder.append(indent).append(isTail ? "└── " : "├── ").append("invoke");
//
// builder.append('\n');
// left.ast("target", builder, indent + (isTail ? " " : "│ "), false);
//
// builder.append('\n');
// if (arguments.isEmpty()) {
// builder.append(indent).append(isTail ? " " : "│ ").append("└── ").append("*");
// } else {
// for (int i = 0; i < arguments.size() - 1; i++) {
// arguments.get(i).ast(builder, indent + (isTail ? " " : "│ "), false);
// builder.append('\n');
// }
// if (arguments.size() > 0) {
// arguments.get(arguments.size() - 1).ast(builder, indent + (isTail ? " " : "│ "), true);
// }
// }
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/BinaryParser.java
// public abstract class BinaryParser implements InfixParser {
// private final int precedence;
// private final boolean leftAssoc;
//
// public BinaryParser(int precedence) {
// this(precedence, true);
// }
//
// public BinaryParser(int precedence, boolean leftAssoc) {
// this.precedence = precedence;
// this.leftAssoc = leftAssoc;
// }
//
// @Override
// public Expr parse(KaiperParser parser, Expr left, Token token) {
// if (!(left instanceof Single)) {
// throw new SyntaxException("Internal compiler error", token.getPosition());
// }
// return parse(parser, (Single) left, token);
// }
//
// public abstract Expr parse(KaiperParser parser, Single left, Token token);
//
// @Override
// public int getPrecedence() {
// return precedence;
// }
//
// public boolean isLeftAssoc() {
// return leftAssoc;
// }
// }
| import xyz.avarel.kaiper.Precedence;
import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.ast.functions.FunctionNode;
import xyz.avarel.kaiper.ast.invocation.Invocation;
import xyz.avarel.kaiper.ast.variables.Identifier;
import xyz.avarel.kaiper.exceptions.SyntaxException;
import xyz.avarel.kaiper.lexer.Token;
import xyz.avarel.kaiper.parser.BinaryParser;
import xyz.avarel.kaiper.parser.KaiperParser;
import java.util.Collections; | /*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.parser.parslets.functional;
public class PipeForwardParser extends BinaryParser {
public PipeForwardParser() {
super(Precedence.INFIX);
}
@Override
public Expr parse(KaiperParser parser, Single left, Token token) {
if (!parser.getParserFlags().allowInvocation()) {
throw new SyntaxException("Function invocation are disabled");
}
Single right = parser.parseSingle(getPrecedence());
if (right instanceof Invocation) {
((Invocation) right).getArguments().add(0, left);
return right; | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/functions/FunctionNode.java
// public class FunctionNode extends Single {
// private final String name;
// private final List<ParameterData> parameters;
// private final Expr expr;
//
// public FunctionNode(Position position, List<ParameterData> parameters, Expr expr) {
// this(position, null, parameters, expr);
// }
//
// public FunctionNode(Position position, String name, List<ParameterData> parameters, Expr expr) {
// super(position);
// this.name = name;
// this.parameters = parameters;
// this.expr = expr;
// }
//
// public String getName() {
// return name;
// }
//
// public List<ParameterData> getParameterExprs() {
// return parameters;
// }
//
// public Expr getExpr() {
// return expr;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// builder.append(indent).append(isTail ? "└── " : "├── ")
// .append("func").append(name != null ? " " + name : "")
// .append('(')
// .append(getParameterExprs().stream().map(Object::toString)
// .collect(Collectors.joining(", ")))
// .append(')');
//
// builder.append('\n');
// expr.ast(builder, indent + (isTail ? " " : "│ "), true);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/invocation/Invocation.java
// public class Invocation extends Single {
// private final Single left;
// private final List<Single> arguments;
//
// public Invocation(Position position, Single left, List<Single> arguments) {
// super(position);
// this.left = left;
// this.arguments = arguments;
// }
//
// public Single getLeft() {
// return left;
// }
//
// public List<Single> getArguments() {
// return arguments;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// builder.append(indent).append(isTail ? "└── " : "├── ").append("invoke");
//
// builder.append('\n');
// left.ast("target", builder, indent + (isTail ? " " : "│ "), false);
//
// builder.append('\n');
// if (arguments.isEmpty()) {
// builder.append(indent).append(isTail ? " " : "│ ").append("└── ").append("*");
// } else {
// for (int i = 0; i < arguments.size() - 1; i++) {
// arguments.get(i).ast(builder, indent + (isTail ? " " : "│ "), false);
// builder.append('\n');
// }
// if (arguments.size() > 0) {
// arguments.get(arguments.size() - 1).ast(builder, indent + (isTail ? " " : "│ "), true);
// }
// }
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/BinaryParser.java
// public abstract class BinaryParser implements InfixParser {
// private final int precedence;
// private final boolean leftAssoc;
//
// public BinaryParser(int precedence) {
// this(precedence, true);
// }
//
// public BinaryParser(int precedence, boolean leftAssoc) {
// this.precedence = precedence;
// this.leftAssoc = leftAssoc;
// }
//
// @Override
// public Expr parse(KaiperParser parser, Expr left, Token token) {
// if (!(left instanceof Single)) {
// throw new SyntaxException("Internal compiler error", token.getPosition());
// }
// return parse(parser, (Single) left, token);
// }
//
// public abstract Expr parse(KaiperParser parser, Single left, Token token);
//
// @Override
// public int getPrecedence() {
// return precedence;
// }
//
// public boolean isLeftAssoc() {
// return leftAssoc;
// }
// }
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/parslets/functional/PipeForwardParser.java
import xyz.avarel.kaiper.Precedence;
import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.ast.functions.FunctionNode;
import xyz.avarel.kaiper.ast.invocation.Invocation;
import xyz.avarel.kaiper.ast.variables.Identifier;
import xyz.avarel.kaiper.exceptions.SyntaxException;
import xyz.avarel.kaiper.lexer.Token;
import xyz.avarel.kaiper.parser.BinaryParser;
import xyz.avarel.kaiper.parser.KaiperParser;
import java.util.Collections;
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.parser.parslets.functional;
public class PipeForwardParser extends BinaryParser {
public PipeForwardParser() {
super(Precedence.INFIX);
}
@Override
public Expr parse(KaiperParser parser, Single left, Token token) {
if (!parser.getParserFlags().allowInvocation()) {
throw new SyntaxException("Function invocation are disabled");
}
Single right = parser.parseSingle(getPrecedence());
if (right instanceof Invocation) {
((Invocation) right).getArguments().add(0, left);
return right; | } else if (right instanceof FunctionNode || right instanceof Identifier) { |
Avarel/Kaiper | Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/Parser.java | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/lexer/TokenType.java
// public enum TokenType {
// // PAIRS
// LEFT_PAREN,
// RIGHT_PAREN,
//
// LEFT_BRACKET,
// RIGHT_BRACKET,
//
// LEFT_BRACE,
// RIGHT_BRACE,
//
// OPTIONAL_ASSIGN,
// ELVIS,
//
// // ASSIGNMENT
// ASSIGN,
//
// // TYPES
// INT,
// NUMBER,
// BOOLEAN,
// FUNCTION,
// STRING,
// ATOM,
//
// // ARITHMETIC
// PLUS,
// MINUS,
// ASTERISK,
// SLASH,
// BACKSLASH,
// CARET,
// PERCENT,
//
// // RELATIONAL
// EQUALS,
// NOT_EQUAL,
// GT,
// GTE,
// LT,
// LTE,
// OR,
// AND,
//
// // BOOLEAN
// AMPERSAND,
// VERTICAL_BAR,
//
// // MISC
// REST,
// RANGE_TO,
// PIPE_FORWARD,
// PIPE_BACKWARD,
// SHIFT_RIGHT,
// SHIFT_LEFT,
// ARROW,
// TILDE,
// BANG,
// QUESTION,
// COLON,
// COMMA,
// DOT,
//
// UNDERSCORE,
//
// // SCRIPT
// MODULE,
// TYPE,
// IDENTIFIER,
// NULL,
// LET,
// RETURN,
// IF,
// ELSE,
// FOR,
//
// LINE,
// EOF,
// }
| import xyz.avarel.kaiper.exceptions.SyntaxException;
import xyz.avarel.kaiper.lexer.KaiperLexer;
import xyz.avarel.kaiper.lexer.Token;
import xyz.avarel.kaiper.lexer.TokenType;
import java.util.ArrayList;
import java.util.List;
import java.util.Map; | /*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.parser;
public abstract class Parser {
private final KaiperLexer lexer;
private final List<Token> tokens;
private final Grammar grammar;
private Token last;
public Parser(KaiperLexer lexer) {
this(lexer, new Grammar());
}
public Parser(KaiperLexer lexer, Grammar grammar) {
this.lexer = lexer;
this.tokens = new ArrayList<>();
this.grammar = grammar;
}
protected Parser(Parser proxy) {
this.lexer = proxy.lexer;
this.tokens = proxy.tokens;
this.grammar = proxy.grammar;
}
public Token getLast() {
return last;
}
| // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/lexer/TokenType.java
// public enum TokenType {
// // PAIRS
// LEFT_PAREN,
// RIGHT_PAREN,
//
// LEFT_BRACKET,
// RIGHT_BRACKET,
//
// LEFT_BRACE,
// RIGHT_BRACE,
//
// OPTIONAL_ASSIGN,
// ELVIS,
//
// // ASSIGNMENT
// ASSIGN,
//
// // TYPES
// INT,
// NUMBER,
// BOOLEAN,
// FUNCTION,
// STRING,
// ATOM,
//
// // ARITHMETIC
// PLUS,
// MINUS,
// ASTERISK,
// SLASH,
// BACKSLASH,
// CARET,
// PERCENT,
//
// // RELATIONAL
// EQUALS,
// NOT_EQUAL,
// GT,
// GTE,
// LT,
// LTE,
// OR,
// AND,
//
// // BOOLEAN
// AMPERSAND,
// VERTICAL_BAR,
//
// // MISC
// REST,
// RANGE_TO,
// PIPE_FORWARD,
// PIPE_BACKWARD,
// SHIFT_RIGHT,
// SHIFT_LEFT,
// ARROW,
// TILDE,
// BANG,
// QUESTION,
// COLON,
// COMMA,
// DOT,
//
// UNDERSCORE,
//
// // SCRIPT
// MODULE,
// TYPE,
// IDENTIFIER,
// NULL,
// LET,
// RETURN,
// IF,
// ELSE,
// FOR,
//
// LINE,
// EOF,
// }
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/Parser.java
import xyz.avarel.kaiper.exceptions.SyntaxException;
import xyz.avarel.kaiper.lexer.KaiperLexer;
import xyz.avarel.kaiper.lexer.Token;
import xyz.avarel.kaiper.lexer.TokenType;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.parser;
public abstract class Parser {
private final KaiperLexer lexer;
private final List<Token> tokens;
private final Grammar grammar;
private Token last;
public Parser(KaiperLexer lexer) {
this(lexer, new Grammar());
}
public Parser(KaiperLexer lexer, Grammar grammar) {
this.lexer = lexer;
this.tokens = new ArrayList<>();
this.grammar = grammar;
}
protected Parser(Parser proxy) {
this.lexer = proxy.lexer;
this.tokens = proxy.tokens;
this.grammar = proxy.grammar;
}
public Token getLast() {
return last;
}
| public Map<TokenType, PrefixParser> getPrefixParsers() { |
Avarel/Kaiper | Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/parslets/TypeParser.java | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/value/NullNode.java
// public class NullNode extends Single {
// public static final NullNode VALUE = new NullNode();
//
// private NullNode() {
// super(null);
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/lexer/TokenType.java
// public enum TokenType {
// // PAIRS
// LEFT_PAREN,
// RIGHT_PAREN,
//
// LEFT_BRACKET,
// RIGHT_BRACKET,
//
// LEFT_BRACE,
// RIGHT_BRACE,
//
// OPTIONAL_ASSIGN,
// ELVIS,
//
// // ASSIGNMENT
// ASSIGN,
//
// // TYPES
// INT,
// NUMBER,
// BOOLEAN,
// FUNCTION,
// STRING,
// ATOM,
//
// // ARITHMETIC
// PLUS,
// MINUS,
// ASTERISK,
// SLASH,
// BACKSLASH,
// CARET,
// PERCENT,
//
// // RELATIONAL
// EQUALS,
// NOT_EQUAL,
// GT,
// GTE,
// LT,
// LTE,
// OR,
// AND,
//
// // BOOLEAN
// AMPERSAND,
// VERTICAL_BAR,
//
// // MISC
// REST,
// RANGE_TO,
// PIPE_FORWARD,
// PIPE_BACKWARD,
// SHIFT_RIGHT,
// SHIFT_LEFT,
// ARROW,
// TILDE,
// BANG,
// QUESTION,
// COLON,
// COMMA,
// DOT,
//
// UNDERSCORE,
//
// // SCRIPT
// MODULE,
// TYPE,
// IDENTIFIER,
// NULL,
// LET,
// RETURN,
// IF,
// ELSE,
// FOR,
//
// LINE,
// EOF,
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/KaiperParserUtils.java
// public class KaiperParserUtils {
// public static Expr parseBlock(KaiperParser parser) {
// Expr expr = NullNode.VALUE;
// parser.eat(TokenType.LEFT_BRACE);
// if (!parser.match(TokenType.RIGHT_BRACE)) {
// expr = parser.parseStatements();
// parser.eat(TokenType.RIGHT_BRACE);
// }
// return expr;
// }
//
// public static List<Single> parseArguments(KaiperParser parser) {
// List<Single> arguments = new ArrayList<>();
//
// parser.eat(TokenType.LEFT_PAREN);
// if (!parser.match(TokenType.RIGHT_PAREN)) {
// do {
// arguments.add(parser.parseSingle());
// } while (parser.match(TokenType.COMMA));
// parser.eat(TokenType.RIGHT_PAREN);
// }
//
// return arguments;
// }
//
// public static List<ParameterData> parseParameters(KaiperParser parser) {
// List<ParameterData> parameters = new ArrayList<>();
//
// parser.eat(TokenType.LEFT_PAREN);
// if (!parser.match(TokenType.RIGHT_PAREN)) {
// Set<String> paramNames = new HashSet<>();
// boolean requireDef = false;
//
// do {
// ParameterData parameter = parseParameter(parser, requireDef);
//
// if (parameter.getDefault() != null) {
// requireDef = true;
// }
//
// if (paramNames.contains(parameter.getName())) {
// throw new SyntaxException("Duplicate parameter name", parser.getLast().getPosition());
// } else {
// paramNames.add(parameter.getName());
// }
//
// if (parameter.isRest() && parser.match(TokenType.COMMA)) {
// throw new SyntaxException("Rest parameters must be the last parameter",
// parser.peek(0).getPosition());
// }
//
// parameters.add(parameter);
// } while (parser.match(TokenType.COMMA));
// parser.match(TokenType.RIGHT_PAREN);
// }
//
// return parameters;
// }
//
// public static ParameterData parseParameter(KaiperParser parser, boolean requireDef) {
// boolean rest = parser.match(TokenType.REST);
//
// String parameterName = parser.eat(TokenType.IDENTIFIER).getString();
//
// Single parameterDefault = null;
//
// if (parser.match(TokenType.COLON)) {
// parser.parseIdentifier(); // keep as type hint, dont do anything
// }
//
// if (parser.match(TokenType.ASSIGN)) {
// if (parameterName.equals("this")) {
// throw new SyntaxException("Instance parameters can not have defaults", parser.getLast().getPosition());
// }
//
// parameterDefault = parser.parseSingle();
// } else if (requireDef) {
// throw new SyntaxException("All parameters after the first default requires a default",
// parser.peek(0).getPosition());
// }
//
// return new ParameterData(parameterName, parameterDefault, rest);
// }
// }
| import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.ast.TypeNode;
import xyz.avarel.kaiper.ast.functions.ParameterData;
import xyz.avarel.kaiper.ast.value.NullNode;
import xyz.avarel.kaiper.ast.variables.Identifier;
import xyz.avarel.kaiper.lexer.Token;
import xyz.avarel.kaiper.lexer.TokenType;
import xyz.avarel.kaiper.parser.KaiperParser;
import xyz.avarel.kaiper.parser.KaiperParserUtils;
import xyz.avarel.kaiper.parser.PrefixParser;
import java.util.Collections;
import java.util.List; | package xyz.avarel.kaiper.parser.parslets;
/**
* type IDENTIFIER(params...) : SUPERTYPE(super params...) {
* // constructor expr
* }
*/
public class TypeParser implements PrefixParser {
@Override
public Expr parse(KaiperParser parser, Token token) { | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/value/NullNode.java
// public class NullNode extends Single {
// public static final NullNode VALUE = new NullNode();
//
// private NullNode() {
// super(null);
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/lexer/TokenType.java
// public enum TokenType {
// // PAIRS
// LEFT_PAREN,
// RIGHT_PAREN,
//
// LEFT_BRACKET,
// RIGHT_BRACKET,
//
// LEFT_BRACE,
// RIGHT_BRACE,
//
// OPTIONAL_ASSIGN,
// ELVIS,
//
// // ASSIGNMENT
// ASSIGN,
//
// // TYPES
// INT,
// NUMBER,
// BOOLEAN,
// FUNCTION,
// STRING,
// ATOM,
//
// // ARITHMETIC
// PLUS,
// MINUS,
// ASTERISK,
// SLASH,
// BACKSLASH,
// CARET,
// PERCENT,
//
// // RELATIONAL
// EQUALS,
// NOT_EQUAL,
// GT,
// GTE,
// LT,
// LTE,
// OR,
// AND,
//
// // BOOLEAN
// AMPERSAND,
// VERTICAL_BAR,
//
// // MISC
// REST,
// RANGE_TO,
// PIPE_FORWARD,
// PIPE_BACKWARD,
// SHIFT_RIGHT,
// SHIFT_LEFT,
// ARROW,
// TILDE,
// BANG,
// QUESTION,
// COLON,
// COMMA,
// DOT,
//
// UNDERSCORE,
//
// // SCRIPT
// MODULE,
// TYPE,
// IDENTIFIER,
// NULL,
// LET,
// RETURN,
// IF,
// ELSE,
// FOR,
//
// LINE,
// EOF,
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/KaiperParserUtils.java
// public class KaiperParserUtils {
// public static Expr parseBlock(KaiperParser parser) {
// Expr expr = NullNode.VALUE;
// parser.eat(TokenType.LEFT_BRACE);
// if (!parser.match(TokenType.RIGHT_BRACE)) {
// expr = parser.parseStatements();
// parser.eat(TokenType.RIGHT_BRACE);
// }
// return expr;
// }
//
// public static List<Single> parseArguments(KaiperParser parser) {
// List<Single> arguments = new ArrayList<>();
//
// parser.eat(TokenType.LEFT_PAREN);
// if (!parser.match(TokenType.RIGHT_PAREN)) {
// do {
// arguments.add(parser.parseSingle());
// } while (parser.match(TokenType.COMMA));
// parser.eat(TokenType.RIGHT_PAREN);
// }
//
// return arguments;
// }
//
// public static List<ParameterData> parseParameters(KaiperParser parser) {
// List<ParameterData> parameters = new ArrayList<>();
//
// parser.eat(TokenType.LEFT_PAREN);
// if (!parser.match(TokenType.RIGHT_PAREN)) {
// Set<String> paramNames = new HashSet<>();
// boolean requireDef = false;
//
// do {
// ParameterData parameter = parseParameter(parser, requireDef);
//
// if (parameter.getDefault() != null) {
// requireDef = true;
// }
//
// if (paramNames.contains(parameter.getName())) {
// throw new SyntaxException("Duplicate parameter name", parser.getLast().getPosition());
// } else {
// paramNames.add(parameter.getName());
// }
//
// if (parameter.isRest() && parser.match(TokenType.COMMA)) {
// throw new SyntaxException("Rest parameters must be the last parameter",
// parser.peek(0).getPosition());
// }
//
// parameters.add(parameter);
// } while (parser.match(TokenType.COMMA));
// parser.match(TokenType.RIGHT_PAREN);
// }
//
// return parameters;
// }
//
// public static ParameterData parseParameter(KaiperParser parser, boolean requireDef) {
// boolean rest = parser.match(TokenType.REST);
//
// String parameterName = parser.eat(TokenType.IDENTIFIER).getString();
//
// Single parameterDefault = null;
//
// if (parser.match(TokenType.COLON)) {
// parser.parseIdentifier(); // keep as type hint, dont do anything
// }
//
// if (parser.match(TokenType.ASSIGN)) {
// if (parameterName.equals("this")) {
// throw new SyntaxException("Instance parameters can not have defaults", parser.getLast().getPosition());
// }
//
// parameterDefault = parser.parseSingle();
// } else if (requireDef) {
// throw new SyntaxException("All parameters after the first default requires a default",
// parser.peek(0).getPosition());
// }
//
// return new ParameterData(parameterName, parameterDefault, rest);
// }
// }
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/parslets/TypeParser.java
import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.ast.TypeNode;
import xyz.avarel.kaiper.ast.functions.ParameterData;
import xyz.avarel.kaiper.ast.value.NullNode;
import xyz.avarel.kaiper.ast.variables.Identifier;
import xyz.avarel.kaiper.lexer.Token;
import xyz.avarel.kaiper.lexer.TokenType;
import xyz.avarel.kaiper.parser.KaiperParser;
import xyz.avarel.kaiper.parser.KaiperParserUtils;
import xyz.avarel.kaiper.parser.PrefixParser;
import java.util.Collections;
import java.util.List;
package xyz.avarel.kaiper.parser.parslets;
/**
* type IDENTIFIER(params...) : SUPERTYPE(super params...) {
* // constructor expr
* }
*/
public class TypeParser implements PrefixParser {
@Override
public Expr parse(KaiperParser parser, Token token) { | String name = parser.eat(TokenType.IDENTIFIER).getString(); |
Avarel/Kaiper | Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/value/DecimalNode.java | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/ExprVisitor.java
// public interface ExprVisitor<R, C> {
// R visit(Statements expr, C scope);
//
// R visit(FunctionNode expr, C scope);
//
// R visit(Identifier expr, C scope);
//
// R visit(Invocation expr, C scope);
//
// R visit(BinaryOperation expr, C scope);
//
// R visit(UnaryOperation expr, C scope);
//
// R visit(RangeNode expr, C scope);
//
// R visit(ArrayNode expr, C scope);
//
// R visit(SliceOperation expr, C scope);
//
// R visit(AssignmentExpr expr, C scope);
//
// R visit(GetOperation expr, C scope);
//
// R visit(SetOperation expr, C scope);
//
// R visit(ReturnExpr expr, C scope);
//
// R visit(ConditionalExpr expr, C scope);
//
// R visit(ForEachExpr expr, C scope);
//
// R visit(DictionaryNode expr, C scope);
//
// R visit(NullNode expr, C scope);
//
// R visit(IntNode expr, C scope);
//
// R visit(DecimalNode expr, C scope);
//
// R visit(BooleanNode expr, C scope);
//
// R visit(StringNode expr, C scope);
//
// R visit(DeclarationExpr expr, C scope);
//
// R visit(ModuleNode expr, C scope);
//
// R visit(TypeNode expr, C scope);
//
// R visit(WhileExpr expr, C scope);
// }
| import xyz.avarel.kaiper.ast.ExprVisitor;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.lexer.Position; | /*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.ast.value;
public class DecimalNode extends Single {
private final double value;
public DecimalNode(Position position, double value) {
super(position);
this.value = value;
}
public double getValue() {
return value;
}
@Override | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/ExprVisitor.java
// public interface ExprVisitor<R, C> {
// R visit(Statements expr, C scope);
//
// R visit(FunctionNode expr, C scope);
//
// R visit(Identifier expr, C scope);
//
// R visit(Invocation expr, C scope);
//
// R visit(BinaryOperation expr, C scope);
//
// R visit(UnaryOperation expr, C scope);
//
// R visit(RangeNode expr, C scope);
//
// R visit(ArrayNode expr, C scope);
//
// R visit(SliceOperation expr, C scope);
//
// R visit(AssignmentExpr expr, C scope);
//
// R visit(GetOperation expr, C scope);
//
// R visit(SetOperation expr, C scope);
//
// R visit(ReturnExpr expr, C scope);
//
// R visit(ConditionalExpr expr, C scope);
//
// R visit(ForEachExpr expr, C scope);
//
// R visit(DictionaryNode expr, C scope);
//
// R visit(NullNode expr, C scope);
//
// R visit(IntNode expr, C scope);
//
// R visit(DecimalNode expr, C scope);
//
// R visit(BooleanNode expr, C scope);
//
// R visit(StringNode expr, C scope);
//
// R visit(DeclarationExpr expr, C scope);
//
// R visit(ModuleNode expr, C scope);
//
// R visit(TypeNode expr, C scope);
//
// R visit(WhileExpr expr, C scope);
// }
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/value/DecimalNode.java
import xyz.avarel.kaiper.ast.ExprVisitor;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.lexer.Position;
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.ast.value;
public class DecimalNode extends Single {
private final double value;
public DecimalNode(Position position, double value) {
super(position);
this.value = value;
}
public double getValue() {
return value;
}
@Override | public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) { |
Avarel/Kaiper | Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/parslets/functional/PipeBackwardParser.java | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/functions/FunctionNode.java
// public class FunctionNode extends Single {
// private final String name;
// private final List<ParameterData> parameters;
// private final Expr expr;
//
// public FunctionNode(Position position, List<ParameterData> parameters, Expr expr) {
// this(position, null, parameters, expr);
// }
//
// public FunctionNode(Position position, String name, List<ParameterData> parameters, Expr expr) {
// super(position);
// this.name = name;
// this.parameters = parameters;
// this.expr = expr;
// }
//
// public String getName() {
// return name;
// }
//
// public List<ParameterData> getParameterExprs() {
// return parameters;
// }
//
// public Expr getExpr() {
// return expr;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// builder.append(indent).append(isTail ? "└── " : "├── ")
// .append("func").append(name != null ? " " + name : "")
// .append('(')
// .append(getParameterExprs().stream().map(Object::toString)
// .collect(Collectors.joining(", ")))
// .append(')');
//
// builder.append('\n');
// expr.ast(builder, indent + (isTail ? " " : "│ "), true);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/invocation/Invocation.java
// public class Invocation extends Single {
// private final Single left;
// private final List<Single> arguments;
//
// public Invocation(Position position, Single left, List<Single> arguments) {
// super(position);
// this.left = left;
// this.arguments = arguments;
// }
//
// public Single getLeft() {
// return left;
// }
//
// public List<Single> getArguments() {
// return arguments;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// builder.append(indent).append(isTail ? "└── " : "├── ").append("invoke");
//
// builder.append('\n');
// left.ast("target", builder, indent + (isTail ? " " : "│ "), false);
//
// builder.append('\n');
// if (arguments.isEmpty()) {
// builder.append(indent).append(isTail ? " " : "│ ").append("└── ").append("*");
// } else {
// for (int i = 0; i < arguments.size() - 1; i++) {
// arguments.get(i).ast(builder, indent + (isTail ? " " : "│ "), false);
// builder.append('\n');
// }
// if (arguments.size() > 0) {
// arguments.get(arguments.size() - 1).ast(builder, indent + (isTail ? " " : "│ "), true);
// }
// }
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/BinaryParser.java
// public abstract class BinaryParser implements InfixParser {
// private final int precedence;
// private final boolean leftAssoc;
//
// public BinaryParser(int precedence) {
// this(precedence, true);
// }
//
// public BinaryParser(int precedence, boolean leftAssoc) {
// this.precedence = precedence;
// this.leftAssoc = leftAssoc;
// }
//
// @Override
// public Expr parse(KaiperParser parser, Expr left, Token token) {
// if (!(left instanceof Single)) {
// throw new SyntaxException("Internal compiler error", token.getPosition());
// }
// return parse(parser, (Single) left, token);
// }
//
// public abstract Expr parse(KaiperParser parser, Single left, Token token);
//
// @Override
// public int getPrecedence() {
// return precedence;
// }
//
// public boolean isLeftAssoc() {
// return leftAssoc;
// }
// }
| import xyz.avarel.kaiper.Precedence;
import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.ast.functions.FunctionNode;
import xyz.avarel.kaiper.ast.invocation.Invocation;
import xyz.avarel.kaiper.ast.variables.Identifier;
import xyz.avarel.kaiper.exceptions.SyntaxException;
import xyz.avarel.kaiper.lexer.Token;
import xyz.avarel.kaiper.parser.BinaryParser;
import xyz.avarel.kaiper.parser.KaiperParser;
import java.util.Collections; | /*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.parser.parslets.functional;
public class PipeBackwardParser extends BinaryParser {
public PipeBackwardParser() {
super(Precedence.INFIX);
}
@Override
public Expr parse(KaiperParser parser, Single left, Token token) {
if (!parser.getParserFlags().allowInvocation()) {
throw new SyntaxException("Function invocation are disabled");
}
Single right = parser.parseSingle(getPrecedence() - 1);
| // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/functions/FunctionNode.java
// public class FunctionNode extends Single {
// private final String name;
// private final List<ParameterData> parameters;
// private final Expr expr;
//
// public FunctionNode(Position position, List<ParameterData> parameters, Expr expr) {
// this(position, null, parameters, expr);
// }
//
// public FunctionNode(Position position, String name, List<ParameterData> parameters, Expr expr) {
// super(position);
// this.name = name;
// this.parameters = parameters;
// this.expr = expr;
// }
//
// public String getName() {
// return name;
// }
//
// public List<ParameterData> getParameterExprs() {
// return parameters;
// }
//
// public Expr getExpr() {
// return expr;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// builder.append(indent).append(isTail ? "└── " : "├── ")
// .append("func").append(name != null ? " " + name : "")
// .append('(')
// .append(getParameterExprs().stream().map(Object::toString)
// .collect(Collectors.joining(", ")))
// .append(')');
//
// builder.append('\n');
// expr.ast(builder, indent + (isTail ? " " : "│ "), true);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/invocation/Invocation.java
// public class Invocation extends Single {
// private final Single left;
// private final List<Single> arguments;
//
// public Invocation(Position position, Single left, List<Single> arguments) {
// super(position);
// this.left = left;
// this.arguments = arguments;
// }
//
// public Single getLeft() {
// return left;
// }
//
// public List<Single> getArguments() {
// return arguments;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// builder.append(indent).append(isTail ? "└── " : "├── ").append("invoke");
//
// builder.append('\n');
// left.ast("target", builder, indent + (isTail ? " " : "│ "), false);
//
// builder.append('\n');
// if (arguments.isEmpty()) {
// builder.append(indent).append(isTail ? " " : "│ ").append("└── ").append("*");
// } else {
// for (int i = 0; i < arguments.size() - 1; i++) {
// arguments.get(i).ast(builder, indent + (isTail ? " " : "│ "), false);
// builder.append('\n');
// }
// if (arguments.size() > 0) {
// arguments.get(arguments.size() - 1).ast(builder, indent + (isTail ? " " : "│ "), true);
// }
// }
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/BinaryParser.java
// public abstract class BinaryParser implements InfixParser {
// private final int precedence;
// private final boolean leftAssoc;
//
// public BinaryParser(int precedence) {
// this(precedence, true);
// }
//
// public BinaryParser(int precedence, boolean leftAssoc) {
// this.precedence = precedence;
// this.leftAssoc = leftAssoc;
// }
//
// @Override
// public Expr parse(KaiperParser parser, Expr left, Token token) {
// if (!(left instanceof Single)) {
// throw new SyntaxException("Internal compiler error", token.getPosition());
// }
// return parse(parser, (Single) left, token);
// }
//
// public abstract Expr parse(KaiperParser parser, Single left, Token token);
//
// @Override
// public int getPrecedence() {
// return precedence;
// }
//
// public boolean isLeftAssoc() {
// return leftAssoc;
// }
// }
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/parslets/functional/PipeBackwardParser.java
import xyz.avarel.kaiper.Precedence;
import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.ast.functions.FunctionNode;
import xyz.avarel.kaiper.ast.invocation.Invocation;
import xyz.avarel.kaiper.ast.variables.Identifier;
import xyz.avarel.kaiper.exceptions.SyntaxException;
import xyz.avarel.kaiper.lexer.Token;
import xyz.avarel.kaiper.parser.BinaryParser;
import xyz.avarel.kaiper.parser.KaiperParser;
import java.util.Collections;
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.parser.parslets.functional;
public class PipeBackwardParser extends BinaryParser {
public PipeBackwardParser() {
super(Precedence.INFIX);
}
@Override
public Expr parse(KaiperParser parser, Single left, Token token) {
if (!parser.getParserFlags().allowInvocation()) {
throw new SyntaxException("Function invocation are disabled");
}
Single right = parser.parseSingle(getPrecedence() - 1);
| if (left instanceof Invocation) { |
Avarel/Kaiper | Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/parslets/functional/PipeBackwardParser.java | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/functions/FunctionNode.java
// public class FunctionNode extends Single {
// private final String name;
// private final List<ParameterData> parameters;
// private final Expr expr;
//
// public FunctionNode(Position position, List<ParameterData> parameters, Expr expr) {
// this(position, null, parameters, expr);
// }
//
// public FunctionNode(Position position, String name, List<ParameterData> parameters, Expr expr) {
// super(position);
// this.name = name;
// this.parameters = parameters;
// this.expr = expr;
// }
//
// public String getName() {
// return name;
// }
//
// public List<ParameterData> getParameterExprs() {
// return parameters;
// }
//
// public Expr getExpr() {
// return expr;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// builder.append(indent).append(isTail ? "└── " : "├── ")
// .append("func").append(name != null ? " " + name : "")
// .append('(')
// .append(getParameterExprs().stream().map(Object::toString)
// .collect(Collectors.joining(", ")))
// .append(')');
//
// builder.append('\n');
// expr.ast(builder, indent + (isTail ? " " : "│ "), true);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/invocation/Invocation.java
// public class Invocation extends Single {
// private final Single left;
// private final List<Single> arguments;
//
// public Invocation(Position position, Single left, List<Single> arguments) {
// super(position);
// this.left = left;
// this.arguments = arguments;
// }
//
// public Single getLeft() {
// return left;
// }
//
// public List<Single> getArguments() {
// return arguments;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// builder.append(indent).append(isTail ? "└── " : "├── ").append("invoke");
//
// builder.append('\n');
// left.ast("target", builder, indent + (isTail ? " " : "│ "), false);
//
// builder.append('\n');
// if (arguments.isEmpty()) {
// builder.append(indent).append(isTail ? " " : "│ ").append("└── ").append("*");
// } else {
// for (int i = 0; i < arguments.size() - 1; i++) {
// arguments.get(i).ast(builder, indent + (isTail ? " " : "│ "), false);
// builder.append('\n');
// }
// if (arguments.size() > 0) {
// arguments.get(arguments.size() - 1).ast(builder, indent + (isTail ? " " : "│ "), true);
// }
// }
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/BinaryParser.java
// public abstract class BinaryParser implements InfixParser {
// private final int precedence;
// private final boolean leftAssoc;
//
// public BinaryParser(int precedence) {
// this(precedence, true);
// }
//
// public BinaryParser(int precedence, boolean leftAssoc) {
// this.precedence = precedence;
// this.leftAssoc = leftAssoc;
// }
//
// @Override
// public Expr parse(KaiperParser parser, Expr left, Token token) {
// if (!(left instanceof Single)) {
// throw new SyntaxException("Internal compiler error", token.getPosition());
// }
// return parse(parser, (Single) left, token);
// }
//
// public abstract Expr parse(KaiperParser parser, Single left, Token token);
//
// @Override
// public int getPrecedence() {
// return precedence;
// }
//
// public boolean isLeftAssoc() {
// return leftAssoc;
// }
// }
| import xyz.avarel.kaiper.Precedence;
import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.ast.functions.FunctionNode;
import xyz.avarel.kaiper.ast.invocation.Invocation;
import xyz.avarel.kaiper.ast.variables.Identifier;
import xyz.avarel.kaiper.exceptions.SyntaxException;
import xyz.avarel.kaiper.lexer.Token;
import xyz.avarel.kaiper.parser.BinaryParser;
import xyz.avarel.kaiper.parser.KaiperParser;
import java.util.Collections; | /*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.parser.parslets.functional;
public class PipeBackwardParser extends BinaryParser {
public PipeBackwardParser() {
super(Precedence.INFIX);
}
@Override
public Expr parse(KaiperParser parser, Single left, Token token) {
if (!parser.getParserFlags().allowInvocation()) {
throw new SyntaxException("Function invocation are disabled");
}
Single right = parser.parseSingle(getPrecedence() - 1);
if (left instanceof Invocation) {
((Invocation) left).getArguments().add(0, left);
return left; | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/functions/FunctionNode.java
// public class FunctionNode extends Single {
// private final String name;
// private final List<ParameterData> parameters;
// private final Expr expr;
//
// public FunctionNode(Position position, List<ParameterData> parameters, Expr expr) {
// this(position, null, parameters, expr);
// }
//
// public FunctionNode(Position position, String name, List<ParameterData> parameters, Expr expr) {
// super(position);
// this.name = name;
// this.parameters = parameters;
// this.expr = expr;
// }
//
// public String getName() {
// return name;
// }
//
// public List<ParameterData> getParameterExprs() {
// return parameters;
// }
//
// public Expr getExpr() {
// return expr;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// builder.append(indent).append(isTail ? "└── " : "├── ")
// .append("func").append(name != null ? " " + name : "")
// .append('(')
// .append(getParameterExprs().stream().map(Object::toString)
// .collect(Collectors.joining(", ")))
// .append(')');
//
// builder.append('\n');
// expr.ast(builder, indent + (isTail ? " " : "│ "), true);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/invocation/Invocation.java
// public class Invocation extends Single {
// private final Single left;
// private final List<Single> arguments;
//
// public Invocation(Position position, Single left, List<Single> arguments) {
// super(position);
// this.left = left;
// this.arguments = arguments;
// }
//
// public Single getLeft() {
// return left;
// }
//
// public List<Single> getArguments() {
// return arguments;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// builder.append(indent).append(isTail ? "└── " : "├── ").append("invoke");
//
// builder.append('\n');
// left.ast("target", builder, indent + (isTail ? " " : "│ "), false);
//
// builder.append('\n');
// if (arguments.isEmpty()) {
// builder.append(indent).append(isTail ? " " : "│ ").append("└── ").append("*");
// } else {
// for (int i = 0; i < arguments.size() - 1; i++) {
// arguments.get(i).ast(builder, indent + (isTail ? " " : "│ "), false);
// builder.append('\n');
// }
// if (arguments.size() > 0) {
// arguments.get(arguments.size() - 1).ast(builder, indent + (isTail ? " " : "│ "), true);
// }
// }
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/BinaryParser.java
// public abstract class BinaryParser implements InfixParser {
// private final int precedence;
// private final boolean leftAssoc;
//
// public BinaryParser(int precedence) {
// this(precedence, true);
// }
//
// public BinaryParser(int precedence, boolean leftAssoc) {
// this.precedence = precedence;
// this.leftAssoc = leftAssoc;
// }
//
// @Override
// public Expr parse(KaiperParser parser, Expr left, Token token) {
// if (!(left instanceof Single)) {
// throw new SyntaxException("Internal compiler error", token.getPosition());
// }
// return parse(parser, (Single) left, token);
// }
//
// public abstract Expr parse(KaiperParser parser, Single left, Token token);
//
// @Override
// public int getPrecedence() {
// return precedence;
// }
//
// public boolean isLeftAssoc() {
// return leftAssoc;
// }
// }
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/parslets/functional/PipeBackwardParser.java
import xyz.avarel.kaiper.Precedence;
import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.ast.functions.FunctionNode;
import xyz.avarel.kaiper.ast.invocation.Invocation;
import xyz.avarel.kaiper.ast.variables.Identifier;
import xyz.avarel.kaiper.exceptions.SyntaxException;
import xyz.avarel.kaiper.lexer.Token;
import xyz.avarel.kaiper.parser.BinaryParser;
import xyz.avarel.kaiper.parser.KaiperParser;
import java.util.Collections;
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.parser.parslets.functional;
public class PipeBackwardParser extends BinaryParser {
public PipeBackwardParser() {
super(Precedence.INFIX);
}
@Override
public Expr parse(KaiperParser parser, Single left, Token token) {
if (!parser.getParserFlags().allowInvocation()) {
throw new SyntaxException("Function invocation are disabled");
}
Single right = parser.parseSingle(getPrecedence() - 1);
if (left instanceof Invocation) {
((Invocation) left).getArguments().add(0, left);
return left; | } else if (left instanceof FunctionNode || left instanceof Identifier) { |
Avarel/Kaiper | Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/flow/Statements.java | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/ExprVisitor.java
// public interface ExprVisitor<R, C> {
// R visit(Statements expr, C scope);
//
// R visit(FunctionNode expr, C scope);
//
// R visit(Identifier expr, C scope);
//
// R visit(Invocation expr, C scope);
//
// R visit(BinaryOperation expr, C scope);
//
// R visit(UnaryOperation expr, C scope);
//
// R visit(RangeNode expr, C scope);
//
// R visit(ArrayNode expr, C scope);
//
// R visit(SliceOperation expr, C scope);
//
// R visit(AssignmentExpr expr, C scope);
//
// R visit(GetOperation expr, C scope);
//
// R visit(SetOperation expr, C scope);
//
// R visit(ReturnExpr expr, C scope);
//
// R visit(ConditionalExpr expr, C scope);
//
// R visit(ForEachExpr expr, C scope);
//
// R visit(DictionaryNode expr, C scope);
//
// R visit(NullNode expr, C scope);
//
// R visit(IntNode expr, C scope);
//
// R visit(DecimalNode expr, C scope);
//
// R visit(BooleanNode expr, C scope);
//
// R visit(StringNode expr, C scope);
//
// R visit(DeclarationExpr expr, C scope);
//
// R visit(ModuleNode expr, C scope);
//
// R visit(TypeNode expr, C scope);
//
// R visit(WhileExpr expr, C scope);
// }
| import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.ExprVisitor;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; | /*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.ast.flow;
public class Statements extends Expr implements Iterable<Expr> {
private final List<Expr> statements;
public Statements(Expr before, Expr after) {
super(before.getPosition());
this.statements = new ArrayList<>();
this.statements.add(before);
this.statements.add(after);
}
@Override
public Statements andThen(Expr after) {
if (after instanceof Statements) {
statements.addAll(((Statements) after).statements);
} else {
statements.add(after);
}
return this;
}
public List<Expr> getExprs() {
return statements;
}
@Override | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/ExprVisitor.java
// public interface ExprVisitor<R, C> {
// R visit(Statements expr, C scope);
//
// R visit(FunctionNode expr, C scope);
//
// R visit(Identifier expr, C scope);
//
// R visit(Invocation expr, C scope);
//
// R visit(BinaryOperation expr, C scope);
//
// R visit(UnaryOperation expr, C scope);
//
// R visit(RangeNode expr, C scope);
//
// R visit(ArrayNode expr, C scope);
//
// R visit(SliceOperation expr, C scope);
//
// R visit(AssignmentExpr expr, C scope);
//
// R visit(GetOperation expr, C scope);
//
// R visit(SetOperation expr, C scope);
//
// R visit(ReturnExpr expr, C scope);
//
// R visit(ConditionalExpr expr, C scope);
//
// R visit(ForEachExpr expr, C scope);
//
// R visit(DictionaryNode expr, C scope);
//
// R visit(NullNode expr, C scope);
//
// R visit(IntNode expr, C scope);
//
// R visit(DecimalNode expr, C scope);
//
// R visit(BooleanNode expr, C scope);
//
// R visit(StringNode expr, C scope);
//
// R visit(DeclarationExpr expr, C scope);
//
// R visit(ModuleNode expr, C scope);
//
// R visit(TypeNode expr, C scope);
//
// R visit(WhileExpr expr, C scope);
// }
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/flow/Statements.java
import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.ExprVisitor;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.ast.flow;
public class Statements extends Expr implements Iterable<Expr> {
private final List<Expr> statements;
public Statements(Expr before, Expr after) {
super(before.getPosition());
this.statements = new ArrayList<>();
this.statements.add(before);
this.statements.add(after);
}
@Override
public Statements andThen(Expr after) {
if (after instanceof Statements) {
statements.addAll(((Statements) after).statements);
} else {
statements.add(after);
}
return this;
}
public List<Expr> getExprs() {
return statements;
}
@Override | public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) { |
Avarel/Kaiper | Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/Null.java | // Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/modules/Module.java
// public abstract class Module implements Obj {
// public static final Type<Module> TYPE = new Type<>("Module");
//
// @Override
// public abstract Obj getAttr(String name);
//
// @Override
// public Type getType() {
// return TYPE;
// }
// }
//
// Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/modules/NativeModule.java
// public abstract class NativeModule extends Module {
// private final Map<String, Obj> map;
//
// protected NativeModule() {
// this.map = new HashMap<>();
// }
//
// public void declare(String name, Obj obj) {
// map.put(name, obj);
// }
//
// @Override
// public Obj getAttr(String name) {
// return map.getOrDefault(name, Null.VALUE);
// }
// }
//
// Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/types/Type.java
// @SuppressWarnings("unused")
// public class Type<T> implements Obj {
// public static final Type<Type> TYPE = new Type<Type>("Type") {
// @Override
// public Type getParent() {
// return Obj.TYPE;
// }
// };
//
// private final Type parent;
// private final String name;
// private final Constructor constructor;
//
// public Type(String name) {
// this(name, null);
// }
//
// public Type(String name, Constructor constructor) {
// this(Obj.TYPE, name, constructor);
// }
//
// public Type(Type parent, String name) {
// this(parent, name, null);
// }
//
// public Type(Type parent, String name, Constructor constructor) {
// this.parent = parent;
// this.name = name;
// this.constructor = constructor;
// if (constructor != null) constructor.targetType = this;
// }
//
// public boolean is(Type type) {
// Type t = this;
// do {
// if (t.equals(type)) return true;
// t = t.getParent();
// } while (t != null);
// return false;
// }
//
//
// public Constructor getConstructor() {
// return constructor;
// }
//
// @Override
// public Type getType() {
// return TYPE;
// }
//
// @Override
// public Type toJava() {
// return this;
// }
//
// public Type getParent() {
// return parent;
// }
//
// public boolean hasParent() {
// return getParent() != null;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return name;
// }
//
// public String toExtendedString() {
// if (parent != null) {
// return name + ": " + parent;
// } else {
// return name;
// }
// }
//
// @Override
// public Obj invoke(List<Obj> arguments) {
// if (constructor == null) {
// throw new ComputeException(toString() + " does not support instantiation");
// } else {
// return constructor.invoke(arguments);
// }
// }
// }
| import xyz.avarel.kaiper.runtime.modules.Module;
import xyz.avarel.kaiper.runtime.modules.NativeModule;
import xyz.avarel.kaiper.runtime.types.Type; | /*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.runtime;
/**
* Every operation results in the same
* instance, NOTHING.
*/
public enum Null implements Obj {
VALUE;
| // Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/modules/Module.java
// public abstract class Module implements Obj {
// public static final Type<Module> TYPE = new Type<>("Module");
//
// @Override
// public abstract Obj getAttr(String name);
//
// @Override
// public Type getType() {
// return TYPE;
// }
// }
//
// Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/modules/NativeModule.java
// public abstract class NativeModule extends Module {
// private final Map<String, Obj> map;
//
// protected NativeModule() {
// this.map = new HashMap<>();
// }
//
// public void declare(String name, Obj obj) {
// map.put(name, obj);
// }
//
// @Override
// public Obj getAttr(String name) {
// return map.getOrDefault(name, Null.VALUE);
// }
// }
//
// Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/types/Type.java
// @SuppressWarnings("unused")
// public class Type<T> implements Obj {
// public static final Type<Type> TYPE = new Type<Type>("Type") {
// @Override
// public Type getParent() {
// return Obj.TYPE;
// }
// };
//
// private final Type parent;
// private final String name;
// private final Constructor constructor;
//
// public Type(String name) {
// this(name, null);
// }
//
// public Type(String name, Constructor constructor) {
// this(Obj.TYPE, name, constructor);
// }
//
// public Type(Type parent, String name) {
// this(parent, name, null);
// }
//
// public Type(Type parent, String name, Constructor constructor) {
// this.parent = parent;
// this.name = name;
// this.constructor = constructor;
// if (constructor != null) constructor.targetType = this;
// }
//
// public boolean is(Type type) {
// Type t = this;
// do {
// if (t.equals(type)) return true;
// t = t.getParent();
// } while (t != null);
// return false;
// }
//
//
// public Constructor getConstructor() {
// return constructor;
// }
//
// @Override
// public Type getType() {
// return TYPE;
// }
//
// @Override
// public Type toJava() {
// return this;
// }
//
// public Type getParent() {
// return parent;
// }
//
// public boolean hasParent() {
// return getParent() != null;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return name;
// }
//
// public String toExtendedString() {
// if (parent != null) {
// return name + ": " + parent;
// } else {
// return name;
// }
// }
//
// @Override
// public Obj invoke(List<Obj> arguments) {
// if (constructor == null) {
// throw new ComputeException(toString() + " does not support instantiation");
// } else {
// return constructor.invoke(arguments);
// }
// }
// }
// Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/Null.java
import xyz.avarel.kaiper.runtime.modules.Module;
import xyz.avarel.kaiper.runtime.modules.NativeModule;
import xyz.avarel.kaiper.runtime.types.Type;
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.runtime;
/**
* Every operation results in the same
* instance, NOTHING.
*/
public enum Null implements Obj {
VALUE;
| public static final Type<Null> TYPE = new Type<>("Null"); |
Avarel/Kaiper | Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/Null.java | // Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/modules/Module.java
// public abstract class Module implements Obj {
// public static final Type<Module> TYPE = new Type<>("Module");
//
// @Override
// public abstract Obj getAttr(String name);
//
// @Override
// public Type getType() {
// return TYPE;
// }
// }
//
// Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/modules/NativeModule.java
// public abstract class NativeModule extends Module {
// private final Map<String, Obj> map;
//
// protected NativeModule() {
// this.map = new HashMap<>();
// }
//
// public void declare(String name, Obj obj) {
// map.put(name, obj);
// }
//
// @Override
// public Obj getAttr(String name) {
// return map.getOrDefault(name, Null.VALUE);
// }
// }
//
// Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/types/Type.java
// @SuppressWarnings("unused")
// public class Type<T> implements Obj {
// public static final Type<Type> TYPE = new Type<Type>("Type") {
// @Override
// public Type getParent() {
// return Obj.TYPE;
// }
// };
//
// private final Type parent;
// private final String name;
// private final Constructor constructor;
//
// public Type(String name) {
// this(name, null);
// }
//
// public Type(String name, Constructor constructor) {
// this(Obj.TYPE, name, constructor);
// }
//
// public Type(Type parent, String name) {
// this(parent, name, null);
// }
//
// public Type(Type parent, String name, Constructor constructor) {
// this.parent = parent;
// this.name = name;
// this.constructor = constructor;
// if (constructor != null) constructor.targetType = this;
// }
//
// public boolean is(Type type) {
// Type t = this;
// do {
// if (t.equals(type)) return true;
// t = t.getParent();
// } while (t != null);
// return false;
// }
//
//
// public Constructor getConstructor() {
// return constructor;
// }
//
// @Override
// public Type getType() {
// return TYPE;
// }
//
// @Override
// public Type toJava() {
// return this;
// }
//
// public Type getParent() {
// return parent;
// }
//
// public boolean hasParent() {
// return getParent() != null;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return name;
// }
//
// public String toExtendedString() {
// if (parent != null) {
// return name + ": " + parent;
// } else {
// return name;
// }
// }
//
// @Override
// public Obj invoke(List<Obj> arguments) {
// if (constructor == null) {
// throw new ComputeException(toString() + " does not support instantiation");
// } else {
// return constructor.invoke(arguments);
// }
// }
// }
| import xyz.avarel.kaiper.runtime.modules.Module;
import xyz.avarel.kaiper.runtime.modules.NativeModule;
import xyz.avarel.kaiper.runtime.types.Type; | /*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.runtime;
/**
* Every operation results in the same
* instance, NOTHING.
*/
public enum Null implements Obj {
VALUE;
public static final Type<Null> TYPE = new Type<>("Null"); | // Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/modules/Module.java
// public abstract class Module implements Obj {
// public static final Type<Module> TYPE = new Type<>("Module");
//
// @Override
// public abstract Obj getAttr(String name);
//
// @Override
// public Type getType() {
// return TYPE;
// }
// }
//
// Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/modules/NativeModule.java
// public abstract class NativeModule extends Module {
// private final Map<String, Obj> map;
//
// protected NativeModule() {
// this.map = new HashMap<>();
// }
//
// public void declare(String name, Obj obj) {
// map.put(name, obj);
// }
//
// @Override
// public Obj getAttr(String name) {
// return map.getOrDefault(name, Null.VALUE);
// }
// }
//
// Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/types/Type.java
// @SuppressWarnings("unused")
// public class Type<T> implements Obj {
// public static final Type<Type> TYPE = new Type<Type>("Type") {
// @Override
// public Type getParent() {
// return Obj.TYPE;
// }
// };
//
// private final Type parent;
// private final String name;
// private final Constructor constructor;
//
// public Type(String name) {
// this(name, null);
// }
//
// public Type(String name, Constructor constructor) {
// this(Obj.TYPE, name, constructor);
// }
//
// public Type(Type parent, String name) {
// this(parent, name, null);
// }
//
// public Type(Type parent, String name, Constructor constructor) {
// this.parent = parent;
// this.name = name;
// this.constructor = constructor;
// if (constructor != null) constructor.targetType = this;
// }
//
// public boolean is(Type type) {
// Type t = this;
// do {
// if (t.equals(type)) return true;
// t = t.getParent();
// } while (t != null);
// return false;
// }
//
//
// public Constructor getConstructor() {
// return constructor;
// }
//
// @Override
// public Type getType() {
// return TYPE;
// }
//
// @Override
// public Type toJava() {
// return this;
// }
//
// public Type getParent() {
// return parent;
// }
//
// public boolean hasParent() {
// return getParent() != null;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return name;
// }
//
// public String toExtendedString() {
// if (parent != null) {
// return name + ": " + parent;
// } else {
// return name;
// }
// }
//
// @Override
// public Obj invoke(List<Obj> arguments) {
// if (constructor == null) {
// throw new ComputeException(toString() + " does not support instantiation");
// } else {
// return constructor.invoke(arguments);
// }
// }
// }
// Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/Null.java
import xyz.avarel.kaiper.runtime.modules.Module;
import xyz.avarel.kaiper.runtime.modules.NativeModule;
import xyz.avarel.kaiper.runtime.types.Type;
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.runtime;
/**
* Every operation results in the same
* instance, NOTHING.
*/
public enum Null implements Obj {
VALUE;
public static final Type<Null> TYPE = new Type<>("Null"); | public static final Module MODULE = new NativeModule() {{ |
Avarel/Kaiper | Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/Null.java | // Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/modules/Module.java
// public abstract class Module implements Obj {
// public static final Type<Module> TYPE = new Type<>("Module");
//
// @Override
// public abstract Obj getAttr(String name);
//
// @Override
// public Type getType() {
// return TYPE;
// }
// }
//
// Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/modules/NativeModule.java
// public abstract class NativeModule extends Module {
// private final Map<String, Obj> map;
//
// protected NativeModule() {
// this.map = new HashMap<>();
// }
//
// public void declare(String name, Obj obj) {
// map.put(name, obj);
// }
//
// @Override
// public Obj getAttr(String name) {
// return map.getOrDefault(name, Null.VALUE);
// }
// }
//
// Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/types/Type.java
// @SuppressWarnings("unused")
// public class Type<T> implements Obj {
// public static final Type<Type> TYPE = new Type<Type>("Type") {
// @Override
// public Type getParent() {
// return Obj.TYPE;
// }
// };
//
// private final Type parent;
// private final String name;
// private final Constructor constructor;
//
// public Type(String name) {
// this(name, null);
// }
//
// public Type(String name, Constructor constructor) {
// this(Obj.TYPE, name, constructor);
// }
//
// public Type(Type parent, String name) {
// this(parent, name, null);
// }
//
// public Type(Type parent, String name, Constructor constructor) {
// this.parent = parent;
// this.name = name;
// this.constructor = constructor;
// if (constructor != null) constructor.targetType = this;
// }
//
// public boolean is(Type type) {
// Type t = this;
// do {
// if (t.equals(type)) return true;
// t = t.getParent();
// } while (t != null);
// return false;
// }
//
//
// public Constructor getConstructor() {
// return constructor;
// }
//
// @Override
// public Type getType() {
// return TYPE;
// }
//
// @Override
// public Type toJava() {
// return this;
// }
//
// public Type getParent() {
// return parent;
// }
//
// public boolean hasParent() {
// return getParent() != null;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return name;
// }
//
// public String toExtendedString() {
// if (parent != null) {
// return name + ": " + parent;
// } else {
// return name;
// }
// }
//
// @Override
// public Obj invoke(List<Obj> arguments) {
// if (constructor == null) {
// throw new ComputeException(toString() + " does not support instantiation");
// } else {
// return constructor.invoke(arguments);
// }
// }
// }
| import xyz.avarel.kaiper.runtime.modules.Module;
import xyz.avarel.kaiper.runtime.modules.NativeModule;
import xyz.avarel.kaiper.runtime.types.Type; | /*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.runtime;
/**
* Every operation results in the same
* instance, NOTHING.
*/
public enum Null implements Obj {
VALUE;
public static final Type<Null> TYPE = new Type<>("Null"); | // Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/modules/Module.java
// public abstract class Module implements Obj {
// public static final Type<Module> TYPE = new Type<>("Module");
//
// @Override
// public abstract Obj getAttr(String name);
//
// @Override
// public Type getType() {
// return TYPE;
// }
// }
//
// Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/modules/NativeModule.java
// public abstract class NativeModule extends Module {
// private final Map<String, Obj> map;
//
// protected NativeModule() {
// this.map = new HashMap<>();
// }
//
// public void declare(String name, Obj obj) {
// map.put(name, obj);
// }
//
// @Override
// public Obj getAttr(String name) {
// return map.getOrDefault(name, Null.VALUE);
// }
// }
//
// Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/types/Type.java
// @SuppressWarnings("unused")
// public class Type<T> implements Obj {
// public static final Type<Type> TYPE = new Type<Type>("Type") {
// @Override
// public Type getParent() {
// return Obj.TYPE;
// }
// };
//
// private final Type parent;
// private final String name;
// private final Constructor constructor;
//
// public Type(String name) {
// this(name, null);
// }
//
// public Type(String name, Constructor constructor) {
// this(Obj.TYPE, name, constructor);
// }
//
// public Type(Type parent, String name) {
// this(parent, name, null);
// }
//
// public Type(Type parent, String name, Constructor constructor) {
// this.parent = parent;
// this.name = name;
// this.constructor = constructor;
// if (constructor != null) constructor.targetType = this;
// }
//
// public boolean is(Type type) {
// Type t = this;
// do {
// if (t.equals(type)) return true;
// t = t.getParent();
// } while (t != null);
// return false;
// }
//
//
// public Constructor getConstructor() {
// return constructor;
// }
//
// @Override
// public Type getType() {
// return TYPE;
// }
//
// @Override
// public Type toJava() {
// return this;
// }
//
// public Type getParent() {
// return parent;
// }
//
// public boolean hasParent() {
// return getParent() != null;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return name;
// }
//
// public String toExtendedString() {
// if (parent != null) {
// return name + ": " + parent;
// } else {
// return name;
// }
// }
//
// @Override
// public Obj invoke(List<Obj> arguments) {
// if (constructor == null) {
// throw new ComputeException(toString() + " does not support instantiation");
// } else {
// return constructor.invoke(arguments);
// }
// }
// }
// Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/Null.java
import xyz.avarel.kaiper.runtime.modules.Module;
import xyz.avarel.kaiper.runtime.modules.NativeModule;
import xyz.avarel.kaiper.runtime.types.Type;
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.runtime;
/**
* Every operation results in the same
* instance, NOTHING.
*/
public enum Null implements Obj {
VALUE;
public static final Type<Null> TYPE = new Type<>("Null"); | public static final Module MODULE = new NativeModule() {{ |
Avarel/Kaiper | Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/parslets/flow/ForEachParser.java | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/flow/ForEachExpr.java
// public class ForEachExpr extends Single {
// private final String variant;
// private final Single iterable;
// private final Expr action;
//
// public ForEachExpr(Position position, String variant, Single iterable, Expr action) {
// super(position);
// this.variant = variant;
// this.iterable = iterable;
// this.action = action;
// }
//
// public String getVariant() {
// return variant;
// }
//
// public Single getIterable() {
// return iterable;
// }
//
// public Expr getAction() {
// return action;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// builder.append(indent).append(isTail ? "└── " : "├── ").append("for each");
//
// builder.append('\n');
// builder.append(indent).append(isTail ? " " : "│ ").append("├── variant: ").append(variant);
//
// builder.append('\n');
// iterable.ast("iterable", builder, indent + (isTail ? " " : "│ "), false);
//
// builder.append('\n');
// action.ast("action", builder, indent + (isTail ? " " : "│ "), true);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/value/NullNode.java
// public class NullNode extends Single {
// public static final NullNode VALUE = new NullNode();
//
// private NullNode() {
// super(null);
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/lexer/TokenType.java
// public enum TokenType {
// // PAIRS
// LEFT_PAREN,
// RIGHT_PAREN,
//
// LEFT_BRACKET,
// RIGHT_BRACKET,
//
// LEFT_BRACE,
// RIGHT_BRACE,
//
// OPTIONAL_ASSIGN,
// ELVIS,
//
// // ASSIGNMENT
// ASSIGN,
//
// // TYPES
// INT,
// NUMBER,
// BOOLEAN,
// FUNCTION,
// STRING,
// ATOM,
//
// // ARITHMETIC
// PLUS,
// MINUS,
// ASTERISK,
// SLASH,
// BACKSLASH,
// CARET,
// PERCENT,
//
// // RELATIONAL
// EQUALS,
// NOT_EQUAL,
// GT,
// GTE,
// LT,
// LTE,
// OR,
// AND,
//
// // BOOLEAN
// AMPERSAND,
// VERTICAL_BAR,
//
// // MISC
// REST,
// RANGE_TO,
// PIPE_FORWARD,
// PIPE_BACKWARD,
// SHIFT_RIGHT,
// SHIFT_LEFT,
// ARROW,
// TILDE,
// BANG,
// QUESTION,
// COLON,
// COMMA,
// DOT,
//
// UNDERSCORE,
//
// // SCRIPT
// MODULE,
// TYPE,
// IDENTIFIER,
// NULL,
// LET,
// RETURN,
// IF,
// ELSE,
// FOR,
//
// LINE,
// EOF,
// }
| import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.ast.flow.ForEachExpr;
import xyz.avarel.kaiper.ast.value.NullNode;
import xyz.avarel.kaiper.exceptions.SyntaxException;
import xyz.avarel.kaiper.lexer.Token;
import xyz.avarel.kaiper.lexer.TokenType;
import xyz.avarel.kaiper.parser.KaiperParser;
import xyz.avarel.kaiper.parser.PrefixParser; | /*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.parser.parslets.flow;
public class ForEachParser implements PrefixParser {
@Override
public Expr parse(KaiperParser parser, Token token) {
if (!parser.getParserFlags().allowControlFlows()) {
throw new SyntaxException("Control flows are disabled");
} else if (!parser.getParserFlags().allowLoops()) {
throw new SyntaxException("Loops are disabled");
}
| // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/flow/ForEachExpr.java
// public class ForEachExpr extends Single {
// private final String variant;
// private final Single iterable;
// private final Expr action;
//
// public ForEachExpr(Position position, String variant, Single iterable, Expr action) {
// super(position);
// this.variant = variant;
// this.iterable = iterable;
// this.action = action;
// }
//
// public String getVariant() {
// return variant;
// }
//
// public Single getIterable() {
// return iterable;
// }
//
// public Expr getAction() {
// return action;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// builder.append(indent).append(isTail ? "└── " : "├── ").append("for each");
//
// builder.append('\n');
// builder.append(indent).append(isTail ? " " : "│ ").append("├── variant: ").append(variant);
//
// builder.append('\n');
// iterable.ast("iterable", builder, indent + (isTail ? " " : "│ "), false);
//
// builder.append('\n');
// action.ast("action", builder, indent + (isTail ? " " : "│ "), true);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/value/NullNode.java
// public class NullNode extends Single {
// public static final NullNode VALUE = new NullNode();
//
// private NullNode() {
// super(null);
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/lexer/TokenType.java
// public enum TokenType {
// // PAIRS
// LEFT_PAREN,
// RIGHT_PAREN,
//
// LEFT_BRACKET,
// RIGHT_BRACKET,
//
// LEFT_BRACE,
// RIGHT_BRACE,
//
// OPTIONAL_ASSIGN,
// ELVIS,
//
// // ASSIGNMENT
// ASSIGN,
//
// // TYPES
// INT,
// NUMBER,
// BOOLEAN,
// FUNCTION,
// STRING,
// ATOM,
//
// // ARITHMETIC
// PLUS,
// MINUS,
// ASTERISK,
// SLASH,
// BACKSLASH,
// CARET,
// PERCENT,
//
// // RELATIONAL
// EQUALS,
// NOT_EQUAL,
// GT,
// GTE,
// LT,
// LTE,
// OR,
// AND,
//
// // BOOLEAN
// AMPERSAND,
// VERTICAL_BAR,
//
// // MISC
// REST,
// RANGE_TO,
// PIPE_FORWARD,
// PIPE_BACKWARD,
// SHIFT_RIGHT,
// SHIFT_LEFT,
// ARROW,
// TILDE,
// BANG,
// QUESTION,
// COLON,
// COMMA,
// DOT,
//
// UNDERSCORE,
//
// // SCRIPT
// MODULE,
// TYPE,
// IDENTIFIER,
// NULL,
// LET,
// RETURN,
// IF,
// ELSE,
// FOR,
//
// LINE,
// EOF,
// }
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/parslets/flow/ForEachParser.java
import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.ast.flow.ForEachExpr;
import xyz.avarel.kaiper.ast.value.NullNode;
import xyz.avarel.kaiper.exceptions.SyntaxException;
import xyz.avarel.kaiper.lexer.Token;
import xyz.avarel.kaiper.lexer.TokenType;
import xyz.avarel.kaiper.parser.KaiperParser;
import xyz.avarel.kaiper.parser.PrefixParser;
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.parser.parslets.flow;
public class ForEachParser implements PrefixParser {
@Override
public Expr parse(KaiperParser parser, Token token) {
if (!parser.getParserFlags().allowControlFlows()) {
throw new SyntaxException("Control flows are disabled");
} else if (!parser.getParserFlags().allowLoops()) {
throw new SyntaxException("Loops are disabled");
}
| parser.eat(TokenType.LEFT_PAREN); |
Avarel/Kaiper | Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/parslets/flow/ForEachParser.java | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/flow/ForEachExpr.java
// public class ForEachExpr extends Single {
// private final String variant;
// private final Single iterable;
// private final Expr action;
//
// public ForEachExpr(Position position, String variant, Single iterable, Expr action) {
// super(position);
// this.variant = variant;
// this.iterable = iterable;
// this.action = action;
// }
//
// public String getVariant() {
// return variant;
// }
//
// public Single getIterable() {
// return iterable;
// }
//
// public Expr getAction() {
// return action;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// builder.append(indent).append(isTail ? "└── " : "├── ").append("for each");
//
// builder.append('\n');
// builder.append(indent).append(isTail ? " " : "│ ").append("├── variant: ").append(variant);
//
// builder.append('\n');
// iterable.ast("iterable", builder, indent + (isTail ? " " : "│ "), false);
//
// builder.append('\n');
// action.ast("action", builder, indent + (isTail ? " " : "│ "), true);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/value/NullNode.java
// public class NullNode extends Single {
// public static final NullNode VALUE = new NullNode();
//
// private NullNode() {
// super(null);
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/lexer/TokenType.java
// public enum TokenType {
// // PAIRS
// LEFT_PAREN,
// RIGHT_PAREN,
//
// LEFT_BRACKET,
// RIGHT_BRACKET,
//
// LEFT_BRACE,
// RIGHT_BRACE,
//
// OPTIONAL_ASSIGN,
// ELVIS,
//
// // ASSIGNMENT
// ASSIGN,
//
// // TYPES
// INT,
// NUMBER,
// BOOLEAN,
// FUNCTION,
// STRING,
// ATOM,
//
// // ARITHMETIC
// PLUS,
// MINUS,
// ASTERISK,
// SLASH,
// BACKSLASH,
// CARET,
// PERCENT,
//
// // RELATIONAL
// EQUALS,
// NOT_EQUAL,
// GT,
// GTE,
// LT,
// LTE,
// OR,
// AND,
//
// // BOOLEAN
// AMPERSAND,
// VERTICAL_BAR,
//
// // MISC
// REST,
// RANGE_TO,
// PIPE_FORWARD,
// PIPE_BACKWARD,
// SHIFT_RIGHT,
// SHIFT_LEFT,
// ARROW,
// TILDE,
// BANG,
// QUESTION,
// COLON,
// COMMA,
// DOT,
//
// UNDERSCORE,
//
// // SCRIPT
// MODULE,
// TYPE,
// IDENTIFIER,
// NULL,
// LET,
// RETURN,
// IF,
// ELSE,
// FOR,
//
// LINE,
// EOF,
// }
| import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.ast.flow.ForEachExpr;
import xyz.avarel.kaiper.ast.value.NullNode;
import xyz.avarel.kaiper.exceptions.SyntaxException;
import xyz.avarel.kaiper.lexer.Token;
import xyz.avarel.kaiper.lexer.TokenType;
import xyz.avarel.kaiper.parser.KaiperParser;
import xyz.avarel.kaiper.parser.PrefixParser; | /*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.parser.parslets.flow;
public class ForEachParser implements PrefixParser {
@Override
public Expr parse(KaiperParser parser, Token token) {
if (!parser.getParserFlags().allowControlFlows()) {
throw new SyntaxException("Control flows are disabled");
} else if (!parser.getParserFlags().allowLoops()) {
throw new SyntaxException("Loops are disabled");
}
parser.eat(TokenType.LEFT_PAREN);
String variant = parser.eat(TokenType.IDENTIFIER).getString();
parser.eatSoftKeyword("in");
Single iterable = parser.parseSingle();
parser.eat(TokenType.RIGHT_PAREN);
Expr expr;
if (parser.match(TokenType.LEFT_BRACE)) {
if (!parser.match(TokenType.RIGHT_BRACE)) {
expr = parser.parseStatements();
parser.eat(TokenType.RIGHT_BRACE);
} else { | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/flow/ForEachExpr.java
// public class ForEachExpr extends Single {
// private final String variant;
// private final Single iterable;
// private final Expr action;
//
// public ForEachExpr(Position position, String variant, Single iterable, Expr action) {
// super(position);
// this.variant = variant;
// this.iterable = iterable;
// this.action = action;
// }
//
// public String getVariant() {
// return variant;
// }
//
// public Single getIterable() {
// return iterable;
// }
//
// public Expr getAction() {
// return action;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// builder.append(indent).append(isTail ? "└── " : "├── ").append("for each");
//
// builder.append('\n');
// builder.append(indent).append(isTail ? " " : "│ ").append("├── variant: ").append(variant);
//
// builder.append('\n');
// iterable.ast("iterable", builder, indent + (isTail ? " " : "│ "), false);
//
// builder.append('\n');
// action.ast("action", builder, indent + (isTail ? " " : "│ "), true);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/value/NullNode.java
// public class NullNode extends Single {
// public static final NullNode VALUE = new NullNode();
//
// private NullNode() {
// super(null);
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/lexer/TokenType.java
// public enum TokenType {
// // PAIRS
// LEFT_PAREN,
// RIGHT_PAREN,
//
// LEFT_BRACKET,
// RIGHT_BRACKET,
//
// LEFT_BRACE,
// RIGHT_BRACE,
//
// OPTIONAL_ASSIGN,
// ELVIS,
//
// // ASSIGNMENT
// ASSIGN,
//
// // TYPES
// INT,
// NUMBER,
// BOOLEAN,
// FUNCTION,
// STRING,
// ATOM,
//
// // ARITHMETIC
// PLUS,
// MINUS,
// ASTERISK,
// SLASH,
// BACKSLASH,
// CARET,
// PERCENT,
//
// // RELATIONAL
// EQUALS,
// NOT_EQUAL,
// GT,
// GTE,
// LT,
// LTE,
// OR,
// AND,
//
// // BOOLEAN
// AMPERSAND,
// VERTICAL_BAR,
//
// // MISC
// REST,
// RANGE_TO,
// PIPE_FORWARD,
// PIPE_BACKWARD,
// SHIFT_RIGHT,
// SHIFT_LEFT,
// ARROW,
// TILDE,
// BANG,
// QUESTION,
// COLON,
// COMMA,
// DOT,
//
// UNDERSCORE,
//
// // SCRIPT
// MODULE,
// TYPE,
// IDENTIFIER,
// NULL,
// LET,
// RETURN,
// IF,
// ELSE,
// FOR,
//
// LINE,
// EOF,
// }
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/parslets/flow/ForEachParser.java
import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.ast.flow.ForEachExpr;
import xyz.avarel.kaiper.ast.value.NullNode;
import xyz.avarel.kaiper.exceptions.SyntaxException;
import xyz.avarel.kaiper.lexer.Token;
import xyz.avarel.kaiper.lexer.TokenType;
import xyz.avarel.kaiper.parser.KaiperParser;
import xyz.avarel.kaiper.parser.PrefixParser;
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.parser.parslets.flow;
public class ForEachParser implements PrefixParser {
@Override
public Expr parse(KaiperParser parser, Token token) {
if (!parser.getParserFlags().allowControlFlows()) {
throw new SyntaxException("Control flows are disabled");
} else if (!parser.getParserFlags().allowLoops()) {
throw new SyntaxException("Loops are disabled");
}
parser.eat(TokenType.LEFT_PAREN);
String variant = parser.eat(TokenType.IDENTIFIER).getString();
parser.eatSoftKeyword("in");
Single iterable = parser.parseSingle();
parser.eat(TokenType.RIGHT_PAREN);
Expr expr;
if (parser.match(TokenType.LEFT_BRACE)) {
if (!parser.match(TokenType.RIGHT_BRACE)) {
expr = parser.parseStatements();
parser.eat(TokenType.RIGHT_BRACE);
} else { | expr = NullNode.VALUE; |
Avarel/Kaiper | Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/parslets/flow/ForEachParser.java | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/flow/ForEachExpr.java
// public class ForEachExpr extends Single {
// private final String variant;
// private final Single iterable;
// private final Expr action;
//
// public ForEachExpr(Position position, String variant, Single iterable, Expr action) {
// super(position);
// this.variant = variant;
// this.iterable = iterable;
// this.action = action;
// }
//
// public String getVariant() {
// return variant;
// }
//
// public Single getIterable() {
// return iterable;
// }
//
// public Expr getAction() {
// return action;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// builder.append(indent).append(isTail ? "└── " : "├── ").append("for each");
//
// builder.append('\n');
// builder.append(indent).append(isTail ? " " : "│ ").append("├── variant: ").append(variant);
//
// builder.append('\n');
// iterable.ast("iterable", builder, indent + (isTail ? " " : "│ "), false);
//
// builder.append('\n');
// action.ast("action", builder, indent + (isTail ? " " : "│ "), true);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/value/NullNode.java
// public class NullNode extends Single {
// public static final NullNode VALUE = new NullNode();
//
// private NullNode() {
// super(null);
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/lexer/TokenType.java
// public enum TokenType {
// // PAIRS
// LEFT_PAREN,
// RIGHT_PAREN,
//
// LEFT_BRACKET,
// RIGHT_BRACKET,
//
// LEFT_BRACE,
// RIGHT_BRACE,
//
// OPTIONAL_ASSIGN,
// ELVIS,
//
// // ASSIGNMENT
// ASSIGN,
//
// // TYPES
// INT,
// NUMBER,
// BOOLEAN,
// FUNCTION,
// STRING,
// ATOM,
//
// // ARITHMETIC
// PLUS,
// MINUS,
// ASTERISK,
// SLASH,
// BACKSLASH,
// CARET,
// PERCENT,
//
// // RELATIONAL
// EQUALS,
// NOT_EQUAL,
// GT,
// GTE,
// LT,
// LTE,
// OR,
// AND,
//
// // BOOLEAN
// AMPERSAND,
// VERTICAL_BAR,
//
// // MISC
// REST,
// RANGE_TO,
// PIPE_FORWARD,
// PIPE_BACKWARD,
// SHIFT_RIGHT,
// SHIFT_LEFT,
// ARROW,
// TILDE,
// BANG,
// QUESTION,
// COLON,
// COMMA,
// DOT,
//
// UNDERSCORE,
//
// // SCRIPT
// MODULE,
// TYPE,
// IDENTIFIER,
// NULL,
// LET,
// RETURN,
// IF,
// ELSE,
// FOR,
//
// LINE,
// EOF,
// }
| import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.ast.flow.ForEachExpr;
import xyz.avarel.kaiper.ast.value.NullNode;
import xyz.avarel.kaiper.exceptions.SyntaxException;
import xyz.avarel.kaiper.lexer.Token;
import xyz.avarel.kaiper.lexer.TokenType;
import xyz.avarel.kaiper.parser.KaiperParser;
import xyz.avarel.kaiper.parser.PrefixParser; | /*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.parser.parslets.flow;
public class ForEachParser implements PrefixParser {
@Override
public Expr parse(KaiperParser parser, Token token) {
if (!parser.getParserFlags().allowControlFlows()) {
throw new SyntaxException("Control flows are disabled");
} else if (!parser.getParserFlags().allowLoops()) {
throw new SyntaxException("Loops are disabled");
}
parser.eat(TokenType.LEFT_PAREN);
String variant = parser.eat(TokenType.IDENTIFIER).getString();
parser.eatSoftKeyword("in");
Single iterable = parser.parseSingle();
parser.eat(TokenType.RIGHT_PAREN);
Expr expr;
if (parser.match(TokenType.LEFT_BRACE)) {
if (!parser.match(TokenType.RIGHT_BRACE)) {
expr = parser.parseStatements();
parser.eat(TokenType.RIGHT_BRACE);
} else {
expr = NullNode.VALUE;
}
} else {
expr = parser.parseExpr();
}
| // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/flow/ForEachExpr.java
// public class ForEachExpr extends Single {
// private final String variant;
// private final Single iterable;
// private final Expr action;
//
// public ForEachExpr(Position position, String variant, Single iterable, Expr action) {
// super(position);
// this.variant = variant;
// this.iterable = iterable;
// this.action = action;
// }
//
// public String getVariant() {
// return variant;
// }
//
// public Single getIterable() {
// return iterable;
// }
//
// public Expr getAction() {
// return action;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// builder.append(indent).append(isTail ? "└── " : "├── ").append("for each");
//
// builder.append('\n');
// builder.append(indent).append(isTail ? " " : "│ ").append("├── variant: ").append(variant);
//
// builder.append('\n');
// iterable.ast("iterable", builder, indent + (isTail ? " " : "│ "), false);
//
// builder.append('\n');
// action.ast("action", builder, indent + (isTail ? " " : "│ "), true);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/value/NullNode.java
// public class NullNode extends Single {
// public static final NullNode VALUE = new NullNode();
//
// private NullNode() {
// super(null);
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/lexer/TokenType.java
// public enum TokenType {
// // PAIRS
// LEFT_PAREN,
// RIGHT_PAREN,
//
// LEFT_BRACKET,
// RIGHT_BRACKET,
//
// LEFT_BRACE,
// RIGHT_BRACE,
//
// OPTIONAL_ASSIGN,
// ELVIS,
//
// // ASSIGNMENT
// ASSIGN,
//
// // TYPES
// INT,
// NUMBER,
// BOOLEAN,
// FUNCTION,
// STRING,
// ATOM,
//
// // ARITHMETIC
// PLUS,
// MINUS,
// ASTERISK,
// SLASH,
// BACKSLASH,
// CARET,
// PERCENT,
//
// // RELATIONAL
// EQUALS,
// NOT_EQUAL,
// GT,
// GTE,
// LT,
// LTE,
// OR,
// AND,
//
// // BOOLEAN
// AMPERSAND,
// VERTICAL_BAR,
//
// // MISC
// REST,
// RANGE_TO,
// PIPE_FORWARD,
// PIPE_BACKWARD,
// SHIFT_RIGHT,
// SHIFT_LEFT,
// ARROW,
// TILDE,
// BANG,
// QUESTION,
// COLON,
// COMMA,
// DOT,
//
// UNDERSCORE,
//
// // SCRIPT
// MODULE,
// TYPE,
// IDENTIFIER,
// NULL,
// LET,
// RETURN,
// IF,
// ELSE,
// FOR,
//
// LINE,
// EOF,
// }
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/parslets/flow/ForEachParser.java
import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.ast.flow.ForEachExpr;
import xyz.avarel.kaiper.ast.value.NullNode;
import xyz.avarel.kaiper.exceptions.SyntaxException;
import xyz.avarel.kaiper.lexer.Token;
import xyz.avarel.kaiper.lexer.TokenType;
import xyz.avarel.kaiper.parser.KaiperParser;
import xyz.avarel.kaiper.parser.PrefixParser;
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.parser.parslets.flow;
public class ForEachParser implements PrefixParser {
@Override
public Expr parse(KaiperParser parser, Token token) {
if (!parser.getParserFlags().allowControlFlows()) {
throw new SyntaxException("Control flows are disabled");
} else if (!parser.getParserFlags().allowLoops()) {
throw new SyntaxException("Loops are disabled");
}
parser.eat(TokenType.LEFT_PAREN);
String variant = parser.eat(TokenType.IDENTIFIER).getString();
parser.eatSoftKeyword("in");
Single iterable = parser.parseSingle();
parser.eat(TokenType.RIGHT_PAREN);
Expr expr;
if (parser.match(TokenType.LEFT_BRACE)) {
if (!parser.match(TokenType.RIGHT_BRACE)) {
expr = parser.parseStatements();
parser.eat(TokenType.RIGHT_BRACE);
} else {
expr = NullNode.VALUE;
}
} else {
expr = parser.parseExpr();
}
| return new ForEachExpr(token.getPosition(), variant, iterable, expr); |
Avarel/Kaiper | Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/parslets/flow/IfElseParser.java | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/flow/ConditionalExpr.java
// public class ConditionalExpr extends Single {
// private final Single condition;
// private final Expr ifBranch;
// private final Expr elseBranch;
//
// public ConditionalExpr(Position position, Single condition, Expr ifBranch, Expr elseBranch) {
// super(position);
// this.condition = condition;
// this.ifBranch = ifBranch;
// this.elseBranch = elseBranch;
// }
//
// public Single getCondition() {
// return condition;
// }
//
// public Expr getIfBranch() {
// return ifBranch;
// }
//
// public Expr getElseBranch() {
// return elseBranch;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) { // return if (sin(0) == 0) sin(50) else false
// builder.append(indent).append(isTail ? "└── " : "├── ").append("if");
//
// builder.append('\n');
// condition.ast("condition", builder, indent + (isTail ? " " : "│ "), false);
//
// builder.append('\n');
// ifBranch.ast("true", builder, indent + (isTail ? " " : "│ "), elseBranch == null);
//
// if (elseBranch != null) {
// builder.append('\n');
// elseBranch.ast("false", builder, indent + (isTail ? " " : "│ "), true);
// }
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/value/NullNode.java
// public class NullNode extends Single {
// public static final NullNode VALUE = new NullNode();
//
// private NullNode() {
// super(null);
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/lexer/TokenType.java
// public enum TokenType {
// // PAIRS
// LEFT_PAREN,
// RIGHT_PAREN,
//
// LEFT_BRACKET,
// RIGHT_BRACKET,
//
// LEFT_BRACE,
// RIGHT_BRACE,
//
// OPTIONAL_ASSIGN,
// ELVIS,
//
// // ASSIGNMENT
// ASSIGN,
//
// // TYPES
// INT,
// NUMBER,
// BOOLEAN,
// FUNCTION,
// STRING,
// ATOM,
//
// // ARITHMETIC
// PLUS,
// MINUS,
// ASTERISK,
// SLASH,
// BACKSLASH,
// CARET,
// PERCENT,
//
// // RELATIONAL
// EQUALS,
// NOT_EQUAL,
// GT,
// GTE,
// LT,
// LTE,
// OR,
// AND,
//
// // BOOLEAN
// AMPERSAND,
// VERTICAL_BAR,
//
// // MISC
// REST,
// RANGE_TO,
// PIPE_FORWARD,
// PIPE_BACKWARD,
// SHIFT_RIGHT,
// SHIFT_LEFT,
// ARROW,
// TILDE,
// BANG,
// QUESTION,
// COLON,
// COMMA,
// DOT,
//
// UNDERSCORE,
//
// // SCRIPT
// MODULE,
// TYPE,
// IDENTIFIER,
// NULL,
// LET,
// RETURN,
// IF,
// ELSE,
// FOR,
//
// LINE,
// EOF,
// }
| import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.ast.flow.ConditionalExpr;
import xyz.avarel.kaiper.ast.value.NullNode;
import xyz.avarel.kaiper.exceptions.SyntaxException;
import xyz.avarel.kaiper.lexer.Token;
import xyz.avarel.kaiper.lexer.TokenType;
import xyz.avarel.kaiper.parser.KaiperParser;
import xyz.avarel.kaiper.parser.PrefixParser; | /*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.parser.parslets.flow;
public class IfElseParser implements PrefixParser {
@Override
public Expr parse(KaiperParser parser, Token token) {
if (!parser.getParserFlags().allowControlFlows()) {
throw new SyntaxException("Control flows are disabled");
}
| // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/flow/ConditionalExpr.java
// public class ConditionalExpr extends Single {
// private final Single condition;
// private final Expr ifBranch;
// private final Expr elseBranch;
//
// public ConditionalExpr(Position position, Single condition, Expr ifBranch, Expr elseBranch) {
// super(position);
// this.condition = condition;
// this.ifBranch = ifBranch;
// this.elseBranch = elseBranch;
// }
//
// public Single getCondition() {
// return condition;
// }
//
// public Expr getIfBranch() {
// return ifBranch;
// }
//
// public Expr getElseBranch() {
// return elseBranch;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) { // return if (sin(0) == 0) sin(50) else false
// builder.append(indent).append(isTail ? "└── " : "├── ").append("if");
//
// builder.append('\n');
// condition.ast("condition", builder, indent + (isTail ? " " : "│ "), false);
//
// builder.append('\n');
// ifBranch.ast("true", builder, indent + (isTail ? " " : "│ "), elseBranch == null);
//
// if (elseBranch != null) {
// builder.append('\n');
// elseBranch.ast("false", builder, indent + (isTail ? " " : "│ "), true);
// }
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/value/NullNode.java
// public class NullNode extends Single {
// public static final NullNode VALUE = new NullNode();
//
// private NullNode() {
// super(null);
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/lexer/TokenType.java
// public enum TokenType {
// // PAIRS
// LEFT_PAREN,
// RIGHT_PAREN,
//
// LEFT_BRACKET,
// RIGHT_BRACKET,
//
// LEFT_BRACE,
// RIGHT_BRACE,
//
// OPTIONAL_ASSIGN,
// ELVIS,
//
// // ASSIGNMENT
// ASSIGN,
//
// // TYPES
// INT,
// NUMBER,
// BOOLEAN,
// FUNCTION,
// STRING,
// ATOM,
//
// // ARITHMETIC
// PLUS,
// MINUS,
// ASTERISK,
// SLASH,
// BACKSLASH,
// CARET,
// PERCENT,
//
// // RELATIONAL
// EQUALS,
// NOT_EQUAL,
// GT,
// GTE,
// LT,
// LTE,
// OR,
// AND,
//
// // BOOLEAN
// AMPERSAND,
// VERTICAL_BAR,
//
// // MISC
// REST,
// RANGE_TO,
// PIPE_FORWARD,
// PIPE_BACKWARD,
// SHIFT_RIGHT,
// SHIFT_LEFT,
// ARROW,
// TILDE,
// BANG,
// QUESTION,
// COLON,
// COMMA,
// DOT,
//
// UNDERSCORE,
//
// // SCRIPT
// MODULE,
// TYPE,
// IDENTIFIER,
// NULL,
// LET,
// RETURN,
// IF,
// ELSE,
// FOR,
//
// LINE,
// EOF,
// }
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/parslets/flow/IfElseParser.java
import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.ast.flow.ConditionalExpr;
import xyz.avarel.kaiper.ast.value.NullNode;
import xyz.avarel.kaiper.exceptions.SyntaxException;
import xyz.avarel.kaiper.lexer.Token;
import xyz.avarel.kaiper.lexer.TokenType;
import xyz.avarel.kaiper.parser.KaiperParser;
import xyz.avarel.kaiper.parser.PrefixParser;
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.parser.parslets.flow;
public class IfElseParser implements PrefixParser {
@Override
public Expr parse(KaiperParser parser, Token token) {
if (!parser.getParserFlags().allowControlFlows()) {
throw new SyntaxException("Control flows are disabled");
}
| parser.eat(TokenType.LEFT_PAREN); |
Avarel/Kaiper | Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/parslets/flow/IfElseParser.java | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/flow/ConditionalExpr.java
// public class ConditionalExpr extends Single {
// private final Single condition;
// private final Expr ifBranch;
// private final Expr elseBranch;
//
// public ConditionalExpr(Position position, Single condition, Expr ifBranch, Expr elseBranch) {
// super(position);
// this.condition = condition;
// this.ifBranch = ifBranch;
// this.elseBranch = elseBranch;
// }
//
// public Single getCondition() {
// return condition;
// }
//
// public Expr getIfBranch() {
// return ifBranch;
// }
//
// public Expr getElseBranch() {
// return elseBranch;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) { // return if (sin(0) == 0) sin(50) else false
// builder.append(indent).append(isTail ? "└── " : "├── ").append("if");
//
// builder.append('\n');
// condition.ast("condition", builder, indent + (isTail ? " " : "│ "), false);
//
// builder.append('\n');
// ifBranch.ast("true", builder, indent + (isTail ? " " : "│ "), elseBranch == null);
//
// if (elseBranch != null) {
// builder.append('\n');
// elseBranch.ast("false", builder, indent + (isTail ? " " : "│ "), true);
// }
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/value/NullNode.java
// public class NullNode extends Single {
// public static final NullNode VALUE = new NullNode();
//
// private NullNode() {
// super(null);
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/lexer/TokenType.java
// public enum TokenType {
// // PAIRS
// LEFT_PAREN,
// RIGHT_PAREN,
//
// LEFT_BRACKET,
// RIGHT_BRACKET,
//
// LEFT_BRACE,
// RIGHT_BRACE,
//
// OPTIONAL_ASSIGN,
// ELVIS,
//
// // ASSIGNMENT
// ASSIGN,
//
// // TYPES
// INT,
// NUMBER,
// BOOLEAN,
// FUNCTION,
// STRING,
// ATOM,
//
// // ARITHMETIC
// PLUS,
// MINUS,
// ASTERISK,
// SLASH,
// BACKSLASH,
// CARET,
// PERCENT,
//
// // RELATIONAL
// EQUALS,
// NOT_EQUAL,
// GT,
// GTE,
// LT,
// LTE,
// OR,
// AND,
//
// // BOOLEAN
// AMPERSAND,
// VERTICAL_BAR,
//
// // MISC
// REST,
// RANGE_TO,
// PIPE_FORWARD,
// PIPE_BACKWARD,
// SHIFT_RIGHT,
// SHIFT_LEFT,
// ARROW,
// TILDE,
// BANG,
// QUESTION,
// COLON,
// COMMA,
// DOT,
//
// UNDERSCORE,
//
// // SCRIPT
// MODULE,
// TYPE,
// IDENTIFIER,
// NULL,
// LET,
// RETURN,
// IF,
// ELSE,
// FOR,
//
// LINE,
// EOF,
// }
| import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.ast.flow.ConditionalExpr;
import xyz.avarel.kaiper.ast.value.NullNode;
import xyz.avarel.kaiper.exceptions.SyntaxException;
import xyz.avarel.kaiper.lexer.Token;
import xyz.avarel.kaiper.lexer.TokenType;
import xyz.avarel.kaiper.parser.KaiperParser;
import xyz.avarel.kaiper.parser.PrefixParser; | /*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.parser.parslets.flow;
public class IfElseParser implements PrefixParser {
@Override
public Expr parse(KaiperParser parser, Token token) {
if (!parser.getParserFlags().allowControlFlows()) {
throw new SyntaxException("Control flows are disabled");
}
parser.eat(TokenType.LEFT_PAREN);
Single condition = parser.parseSingle();
parser.eat(TokenType.RIGHT_PAREN);
Expr ifBranch;
if (parser.matchSignificant(TokenType.LEFT_BRACE)) {
if (!parser.matchSignificant(TokenType.RIGHT_BRACE)) {
ifBranch = parser.parseStatements();
parser.eat(TokenType.RIGHT_BRACE);
} else { | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/flow/ConditionalExpr.java
// public class ConditionalExpr extends Single {
// private final Single condition;
// private final Expr ifBranch;
// private final Expr elseBranch;
//
// public ConditionalExpr(Position position, Single condition, Expr ifBranch, Expr elseBranch) {
// super(position);
// this.condition = condition;
// this.ifBranch = ifBranch;
// this.elseBranch = elseBranch;
// }
//
// public Single getCondition() {
// return condition;
// }
//
// public Expr getIfBranch() {
// return ifBranch;
// }
//
// public Expr getElseBranch() {
// return elseBranch;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) { // return if (sin(0) == 0) sin(50) else false
// builder.append(indent).append(isTail ? "└── " : "├── ").append("if");
//
// builder.append('\n');
// condition.ast("condition", builder, indent + (isTail ? " " : "│ "), false);
//
// builder.append('\n');
// ifBranch.ast("true", builder, indent + (isTail ? " " : "│ "), elseBranch == null);
//
// if (elseBranch != null) {
// builder.append('\n');
// elseBranch.ast("false", builder, indent + (isTail ? " " : "│ "), true);
// }
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/value/NullNode.java
// public class NullNode extends Single {
// public static final NullNode VALUE = new NullNode();
//
// private NullNode() {
// super(null);
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/lexer/TokenType.java
// public enum TokenType {
// // PAIRS
// LEFT_PAREN,
// RIGHT_PAREN,
//
// LEFT_BRACKET,
// RIGHT_BRACKET,
//
// LEFT_BRACE,
// RIGHT_BRACE,
//
// OPTIONAL_ASSIGN,
// ELVIS,
//
// // ASSIGNMENT
// ASSIGN,
//
// // TYPES
// INT,
// NUMBER,
// BOOLEAN,
// FUNCTION,
// STRING,
// ATOM,
//
// // ARITHMETIC
// PLUS,
// MINUS,
// ASTERISK,
// SLASH,
// BACKSLASH,
// CARET,
// PERCENT,
//
// // RELATIONAL
// EQUALS,
// NOT_EQUAL,
// GT,
// GTE,
// LT,
// LTE,
// OR,
// AND,
//
// // BOOLEAN
// AMPERSAND,
// VERTICAL_BAR,
//
// // MISC
// REST,
// RANGE_TO,
// PIPE_FORWARD,
// PIPE_BACKWARD,
// SHIFT_RIGHT,
// SHIFT_LEFT,
// ARROW,
// TILDE,
// BANG,
// QUESTION,
// COLON,
// COMMA,
// DOT,
//
// UNDERSCORE,
//
// // SCRIPT
// MODULE,
// TYPE,
// IDENTIFIER,
// NULL,
// LET,
// RETURN,
// IF,
// ELSE,
// FOR,
//
// LINE,
// EOF,
// }
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/parslets/flow/IfElseParser.java
import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.ast.flow.ConditionalExpr;
import xyz.avarel.kaiper.ast.value.NullNode;
import xyz.avarel.kaiper.exceptions.SyntaxException;
import xyz.avarel.kaiper.lexer.Token;
import xyz.avarel.kaiper.lexer.TokenType;
import xyz.avarel.kaiper.parser.KaiperParser;
import xyz.avarel.kaiper.parser.PrefixParser;
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.parser.parslets.flow;
public class IfElseParser implements PrefixParser {
@Override
public Expr parse(KaiperParser parser, Token token) {
if (!parser.getParserFlags().allowControlFlows()) {
throw new SyntaxException("Control flows are disabled");
}
parser.eat(TokenType.LEFT_PAREN);
Single condition = parser.parseSingle();
parser.eat(TokenType.RIGHT_PAREN);
Expr ifBranch;
if (parser.matchSignificant(TokenType.LEFT_BRACE)) {
if (!parser.matchSignificant(TokenType.RIGHT_BRACE)) {
ifBranch = parser.parseStatements();
parser.eat(TokenType.RIGHT_BRACE);
} else { | ifBranch = NullNode.VALUE; |
Avarel/Kaiper | Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/parslets/flow/IfElseParser.java | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/flow/ConditionalExpr.java
// public class ConditionalExpr extends Single {
// private final Single condition;
// private final Expr ifBranch;
// private final Expr elseBranch;
//
// public ConditionalExpr(Position position, Single condition, Expr ifBranch, Expr elseBranch) {
// super(position);
// this.condition = condition;
// this.ifBranch = ifBranch;
// this.elseBranch = elseBranch;
// }
//
// public Single getCondition() {
// return condition;
// }
//
// public Expr getIfBranch() {
// return ifBranch;
// }
//
// public Expr getElseBranch() {
// return elseBranch;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) { // return if (sin(0) == 0) sin(50) else false
// builder.append(indent).append(isTail ? "└── " : "├── ").append("if");
//
// builder.append('\n');
// condition.ast("condition", builder, indent + (isTail ? " " : "│ "), false);
//
// builder.append('\n');
// ifBranch.ast("true", builder, indent + (isTail ? " " : "│ "), elseBranch == null);
//
// if (elseBranch != null) {
// builder.append('\n');
// elseBranch.ast("false", builder, indent + (isTail ? " " : "│ "), true);
// }
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/value/NullNode.java
// public class NullNode extends Single {
// public static final NullNode VALUE = new NullNode();
//
// private NullNode() {
// super(null);
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/lexer/TokenType.java
// public enum TokenType {
// // PAIRS
// LEFT_PAREN,
// RIGHT_PAREN,
//
// LEFT_BRACKET,
// RIGHT_BRACKET,
//
// LEFT_BRACE,
// RIGHT_BRACE,
//
// OPTIONAL_ASSIGN,
// ELVIS,
//
// // ASSIGNMENT
// ASSIGN,
//
// // TYPES
// INT,
// NUMBER,
// BOOLEAN,
// FUNCTION,
// STRING,
// ATOM,
//
// // ARITHMETIC
// PLUS,
// MINUS,
// ASTERISK,
// SLASH,
// BACKSLASH,
// CARET,
// PERCENT,
//
// // RELATIONAL
// EQUALS,
// NOT_EQUAL,
// GT,
// GTE,
// LT,
// LTE,
// OR,
// AND,
//
// // BOOLEAN
// AMPERSAND,
// VERTICAL_BAR,
//
// // MISC
// REST,
// RANGE_TO,
// PIPE_FORWARD,
// PIPE_BACKWARD,
// SHIFT_RIGHT,
// SHIFT_LEFT,
// ARROW,
// TILDE,
// BANG,
// QUESTION,
// COLON,
// COMMA,
// DOT,
//
// UNDERSCORE,
//
// // SCRIPT
// MODULE,
// TYPE,
// IDENTIFIER,
// NULL,
// LET,
// RETURN,
// IF,
// ELSE,
// FOR,
//
// LINE,
// EOF,
// }
| import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.ast.flow.ConditionalExpr;
import xyz.avarel.kaiper.ast.value.NullNode;
import xyz.avarel.kaiper.exceptions.SyntaxException;
import xyz.avarel.kaiper.lexer.Token;
import xyz.avarel.kaiper.lexer.TokenType;
import xyz.avarel.kaiper.parser.KaiperParser;
import xyz.avarel.kaiper.parser.PrefixParser; | parser.eat(TokenType.RIGHT_PAREN);
Expr ifBranch;
if (parser.matchSignificant(TokenType.LEFT_BRACE)) {
if (!parser.matchSignificant(TokenType.RIGHT_BRACE)) {
ifBranch = parser.parseStatements();
parser.eat(TokenType.RIGHT_BRACE);
} else {
ifBranch = NullNode.VALUE;
}
} else {
ifBranch = parser.parseExpr();
}
Expr elseBranch = null;
if (parser.matchSignificant(TokenType.ELSE)) {
if (parser.matchSignificant(TokenType.LEFT_BRACE)) {
if (!parser.matchSignificant(TokenType.RIGHT_BRACE)) {
elseBranch = parser.parseStatements();
parser.eat(TokenType.RIGHT_BRACE);
} else {
elseBranch = NullNode.VALUE;
}
} else {
elseBranch = parser.parseExpr();
}
}
| // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/flow/ConditionalExpr.java
// public class ConditionalExpr extends Single {
// private final Single condition;
// private final Expr ifBranch;
// private final Expr elseBranch;
//
// public ConditionalExpr(Position position, Single condition, Expr ifBranch, Expr elseBranch) {
// super(position);
// this.condition = condition;
// this.ifBranch = ifBranch;
// this.elseBranch = elseBranch;
// }
//
// public Single getCondition() {
// return condition;
// }
//
// public Expr getIfBranch() {
// return ifBranch;
// }
//
// public Expr getElseBranch() {
// return elseBranch;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) { // return if (sin(0) == 0) sin(50) else false
// builder.append(indent).append(isTail ? "└── " : "├── ").append("if");
//
// builder.append('\n');
// condition.ast("condition", builder, indent + (isTail ? " " : "│ "), false);
//
// builder.append('\n');
// ifBranch.ast("true", builder, indent + (isTail ? " " : "│ "), elseBranch == null);
//
// if (elseBranch != null) {
// builder.append('\n');
// elseBranch.ast("false", builder, indent + (isTail ? " " : "│ "), true);
// }
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/value/NullNode.java
// public class NullNode extends Single {
// public static final NullNode VALUE = new NullNode();
//
// private NullNode() {
// super(null);
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/lexer/TokenType.java
// public enum TokenType {
// // PAIRS
// LEFT_PAREN,
// RIGHT_PAREN,
//
// LEFT_BRACKET,
// RIGHT_BRACKET,
//
// LEFT_BRACE,
// RIGHT_BRACE,
//
// OPTIONAL_ASSIGN,
// ELVIS,
//
// // ASSIGNMENT
// ASSIGN,
//
// // TYPES
// INT,
// NUMBER,
// BOOLEAN,
// FUNCTION,
// STRING,
// ATOM,
//
// // ARITHMETIC
// PLUS,
// MINUS,
// ASTERISK,
// SLASH,
// BACKSLASH,
// CARET,
// PERCENT,
//
// // RELATIONAL
// EQUALS,
// NOT_EQUAL,
// GT,
// GTE,
// LT,
// LTE,
// OR,
// AND,
//
// // BOOLEAN
// AMPERSAND,
// VERTICAL_BAR,
//
// // MISC
// REST,
// RANGE_TO,
// PIPE_FORWARD,
// PIPE_BACKWARD,
// SHIFT_RIGHT,
// SHIFT_LEFT,
// ARROW,
// TILDE,
// BANG,
// QUESTION,
// COLON,
// COMMA,
// DOT,
//
// UNDERSCORE,
//
// // SCRIPT
// MODULE,
// TYPE,
// IDENTIFIER,
// NULL,
// LET,
// RETURN,
// IF,
// ELSE,
// FOR,
//
// LINE,
// EOF,
// }
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/parslets/flow/IfElseParser.java
import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.ast.flow.ConditionalExpr;
import xyz.avarel.kaiper.ast.value.NullNode;
import xyz.avarel.kaiper.exceptions.SyntaxException;
import xyz.avarel.kaiper.lexer.Token;
import xyz.avarel.kaiper.lexer.TokenType;
import xyz.avarel.kaiper.parser.KaiperParser;
import xyz.avarel.kaiper.parser.PrefixParser;
parser.eat(TokenType.RIGHT_PAREN);
Expr ifBranch;
if (parser.matchSignificant(TokenType.LEFT_BRACE)) {
if (!parser.matchSignificant(TokenType.RIGHT_BRACE)) {
ifBranch = parser.parseStatements();
parser.eat(TokenType.RIGHT_BRACE);
} else {
ifBranch = NullNode.VALUE;
}
} else {
ifBranch = parser.parseExpr();
}
Expr elseBranch = null;
if (parser.matchSignificant(TokenType.ELSE)) {
if (parser.matchSignificant(TokenType.LEFT_BRACE)) {
if (!parser.matchSignificant(TokenType.RIGHT_BRACE)) {
elseBranch = parser.parseStatements();
parser.eat(TokenType.RIGHT_BRACE);
} else {
elseBranch = NullNode.VALUE;
}
} else {
elseBranch = parser.parseExpr();
}
}
| return new ConditionalExpr(token.getPosition(), condition, ifBranch, elseBranch); |
Avarel/Kaiper | Kaiper-Interpreter/src/main/java/xyz/avarel/kaiper/interpreter/GlobalVisitorSettings.java | // Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/exceptions/ComputeException.java
// public class ComputeException extends KaiperException {
// public ComputeException(String msg) {
// super(msg);
// }
//
// public ComputeException(String s, Throwable throwable) {
// super(s, throwable);
// }
//
// public ComputeException(Throwable throwable) {
// super(throwable);
// }
// }
| import xyz.avarel.kaiper.exceptions.ComputeException; | /*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.interpreter;
public class GlobalVisitorSettings {
public static int ITERATION_LIMIT = -1;
public static int SIZE_LIMIT = -1;
public static long MILLISECONDS_LIMIT = -1;
public static int RECURSION_DEPTH_LIMIT = -1;
public static void checkIterationLimit(int iter) {
if (ITERATION_LIMIT != -1 && iter > ITERATION_LIMIT) { | // Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/exceptions/ComputeException.java
// public class ComputeException extends KaiperException {
// public ComputeException(String msg) {
// super(msg);
// }
//
// public ComputeException(String s, Throwable throwable) {
// super(s, throwable);
// }
//
// public ComputeException(Throwable throwable) {
// super(throwable);
// }
// }
// Path: Kaiper-Interpreter/src/main/java/xyz/avarel/kaiper/interpreter/GlobalVisitorSettings.java
import xyz.avarel.kaiper.exceptions.ComputeException;
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.interpreter;
public class GlobalVisitorSettings {
public static int ITERATION_LIMIT = -1;
public static int SIZE_LIMIT = -1;
public static long MILLISECONDS_LIMIT = -1;
public static int RECURSION_DEPTH_LIMIT = -1;
public static void checkIterationLimit(int iter) {
if (ITERATION_LIMIT != -1 && iter > ITERATION_LIMIT) { | throw new ComputeException("Iteration limit"); |
Avarel/Kaiper | Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/Obj.java | // Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/exceptions/ComputeException.java
// public class ComputeException extends KaiperException {
// public ComputeException(String msg) {
// super(msg);
// }
//
// public ComputeException(String s, Throwable throwable) {
// super(s, throwable);
// }
//
// public ComputeException(Throwable throwable) {
// super(throwable);
// }
// }
//
// Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/modules/Module.java
// public abstract class Module implements Obj {
// public static final Type<Module> TYPE = new Type<>("Module");
//
// @Override
// public abstract Obj getAttr(String name);
//
// @Override
// public Type getType() {
// return TYPE;
// }
// }
//
// Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/modules/NativeModule.java
// public abstract class NativeModule extends Module {
// private final Map<String, Obj> map;
//
// protected NativeModule() {
// this.map = new HashMap<>();
// }
//
// public void declare(String name, Obj obj) {
// map.put(name, obj);
// }
//
// @Override
// public Obj getAttr(String name) {
// return map.getOrDefault(name, Null.VALUE);
// }
// }
//
// Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/types/Type.java
// @SuppressWarnings("unused")
// public class Type<T> implements Obj {
// public static final Type<Type> TYPE = new Type<Type>("Type") {
// @Override
// public Type getParent() {
// return Obj.TYPE;
// }
// };
//
// private final Type parent;
// private final String name;
// private final Constructor constructor;
//
// public Type(String name) {
// this(name, null);
// }
//
// public Type(String name, Constructor constructor) {
// this(Obj.TYPE, name, constructor);
// }
//
// public Type(Type parent, String name) {
// this(parent, name, null);
// }
//
// public Type(Type parent, String name, Constructor constructor) {
// this.parent = parent;
// this.name = name;
// this.constructor = constructor;
// if (constructor != null) constructor.targetType = this;
// }
//
// public boolean is(Type type) {
// Type t = this;
// do {
// if (t.equals(type)) return true;
// t = t.getParent();
// } while (t != null);
// return false;
// }
//
//
// public Constructor getConstructor() {
// return constructor;
// }
//
// @Override
// public Type getType() {
// return TYPE;
// }
//
// @Override
// public Type toJava() {
// return this;
// }
//
// public Type getParent() {
// return parent;
// }
//
// public boolean hasParent() {
// return getParent() != null;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return name;
// }
//
// public String toExtendedString() {
// if (parent != null) {
// return name + ": " + parent;
// } else {
// return name;
// }
// }
//
// @Override
// public Obj invoke(List<Obj> arguments) {
// if (constructor == null) {
// throw new ComputeException(toString() + " does not support instantiation");
// } else {
// return constructor.invoke(arguments);
// }
// }
// }
| import xyz.avarel.kaiper.exceptions.ComputeException;
import xyz.avarel.kaiper.runtime.modules.Module;
import xyz.avarel.kaiper.runtime.modules.NativeModule;
import xyz.avarel.kaiper.runtime.types.Type;
import java.util.Arrays;
import java.util.List; | /*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.runtime;
/**
* An interface containing all natively implemented operations.
*/
public interface Obj {
Type<Obj> TYPE = new Type<>("Object"); | // Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/exceptions/ComputeException.java
// public class ComputeException extends KaiperException {
// public ComputeException(String msg) {
// super(msg);
// }
//
// public ComputeException(String s, Throwable throwable) {
// super(s, throwable);
// }
//
// public ComputeException(Throwable throwable) {
// super(throwable);
// }
// }
//
// Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/modules/Module.java
// public abstract class Module implements Obj {
// public static final Type<Module> TYPE = new Type<>("Module");
//
// @Override
// public abstract Obj getAttr(String name);
//
// @Override
// public Type getType() {
// return TYPE;
// }
// }
//
// Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/modules/NativeModule.java
// public abstract class NativeModule extends Module {
// private final Map<String, Obj> map;
//
// protected NativeModule() {
// this.map = new HashMap<>();
// }
//
// public void declare(String name, Obj obj) {
// map.put(name, obj);
// }
//
// @Override
// public Obj getAttr(String name) {
// return map.getOrDefault(name, Null.VALUE);
// }
// }
//
// Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/types/Type.java
// @SuppressWarnings("unused")
// public class Type<T> implements Obj {
// public static final Type<Type> TYPE = new Type<Type>("Type") {
// @Override
// public Type getParent() {
// return Obj.TYPE;
// }
// };
//
// private final Type parent;
// private final String name;
// private final Constructor constructor;
//
// public Type(String name) {
// this(name, null);
// }
//
// public Type(String name, Constructor constructor) {
// this(Obj.TYPE, name, constructor);
// }
//
// public Type(Type parent, String name) {
// this(parent, name, null);
// }
//
// public Type(Type parent, String name, Constructor constructor) {
// this.parent = parent;
// this.name = name;
// this.constructor = constructor;
// if (constructor != null) constructor.targetType = this;
// }
//
// public boolean is(Type type) {
// Type t = this;
// do {
// if (t.equals(type)) return true;
// t = t.getParent();
// } while (t != null);
// return false;
// }
//
//
// public Constructor getConstructor() {
// return constructor;
// }
//
// @Override
// public Type getType() {
// return TYPE;
// }
//
// @Override
// public Type toJava() {
// return this;
// }
//
// public Type getParent() {
// return parent;
// }
//
// public boolean hasParent() {
// return getParent() != null;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return name;
// }
//
// public String toExtendedString() {
// if (parent != null) {
// return name + ": " + parent;
// } else {
// return name;
// }
// }
//
// @Override
// public Obj invoke(List<Obj> arguments) {
// if (constructor == null) {
// throw new ComputeException(toString() + " does not support instantiation");
// } else {
// return constructor.invoke(arguments);
// }
// }
// }
// Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/Obj.java
import xyz.avarel.kaiper.exceptions.ComputeException;
import xyz.avarel.kaiper.runtime.modules.Module;
import xyz.avarel.kaiper.runtime.modules.NativeModule;
import xyz.avarel.kaiper.runtime.types.Type;
import java.util.Arrays;
import java.util.List;
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.runtime;
/**
* An interface containing all natively implemented operations.
*/
public interface Obj {
Type<Obj> TYPE = new Type<>("Object"); | Module MODULE = new NativeModule() {{ |
Avarel/Kaiper | Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/Obj.java | // Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/exceptions/ComputeException.java
// public class ComputeException extends KaiperException {
// public ComputeException(String msg) {
// super(msg);
// }
//
// public ComputeException(String s, Throwable throwable) {
// super(s, throwable);
// }
//
// public ComputeException(Throwable throwable) {
// super(throwable);
// }
// }
//
// Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/modules/Module.java
// public abstract class Module implements Obj {
// public static final Type<Module> TYPE = new Type<>("Module");
//
// @Override
// public abstract Obj getAttr(String name);
//
// @Override
// public Type getType() {
// return TYPE;
// }
// }
//
// Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/modules/NativeModule.java
// public abstract class NativeModule extends Module {
// private final Map<String, Obj> map;
//
// protected NativeModule() {
// this.map = new HashMap<>();
// }
//
// public void declare(String name, Obj obj) {
// map.put(name, obj);
// }
//
// @Override
// public Obj getAttr(String name) {
// return map.getOrDefault(name, Null.VALUE);
// }
// }
//
// Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/types/Type.java
// @SuppressWarnings("unused")
// public class Type<T> implements Obj {
// public static final Type<Type> TYPE = new Type<Type>("Type") {
// @Override
// public Type getParent() {
// return Obj.TYPE;
// }
// };
//
// private final Type parent;
// private final String name;
// private final Constructor constructor;
//
// public Type(String name) {
// this(name, null);
// }
//
// public Type(String name, Constructor constructor) {
// this(Obj.TYPE, name, constructor);
// }
//
// public Type(Type parent, String name) {
// this(parent, name, null);
// }
//
// public Type(Type parent, String name, Constructor constructor) {
// this.parent = parent;
// this.name = name;
// this.constructor = constructor;
// if (constructor != null) constructor.targetType = this;
// }
//
// public boolean is(Type type) {
// Type t = this;
// do {
// if (t.equals(type)) return true;
// t = t.getParent();
// } while (t != null);
// return false;
// }
//
//
// public Constructor getConstructor() {
// return constructor;
// }
//
// @Override
// public Type getType() {
// return TYPE;
// }
//
// @Override
// public Type toJava() {
// return this;
// }
//
// public Type getParent() {
// return parent;
// }
//
// public boolean hasParent() {
// return getParent() != null;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return name;
// }
//
// public String toExtendedString() {
// if (parent != null) {
// return name + ": " + parent;
// } else {
// return name;
// }
// }
//
// @Override
// public Obj invoke(List<Obj> arguments) {
// if (constructor == null) {
// throw new ComputeException(toString() + " does not support instantiation");
// } else {
// return constructor.invoke(arguments);
// }
// }
// }
| import xyz.avarel.kaiper.exceptions.ComputeException;
import xyz.avarel.kaiper.runtime.modules.Module;
import xyz.avarel.kaiper.runtime.modules.NativeModule;
import xyz.avarel.kaiper.runtime.types.Type;
import java.util.Arrays;
import java.util.List; | /*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.runtime;
/**
* An interface containing all natively implemented operations.
*/
public interface Obj {
Type<Obj> TYPE = new Type<>("Object"); | // Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/exceptions/ComputeException.java
// public class ComputeException extends KaiperException {
// public ComputeException(String msg) {
// super(msg);
// }
//
// public ComputeException(String s, Throwable throwable) {
// super(s, throwable);
// }
//
// public ComputeException(Throwable throwable) {
// super(throwable);
// }
// }
//
// Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/modules/Module.java
// public abstract class Module implements Obj {
// public static final Type<Module> TYPE = new Type<>("Module");
//
// @Override
// public abstract Obj getAttr(String name);
//
// @Override
// public Type getType() {
// return TYPE;
// }
// }
//
// Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/modules/NativeModule.java
// public abstract class NativeModule extends Module {
// private final Map<String, Obj> map;
//
// protected NativeModule() {
// this.map = new HashMap<>();
// }
//
// public void declare(String name, Obj obj) {
// map.put(name, obj);
// }
//
// @Override
// public Obj getAttr(String name) {
// return map.getOrDefault(name, Null.VALUE);
// }
// }
//
// Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/types/Type.java
// @SuppressWarnings("unused")
// public class Type<T> implements Obj {
// public static final Type<Type> TYPE = new Type<Type>("Type") {
// @Override
// public Type getParent() {
// return Obj.TYPE;
// }
// };
//
// private final Type parent;
// private final String name;
// private final Constructor constructor;
//
// public Type(String name) {
// this(name, null);
// }
//
// public Type(String name, Constructor constructor) {
// this(Obj.TYPE, name, constructor);
// }
//
// public Type(Type parent, String name) {
// this(parent, name, null);
// }
//
// public Type(Type parent, String name, Constructor constructor) {
// this.parent = parent;
// this.name = name;
// this.constructor = constructor;
// if (constructor != null) constructor.targetType = this;
// }
//
// public boolean is(Type type) {
// Type t = this;
// do {
// if (t.equals(type)) return true;
// t = t.getParent();
// } while (t != null);
// return false;
// }
//
//
// public Constructor getConstructor() {
// return constructor;
// }
//
// @Override
// public Type getType() {
// return TYPE;
// }
//
// @Override
// public Type toJava() {
// return this;
// }
//
// public Type getParent() {
// return parent;
// }
//
// public boolean hasParent() {
// return getParent() != null;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return name;
// }
//
// public String toExtendedString() {
// if (parent != null) {
// return name + ": " + parent;
// } else {
// return name;
// }
// }
//
// @Override
// public Obj invoke(List<Obj> arguments) {
// if (constructor == null) {
// throw new ComputeException(toString() + " does not support instantiation");
// } else {
// return constructor.invoke(arguments);
// }
// }
// }
// Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/Obj.java
import xyz.avarel.kaiper.exceptions.ComputeException;
import xyz.avarel.kaiper.runtime.modules.Module;
import xyz.avarel.kaiper.runtime.modules.NativeModule;
import xyz.avarel.kaiper.runtime.types.Type;
import java.util.Arrays;
import java.util.List;
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.runtime;
/**
* An interface containing all natively implemented operations.
*/
public interface Obj {
Type<Obj> TYPE = new Type<>("Object"); | Module MODULE = new NativeModule() {{ |
Avarel/Kaiper | Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/Obj.java | // Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/exceptions/ComputeException.java
// public class ComputeException extends KaiperException {
// public ComputeException(String msg) {
// super(msg);
// }
//
// public ComputeException(String s, Throwable throwable) {
// super(s, throwable);
// }
//
// public ComputeException(Throwable throwable) {
// super(throwable);
// }
// }
//
// Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/modules/Module.java
// public abstract class Module implements Obj {
// public static final Type<Module> TYPE = new Type<>("Module");
//
// @Override
// public abstract Obj getAttr(String name);
//
// @Override
// public Type getType() {
// return TYPE;
// }
// }
//
// Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/modules/NativeModule.java
// public abstract class NativeModule extends Module {
// private final Map<String, Obj> map;
//
// protected NativeModule() {
// this.map = new HashMap<>();
// }
//
// public void declare(String name, Obj obj) {
// map.put(name, obj);
// }
//
// @Override
// public Obj getAttr(String name) {
// return map.getOrDefault(name, Null.VALUE);
// }
// }
//
// Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/types/Type.java
// @SuppressWarnings("unused")
// public class Type<T> implements Obj {
// public static final Type<Type> TYPE = new Type<Type>("Type") {
// @Override
// public Type getParent() {
// return Obj.TYPE;
// }
// };
//
// private final Type parent;
// private final String name;
// private final Constructor constructor;
//
// public Type(String name) {
// this(name, null);
// }
//
// public Type(String name, Constructor constructor) {
// this(Obj.TYPE, name, constructor);
// }
//
// public Type(Type parent, String name) {
// this(parent, name, null);
// }
//
// public Type(Type parent, String name, Constructor constructor) {
// this.parent = parent;
// this.name = name;
// this.constructor = constructor;
// if (constructor != null) constructor.targetType = this;
// }
//
// public boolean is(Type type) {
// Type t = this;
// do {
// if (t.equals(type)) return true;
// t = t.getParent();
// } while (t != null);
// return false;
// }
//
//
// public Constructor getConstructor() {
// return constructor;
// }
//
// @Override
// public Type getType() {
// return TYPE;
// }
//
// @Override
// public Type toJava() {
// return this;
// }
//
// public Type getParent() {
// return parent;
// }
//
// public boolean hasParent() {
// return getParent() != null;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return name;
// }
//
// public String toExtendedString() {
// if (parent != null) {
// return name + ": " + parent;
// } else {
// return name;
// }
// }
//
// @Override
// public Obj invoke(List<Obj> arguments) {
// if (constructor == null) {
// throw new ComputeException(toString() + " does not support instantiation");
// } else {
// return constructor.invoke(arguments);
// }
// }
// }
| import xyz.avarel.kaiper.exceptions.ComputeException;
import xyz.avarel.kaiper.runtime.modules.Module;
import xyz.avarel.kaiper.runtime.modules.NativeModule;
import xyz.avarel.kaiper.runtime.types.Type;
import java.util.Arrays;
import java.util.List; | */
default Obj identity() {
return this;
}
/**
* Get operator in Kaiper. Default symbol is {@code a[b]}.
* <br> Implementation should default to error if not implemented.
*
* @param key
* Right {@link Obj} operand.
* @return The {@link Obj} result of the operation.
*/
default Obj get(Obj key) {
throw unimplemented("get");
}
default Obj set(Obj key, Obj value) {
throw unimplemented("set");
}
/**
* Attribute operator in Kaiper. Default symbol is {@code a.b}.
* <br> Implementation should default to error if not implemented.
*
* @param name
* Attribute name.
* @return The {@link Obj} result of the operation.
*/
default Obj getAttr(String name) { | // Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/exceptions/ComputeException.java
// public class ComputeException extends KaiperException {
// public ComputeException(String msg) {
// super(msg);
// }
//
// public ComputeException(String s, Throwable throwable) {
// super(s, throwable);
// }
//
// public ComputeException(Throwable throwable) {
// super(throwable);
// }
// }
//
// Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/modules/Module.java
// public abstract class Module implements Obj {
// public static final Type<Module> TYPE = new Type<>("Module");
//
// @Override
// public abstract Obj getAttr(String name);
//
// @Override
// public Type getType() {
// return TYPE;
// }
// }
//
// Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/modules/NativeModule.java
// public abstract class NativeModule extends Module {
// private final Map<String, Obj> map;
//
// protected NativeModule() {
// this.map = new HashMap<>();
// }
//
// public void declare(String name, Obj obj) {
// map.put(name, obj);
// }
//
// @Override
// public Obj getAttr(String name) {
// return map.getOrDefault(name, Null.VALUE);
// }
// }
//
// Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/types/Type.java
// @SuppressWarnings("unused")
// public class Type<T> implements Obj {
// public static final Type<Type> TYPE = new Type<Type>("Type") {
// @Override
// public Type getParent() {
// return Obj.TYPE;
// }
// };
//
// private final Type parent;
// private final String name;
// private final Constructor constructor;
//
// public Type(String name) {
// this(name, null);
// }
//
// public Type(String name, Constructor constructor) {
// this(Obj.TYPE, name, constructor);
// }
//
// public Type(Type parent, String name) {
// this(parent, name, null);
// }
//
// public Type(Type parent, String name, Constructor constructor) {
// this.parent = parent;
// this.name = name;
// this.constructor = constructor;
// if (constructor != null) constructor.targetType = this;
// }
//
// public boolean is(Type type) {
// Type t = this;
// do {
// if (t.equals(type)) return true;
// t = t.getParent();
// } while (t != null);
// return false;
// }
//
//
// public Constructor getConstructor() {
// return constructor;
// }
//
// @Override
// public Type getType() {
// return TYPE;
// }
//
// @Override
// public Type toJava() {
// return this;
// }
//
// public Type getParent() {
// return parent;
// }
//
// public boolean hasParent() {
// return getParent() != null;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return name;
// }
//
// public String toExtendedString() {
// if (parent != null) {
// return name + ": " + parent;
// } else {
// return name;
// }
// }
//
// @Override
// public Obj invoke(List<Obj> arguments) {
// if (constructor == null) {
// throw new ComputeException(toString() + " does not support instantiation");
// } else {
// return constructor.invoke(arguments);
// }
// }
// }
// Path: Kaiper-Runtime-Lib/src/main/java/xyz/avarel/kaiper/runtime/Obj.java
import xyz.avarel.kaiper.exceptions.ComputeException;
import xyz.avarel.kaiper.runtime.modules.Module;
import xyz.avarel.kaiper.runtime.modules.NativeModule;
import xyz.avarel.kaiper.runtime.types.Type;
import java.util.Arrays;
import java.util.List;
*/
default Obj identity() {
return this;
}
/**
* Get operator in Kaiper. Default symbol is {@code a[b]}.
* <br> Implementation should default to error if not implemented.
*
* @param key
* Right {@link Obj} operand.
* @return The {@link Obj} result of the operation.
*/
default Obj get(Obj key) {
throw unimplemented("get");
}
default Obj set(Obj key, Obj value) {
throw unimplemented("set");
}
/**
* Attribute operator in Kaiper. Default symbol is {@code a.b}.
* <br> Implementation should default to error if not implemented.
*
* @param name
* Attribute name.
* @return The {@link Obj} result of the operation.
*/
default Obj getAttr(String name) { | throw new ComputeException("Can not read attribute " + name + " of " + toString()); |
Avarel/Kaiper | Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/collections/DictionaryNode.java | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/ExprVisitor.java
// public interface ExprVisitor<R, C> {
// R visit(Statements expr, C scope);
//
// R visit(FunctionNode expr, C scope);
//
// R visit(Identifier expr, C scope);
//
// R visit(Invocation expr, C scope);
//
// R visit(BinaryOperation expr, C scope);
//
// R visit(UnaryOperation expr, C scope);
//
// R visit(RangeNode expr, C scope);
//
// R visit(ArrayNode expr, C scope);
//
// R visit(SliceOperation expr, C scope);
//
// R visit(AssignmentExpr expr, C scope);
//
// R visit(GetOperation expr, C scope);
//
// R visit(SetOperation expr, C scope);
//
// R visit(ReturnExpr expr, C scope);
//
// R visit(ConditionalExpr expr, C scope);
//
// R visit(ForEachExpr expr, C scope);
//
// R visit(DictionaryNode expr, C scope);
//
// R visit(NullNode expr, C scope);
//
// R visit(IntNode expr, C scope);
//
// R visit(DecimalNode expr, C scope);
//
// R visit(BooleanNode expr, C scope);
//
// R visit(StringNode expr, C scope);
//
// R visit(DeclarationExpr expr, C scope);
//
// R visit(ModuleNode expr, C scope);
//
// R visit(TypeNode expr, C scope);
//
// R visit(WhileExpr expr, C scope);
// }
| import xyz.avarel.kaiper.ast.ExprVisitor;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.lexer.Position;
import java.util.Map; | /*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.ast.collections;
public class DictionaryNode extends Single {
private final Map<Single, Single> map;
public DictionaryNode(Position position, Map<Single, Single> map) {
super(position);
this.map = map;
}
public Map<Single, Single> getMap() {
return map;
}
@Override | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/ExprVisitor.java
// public interface ExprVisitor<R, C> {
// R visit(Statements expr, C scope);
//
// R visit(FunctionNode expr, C scope);
//
// R visit(Identifier expr, C scope);
//
// R visit(Invocation expr, C scope);
//
// R visit(BinaryOperation expr, C scope);
//
// R visit(UnaryOperation expr, C scope);
//
// R visit(RangeNode expr, C scope);
//
// R visit(ArrayNode expr, C scope);
//
// R visit(SliceOperation expr, C scope);
//
// R visit(AssignmentExpr expr, C scope);
//
// R visit(GetOperation expr, C scope);
//
// R visit(SetOperation expr, C scope);
//
// R visit(ReturnExpr expr, C scope);
//
// R visit(ConditionalExpr expr, C scope);
//
// R visit(ForEachExpr expr, C scope);
//
// R visit(DictionaryNode expr, C scope);
//
// R visit(NullNode expr, C scope);
//
// R visit(IntNode expr, C scope);
//
// R visit(DecimalNode expr, C scope);
//
// R visit(BooleanNode expr, C scope);
//
// R visit(StringNode expr, C scope);
//
// R visit(DeclarationExpr expr, C scope);
//
// R visit(ModuleNode expr, C scope);
//
// R visit(TypeNode expr, C scope);
//
// R visit(WhileExpr expr, C scope);
// }
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/collections/DictionaryNode.java
import xyz.avarel.kaiper.ast.ExprVisitor;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.lexer.Position;
import java.util.Map;
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.ast.collections;
public class DictionaryNode extends Single {
private final Map<Single, Single> map;
public DictionaryNode(Position position, Map<Single, Single> map) {
super(position);
this.map = map;
}
public Map<Single, Single> getMap() {
return map;
}
@Override | public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) { |
Avarel/Kaiper | Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/parslets/nodes/DecimalParser.java | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/value/DecimalNode.java
// public class DecimalNode extends Single {
// private final double value;
//
// public DecimalNode(Position position, double value) {
// super(position);
// this.value = value;
// }
//
// public double getValue() {
// return value;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public String toString() {
// return String.valueOf(value);
// }
// }
| import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.value.DecimalNode;
import xyz.avarel.kaiper.lexer.Token;
import xyz.avarel.kaiper.parser.KaiperParser;
import xyz.avarel.kaiper.parser.PrefixParser; | /*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.parser.parslets.nodes;
public class DecimalParser implements PrefixParser {
@Override
public Expr parse(KaiperParser parser, Token token) { | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/value/DecimalNode.java
// public class DecimalNode extends Single {
// private final double value;
//
// public DecimalNode(Position position, double value) {
// super(position);
// this.value = value;
// }
//
// public double getValue() {
// return value;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public String toString() {
// return String.valueOf(value);
// }
// }
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/parslets/nodes/DecimalParser.java
import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.value.DecimalNode;
import xyz.avarel.kaiper.lexer.Token;
import xyz.avarel.kaiper.parser.KaiperParser;
import xyz.avarel.kaiper.parser.PrefixParser;
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.parser.parslets.nodes;
public class DecimalParser implements PrefixParser {
@Override
public Expr parse(KaiperParser parser, Token token) { | return new DecimalNode(token.getPosition(), Double.parseDouble(token.getString())); |
Avarel/Kaiper | Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/KaiperParserUtils.java | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/value/NullNode.java
// public class NullNode extends Single {
// public static final NullNode VALUE = new NullNode();
//
// private NullNode() {
// super(null);
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/lexer/TokenType.java
// public enum TokenType {
// // PAIRS
// LEFT_PAREN,
// RIGHT_PAREN,
//
// LEFT_BRACKET,
// RIGHT_BRACKET,
//
// LEFT_BRACE,
// RIGHT_BRACE,
//
// OPTIONAL_ASSIGN,
// ELVIS,
//
// // ASSIGNMENT
// ASSIGN,
//
// // TYPES
// INT,
// NUMBER,
// BOOLEAN,
// FUNCTION,
// STRING,
// ATOM,
//
// // ARITHMETIC
// PLUS,
// MINUS,
// ASTERISK,
// SLASH,
// BACKSLASH,
// CARET,
// PERCENT,
//
// // RELATIONAL
// EQUALS,
// NOT_EQUAL,
// GT,
// GTE,
// LT,
// LTE,
// OR,
// AND,
//
// // BOOLEAN
// AMPERSAND,
// VERTICAL_BAR,
//
// // MISC
// REST,
// RANGE_TO,
// PIPE_FORWARD,
// PIPE_BACKWARD,
// SHIFT_RIGHT,
// SHIFT_LEFT,
// ARROW,
// TILDE,
// BANG,
// QUESTION,
// COLON,
// COMMA,
// DOT,
//
// UNDERSCORE,
//
// // SCRIPT
// MODULE,
// TYPE,
// IDENTIFIER,
// NULL,
// LET,
// RETURN,
// IF,
// ELSE,
// FOR,
//
// LINE,
// EOF,
// }
| import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.ast.functions.ParameterData;
import xyz.avarel.kaiper.ast.value.NullNode;
import xyz.avarel.kaiper.exceptions.SyntaxException;
import xyz.avarel.kaiper.lexer.TokenType;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set; | /*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.parser;
public class KaiperParserUtils {
public static Expr parseBlock(KaiperParser parser) { | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/value/NullNode.java
// public class NullNode extends Single {
// public static final NullNode VALUE = new NullNode();
//
// private NullNode() {
// super(null);
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/lexer/TokenType.java
// public enum TokenType {
// // PAIRS
// LEFT_PAREN,
// RIGHT_PAREN,
//
// LEFT_BRACKET,
// RIGHT_BRACKET,
//
// LEFT_BRACE,
// RIGHT_BRACE,
//
// OPTIONAL_ASSIGN,
// ELVIS,
//
// // ASSIGNMENT
// ASSIGN,
//
// // TYPES
// INT,
// NUMBER,
// BOOLEAN,
// FUNCTION,
// STRING,
// ATOM,
//
// // ARITHMETIC
// PLUS,
// MINUS,
// ASTERISK,
// SLASH,
// BACKSLASH,
// CARET,
// PERCENT,
//
// // RELATIONAL
// EQUALS,
// NOT_EQUAL,
// GT,
// GTE,
// LT,
// LTE,
// OR,
// AND,
//
// // BOOLEAN
// AMPERSAND,
// VERTICAL_BAR,
//
// // MISC
// REST,
// RANGE_TO,
// PIPE_FORWARD,
// PIPE_BACKWARD,
// SHIFT_RIGHT,
// SHIFT_LEFT,
// ARROW,
// TILDE,
// BANG,
// QUESTION,
// COLON,
// COMMA,
// DOT,
//
// UNDERSCORE,
//
// // SCRIPT
// MODULE,
// TYPE,
// IDENTIFIER,
// NULL,
// LET,
// RETURN,
// IF,
// ELSE,
// FOR,
//
// LINE,
// EOF,
// }
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/KaiperParserUtils.java
import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.ast.functions.ParameterData;
import xyz.avarel.kaiper.ast.value.NullNode;
import xyz.avarel.kaiper.exceptions.SyntaxException;
import xyz.avarel.kaiper.lexer.TokenType;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.parser;
public class KaiperParserUtils {
public static Expr parseBlock(KaiperParser parser) { | Expr expr = NullNode.VALUE; |
Avarel/Kaiper | Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/KaiperParserUtils.java | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/value/NullNode.java
// public class NullNode extends Single {
// public static final NullNode VALUE = new NullNode();
//
// private NullNode() {
// super(null);
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/lexer/TokenType.java
// public enum TokenType {
// // PAIRS
// LEFT_PAREN,
// RIGHT_PAREN,
//
// LEFT_BRACKET,
// RIGHT_BRACKET,
//
// LEFT_BRACE,
// RIGHT_BRACE,
//
// OPTIONAL_ASSIGN,
// ELVIS,
//
// // ASSIGNMENT
// ASSIGN,
//
// // TYPES
// INT,
// NUMBER,
// BOOLEAN,
// FUNCTION,
// STRING,
// ATOM,
//
// // ARITHMETIC
// PLUS,
// MINUS,
// ASTERISK,
// SLASH,
// BACKSLASH,
// CARET,
// PERCENT,
//
// // RELATIONAL
// EQUALS,
// NOT_EQUAL,
// GT,
// GTE,
// LT,
// LTE,
// OR,
// AND,
//
// // BOOLEAN
// AMPERSAND,
// VERTICAL_BAR,
//
// // MISC
// REST,
// RANGE_TO,
// PIPE_FORWARD,
// PIPE_BACKWARD,
// SHIFT_RIGHT,
// SHIFT_LEFT,
// ARROW,
// TILDE,
// BANG,
// QUESTION,
// COLON,
// COMMA,
// DOT,
//
// UNDERSCORE,
//
// // SCRIPT
// MODULE,
// TYPE,
// IDENTIFIER,
// NULL,
// LET,
// RETURN,
// IF,
// ELSE,
// FOR,
//
// LINE,
// EOF,
// }
| import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.ast.functions.ParameterData;
import xyz.avarel.kaiper.ast.value.NullNode;
import xyz.avarel.kaiper.exceptions.SyntaxException;
import xyz.avarel.kaiper.lexer.TokenType;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set; | /*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.parser;
public class KaiperParserUtils {
public static Expr parseBlock(KaiperParser parser) {
Expr expr = NullNode.VALUE; | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/value/NullNode.java
// public class NullNode extends Single {
// public static final NullNode VALUE = new NullNode();
//
// private NullNode() {
// super(null);
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/lexer/TokenType.java
// public enum TokenType {
// // PAIRS
// LEFT_PAREN,
// RIGHT_PAREN,
//
// LEFT_BRACKET,
// RIGHT_BRACKET,
//
// LEFT_BRACE,
// RIGHT_BRACE,
//
// OPTIONAL_ASSIGN,
// ELVIS,
//
// // ASSIGNMENT
// ASSIGN,
//
// // TYPES
// INT,
// NUMBER,
// BOOLEAN,
// FUNCTION,
// STRING,
// ATOM,
//
// // ARITHMETIC
// PLUS,
// MINUS,
// ASTERISK,
// SLASH,
// BACKSLASH,
// CARET,
// PERCENT,
//
// // RELATIONAL
// EQUALS,
// NOT_EQUAL,
// GT,
// GTE,
// LT,
// LTE,
// OR,
// AND,
//
// // BOOLEAN
// AMPERSAND,
// VERTICAL_BAR,
//
// // MISC
// REST,
// RANGE_TO,
// PIPE_FORWARD,
// PIPE_BACKWARD,
// SHIFT_RIGHT,
// SHIFT_LEFT,
// ARROW,
// TILDE,
// BANG,
// QUESTION,
// COLON,
// COMMA,
// DOT,
//
// UNDERSCORE,
//
// // SCRIPT
// MODULE,
// TYPE,
// IDENTIFIER,
// NULL,
// LET,
// RETURN,
// IF,
// ELSE,
// FOR,
//
// LINE,
// EOF,
// }
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/KaiperParserUtils.java
import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.ast.functions.ParameterData;
import xyz.avarel.kaiper.ast.value.NullNode;
import xyz.avarel.kaiper.exceptions.SyntaxException;
import xyz.avarel.kaiper.lexer.TokenType;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.parser;
public class KaiperParserUtils {
public static Expr parseBlock(KaiperParser parser) {
Expr expr = NullNode.VALUE; | parser.eat(TokenType.LEFT_BRACE); |
Avarel/Kaiper | Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/collections/ArrayNode.java | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/ExprVisitor.java
// public interface ExprVisitor<R, C> {
// R visit(Statements expr, C scope);
//
// R visit(FunctionNode expr, C scope);
//
// R visit(Identifier expr, C scope);
//
// R visit(Invocation expr, C scope);
//
// R visit(BinaryOperation expr, C scope);
//
// R visit(UnaryOperation expr, C scope);
//
// R visit(RangeNode expr, C scope);
//
// R visit(ArrayNode expr, C scope);
//
// R visit(SliceOperation expr, C scope);
//
// R visit(AssignmentExpr expr, C scope);
//
// R visit(GetOperation expr, C scope);
//
// R visit(SetOperation expr, C scope);
//
// R visit(ReturnExpr expr, C scope);
//
// R visit(ConditionalExpr expr, C scope);
//
// R visit(ForEachExpr expr, C scope);
//
// R visit(DictionaryNode expr, C scope);
//
// R visit(NullNode expr, C scope);
//
// R visit(IntNode expr, C scope);
//
// R visit(DecimalNode expr, C scope);
//
// R visit(BooleanNode expr, C scope);
//
// R visit(StringNode expr, C scope);
//
// R visit(DeclarationExpr expr, C scope);
//
// R visit(ModuleNode expr, C scope);
//
// R visit(TypeNode expr, C scope);
//
// R visit(WhileExpr expr, C scope);
// }
| import xyz.avarel.kaiper.ast.ExprVisitor;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.lexer.Position;
import java.util.List; | /*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.ast.collections;
public class ArrayNode extends Single {
private final List<Single> items;
public ArrayNode(Position position, List<Single> items) {
super(position);
this.items = items;
}
public List<Single> getItems() {
return items;
}
@Override | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/ExprVisitor.java
// public interface ExprVisitor<R, C> {
// R visit(Statements expr, C scope);
//
// R visit(FunctionNode expr, C scope);
//
// R visit(Identifier expr, C scope);
//
// R visit(Invocation expr, C scope);
//
// R visit(BinaryOperation expr, C scope);
//
// R visit(UnaryOperation expr, C scope);
//
// R visit(RangeNode expr, C scope);
//
// R visit(ArrayNode expr, C scope);
//
// R visit(SliceOperation expr, C scope);
//
// R visit(AssignmentExpr expr, C scope);
//
// R visit(GetOperation expr, C scope);
//
// R visit(SetOperation expr, C scope);
//
// R visit(ReturnExpr expr, C scope);
//
// R visit(ConditionalExpr expr, C scope);
//
// R visit(ForEachExpr expr, C scope);
//
// R visit(DictionaryNode expr, C scope);
//
// R visit(NullNode expr, C scope);
//
// R visit(IntNode expr, C scope);
//
// R visit(DecimalNode expr, C scope);
//
// R visit(BooleanNode expr, C scope);
//
// R visit(StringNode expr, C scope);
//
// R visit(DeclarationExpr expr, C scope);
//
// R visit(ModuleNode expr, C scope);
//
// R visit(TypeNode expr, C scope);
//
// R visit(WhileExpr expr, C scope);
// }
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/collections/ArrayNode.java
import xyz.avarel.kaiper.ast.ExprVisitor;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.lexer.Position;
import java.util.List;
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.ast.collections;
public class ArrayNode extends Single {
private final List<Single> items;
public ArrayNode(Position position, List<Single> items) {
super(position);
this.items = items;
}
public List<Single> getItems() {
return items;
}
@Override | public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) { |
Avarel/Kaiper | Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/parslets/ModuleParser.java | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/value/NullNode.java
// public class NullNode extends Single {
// public static final NullNode VALUE = new NullNode();
//
// private NullNode() {
// super(null);
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/lexer/TokenType.java
// public enum TokenType {
// // PAIRS
// LEFT_PAREN,
// RIGHT_PAREN,
//
// LEFT_BRACKET,
// RIGHT_BRACKET,
//
// LEFT_BRACE,
// RIGHT_BRACE,
//
// OPTIONAL_ASSIGN,
// ELVIS,
//
// // ASSIGNMENT
// ASSIGN,
//
// // TYPES
// INT,
// NUMBER,
// BOOLEAN,
// FUNCTION,
// STRING,
// ATOM,
//
// // ARITHMETIC
// PLUS,
// MINUS,
// ASTERISK,
// SLASH,
// BACKSLASH,
// CARET,
// PERCENT,
//
// // RELATIONAL
// EQUALS,
// NOT_EQUAL,
// GT,
// GTE,
// LT,
// LTE,
// OR,
// AND,
//
// // BOOLEAN
// AMPERSAND,
// VERTICAL_BAR,
//
// // MISC
// REST,
// RANGE_TO,
// PIPE_FORWARD,
// PIPE_BACKWARD,
// SHIFT_RIGHT,
// SHIFT_LEFT,
// ARROW,
// TILDE,
// BANG,
// QUESTION,
// COLON,
// COMMA,
// DOT,
//
// UNDERSCORE,
//
// // SCRIPT
// MODULE,
// TYPE,
// IDENTIFIER,
// NULL,
// LET,
// RETURN,
// IF,
// ELSE,
// FOR,
//
// LINE,
// EOF,
// }
| import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.ModuleNode;
import xyz.avarel.kaiper.ast.value.NullNode;
import xyz.avarel.kaiper.lexer.Token;
import xyz.avarel.kaiper.lexer.TokenType;
import xyz.avarel.kaiper.parser.KaiperParser;
import xyz.avarel.kaiper.parser.PrefixParser; | package xyz.avarel.kaiper.parser.parslets;
public class ModuleParser implements PrefixParser {
@Override
public Expr parse(KaiperParser parser, Token token) { | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/value/NullNode.java
// public class NullNode extends Single {
// public static final NullNode VALUE = new NullNode();
//
// private NullNode() {
// super(null);
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/lexer/TokenType.java
// public enum TokenType {
// // PAIRS
// LEFT_PAREN,
// RIGHT_PAREN,
//
// LEFT_BRACKET,
// RIGHT_BRACKET,
//
// LEFT_BRACE,
// RIGHT_BRACE,
//
// OPTIONAL_ASSIGN,
// ELVIS,
//
// // ASSIGNMENT
// ASSIGN,
//
// // TYPES
// INT,
// NUMBER,
// BOOLEAN,
// FUNCTION,
// STRING,
// ATOM,
//
// // ARITHMETIC
// PLUS,
// MINUS,
// ASTERISK,
// SLASH,
// BACKSLASH,
// CARET,
// PERCENT,
//
// // RELATIONAL
// EQUALS,
// NOT_EQUAL,
// GT,
// GTE,
// LT,
// LTE,
// OR,
// AND,
//
// // BOOLEAN
// AMPERSAND,
// VERTICAL_BAR,
//
// // MISC
// REST,
// RANGE_TO,
// PIPE_FORWARD,
// PIPE_BACKWARD,
// SHIFT_RIGHT,
// SHIFT_LEFT,
// ARROW,
// TILDE,
// BANG,
// QUESTION,
// COLON,
// COMMA,
// DOT,
//
// UNDERSCORE,
//
// // SCRIPT
// MODULE,
// TYPE,
// IDENTIFIER,
// NULL,
// LET,
// RETURN,
// IF,
// ELSE,
// FOR,
//
// LINE,
// EOF,
// }
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/parslets/ModuleParser.java
import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.ModuleNode;
import xyz.avarel.kaiper.ast.value.NullNode;
import xyz.avarel.kaiper.lexer.Token;
import xyz.avarel.kaiper.lexer.TokenType;
import xyz.avarel.kaiper.parser.KaiperParser;
import xyz.avarel.kaiper.parser.PrefixParser;
package xyz.avarel.kaiper.parser.parslets;
public class ModuleParser implements PrefixParser {
@Override
public Expr parse(KaiperParser parser, Token token) { | String name = parser.eat(TokenType.IDENTIFIER).getString(); |
Avarel/Kaiper | Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/parslets/ModuleParser.java | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/value/NullNode.java
// public class NullNode extends Single {
// public static final NullNode VALUE = new NullNode();
//
// private NullNode() {
// super(null);
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/lexer/TokenType.java
// public enum TokenType {
// // PAIRS
// LEFT_PAREN,
// RIGHT_PAREN,
//
// LEFT_BRACKET,
// RIGHT_BRACKET,
//
// LEFT_BRACE,
// RIGHT_BRACE,
//
// OPTIONAL_ASSIGN,
// ELVIS,
//
// // ASSIGNMENT
// ASSIGN,
//
// // TYPES
// INT,
// NUMBER,
// BOOLEAN,
// FUNCTION,
// STRING,
// ATOM,
//
// // ARITHMETIC
// PLUS,
// MINUS,
// ASTERISK,
// SLASH,
// BACKSLASH,
// CARET,
// PERCENT,
//
// // RELATIONAL
// EQUALS,
// NOT_EQUAL,
// GT,
// GTE,
// LT,
// LTE,
// OR,
// AND,
//
// // BOOLEAN
// AMPERSAND,
// VERTICAL_BAR,
//
// // MISC
// REST,
// RANGE_TO,
// PIPE_FORWARD,
// PIPE_BACKWARD,
// SHIFT_RIGHT,
// SHIFT_LEFT,
// ARROW,
// TILDE,
// BANG,
// QUESTION,
// COLON,
// COMMA,
// DOT,
//
// UNDERSCORE,
//
// // SCRIPT
// MODULE,
// TYPE,
// IDENTIFIER,
// NULL,
// LET,
// RETURN,
// IF,
// ELSE,
// FOR,
//
// LINE,
// EOF,
// }
| import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.ModuleNode;
import xyz.avarel.kaiper.ast.value.NullNode;
import xyz.avarel.kaiper.lexer.Token;
import xyz.avarel.kaiper.lexer.TokenType;
import xyz.avarel.kaiper.parser.KaiperParser;
import xyz.avarel.kaiper.parser.PrefixParser; | package xyz.avarel.kaiper.parser.parslets;
public class ModuleParser implements PrefixParser {
@Override
public Expr parse(KaiperParser parser, Token token) {
String name = parser.eat(TokenType.IDENTIFIER).getString();
| // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/value/NullNode.java
// public class NullNode extends Single {
// public static final NullNode VALUE = new NullNode();
//
// private NullNode() {
// super(null);
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/lexer/TokenType.java
// public enum TokenType {
// // PAIRS
// LEFT_PAREN,
// RIGHT_PAREN,
//
// LEFT_BRACKET,
// RIGHT_BRACKET,
//
// LEFT_BRACE,
// RIGHT_BRACE,
//
// OPTIONAL_ASSIGN,
// ELVIS,
//
// // ASSIGNMENT
// ASSIGN,
//
// // TYPES
// INT,
// NUMBER,
// BOOLEAN,
// FUNCTION,
// STRING,
// ATOM,
//
// // ARITHMETIC
// PLUS,
// MINUS,
// ASTERISK,
// SLASH,
// BACKSLASH,
// CARET,
// PERCENT,
//
// // RELATIONAL
// EQUALS,
// NOT_EQUAL,
// GT,
// GTE,
// LT,
// LTE,
// OR,
// AND,
//
// // BOOLEAN
// AMPERSAND,
// VERTICAL_BAR,
//
// // MISC
// REST,
// RANGE_TO,
// PIPE_FORWARD,
// PIPE_BACKWARD,
// SHIFT_RIGHT,
// SHIFT_LEFT,
// ARROW,
// TILDE,
// BANG,
// QUESTION,
// COLON,
// COMMA,
// DOT,
//
// UNDERSCORE,
//
// // SCRIPT
// MODULE,
// TYPE,
// IDENTIFIER,
// NULL,
// LET,
// RETURN,
// IF,
// ELSE,
// FOR,
//
// LINE,
// EOF,
// }
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/parslets/ModuleParser.java
import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.ModuleNode;
import xyz.avarel.kaiper.ast.value.NullNode;
import xyz.avarel.kaiper.lexer.Token;
import xyz.avarel.kaiper.lexer.TokenType;
import xyz.avarel.kaiper.parser.KaiperParser;
import xyz.avarel.kaiper.parser.PrefixParser;
package xyz.avarel.kaiper.parser.parslets;
public class ModuleParser implements PrefixParser {
@Override
public Expr parse(KaiperParser parser, Token token) {
String name = parser.eat(TokenType.IDENTIFIER).getString();
| Expr expr = NullNode.VALUE; |
Avarel/Kaiper | Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/parslets/nodes/IntParser.java | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/value/IntNode.java
// public class IntNode extends Single {
// private final int value;
//
// public IntNode(Position position, int value) {
// super(position);
// this.value = value;
// }
//
// public int getValue() {
// return value;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public String toString() {
// return String.valueOf(value);
// }
// }
| import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.value.IntNode;
import xyz.avarel.kaiper.lexer.Token;
import xyz.avarel.kaiper.parser.KaiperParser;
import xyz.avarel.kaiper.parser.PrefixParser; | /*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.parser.parslets.nodes;
public class IntParser implements PrefixParser {
@Override
public Expr parse(KaiperParser parser, Token token) { | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/value/IntNode.java
// public class IntNode extends Single {
// private final int value;
//
// public IntNode(Position position, int value) {
// super(position);
// this.value = value;
// }
//
// public int getValue() {
// return value;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public String toString() {
// return String.valueOf(value);
// }
// }
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/parslets/nodes/IntParser.java
import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.value.IntNode;
import xyz.avarel.kaiper.lexer.Token;
import xyz.avarel.kaiper.parser.KaiperParser;
import xyz.avarel.kaiper.parser.PrefixParser;
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.parser.parslets.nodes;
public class IntParser implements PrefixParser {
@Override
public Expr parse(KaiperParser parser, Token token) { | return new IntNode(token.getPosition(), Integer.parseInt(token.getString())); |
Avarel/Kaiper | Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/functions/FunctionNode.java | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/ExprVisitor.java
// public interface ExprVisitor<R, C> {
// R visit(Statements expr, C scope);
//
// R visit(FunctionNode expr, C scope);
//
// R visit(Identifier expr, C scope);
//
// R visit(Invocation expr, C scope);
//
// R visit(BinaryOperation expr, C scope);
//
// R visit(UnaryOperation expr, C scope);
//
// R visit(RangeNode expr, C scope);
//
// R visit(ArrayNode expr, C scope);
//
// R visit(SliceOperation expr, C scope);
//
// R visit(AssignmentExpr expr, C scope);
//
// R visit(GetOperation expr, C scope);
//
// R visit(SetOperation expr, C scope);
//
// R visit(ReturnExpr expr, C scope);
//
// R visit(ConditionalExpr expr, C scope);
//
// R visit(ForEachExpr expr, C scope);
//
// R visit(DictionaryNode expr, C scope);
//
// R visit(NullNode expr, C scope);
//
// R visit(IntNode expr, C scope);
//
// R visit(DecimalNode expr, C scope);
//
// R visit(BooleanNode expr, C scope);
//
// R visit(StringNode expr, C scope);
//
// R visit(DeclarationExpr expr, C scope);
//
// R visit(ModuleNode expr, C scope);
//
// R visit(TypeNode expr, C scope);
//
// R visit(WhileExpr expr, C scope);
// }
| import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.ExprVisitor;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.lexer.Position;
import java.util.List;
import java.util.stream.Collectors; | /*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.ast.functions;
public class FunctionNode extends Single {
private final String name;
private final List<ParameterData> parameters;
private final Expr expr;
public FunctionNode(Position position, List<ParameterData> parameters, Expr expr) {
this(position, null, parameters, expr);
}
public FunctionNode(Position position, String name, List<ParameterData> parameters, Expr expr) {
super(position);
this.name = name;
this.parameters = parameters;
this.expr = expr;
}
public String getName() {
return name;
}
public List<ParameterData> getParameterExprs() {
return parameters;
}
public Expr getExpr() {
return expr;
}
@Override | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/ExprVisitor.java
// public interface ExprVisitor<R, C> {
// R visit(Statements expr, C scope);
//
// R visit(FunctionNode expr, C scope);
//
// R visit(Identifier expr, C scope);
//
// R visit(Invocation expr, C scope);
//
// R visit(BinaryOperation expr, C scope);
//
// R visit(UnaryOperation expr, C scope);
//
// R visit(RangeNode expr, C scope);
//
// R visit(ArrayNode expr, C scope);
//
// R visit(SliceOperation expr, C scope);
//
// R visit(AssignmentExpr expr, C scope);
//
// R visit(GetOperation expr, C scope);
//
// R visit(SetOperation expr, C scope);
//
// R visit(ReturnExpr expr, C scope);
//
// R visit(ConditionalExpr expr, C scope);
//
// R visit(ForEachExpr expr, C scope);
//
// R visit(DictionaryNode expr, C scope);
//
// R visit(NullNode expr, C scope);
//
// R visit(IntNode expr, C scope);
//
// R visit(DecimalNode expr, C scope);
//
// R visit(BooleanNode expr, C scope);
//
// R visit(StringNode expr, C scope);
//
// R visit(DeclarationExpr expr, C scope);
//
// R visit(ModuleNode expr, C scope);
//
// R visit(TypeNode expr, C scope);
//
// R visit(WhileExpr expr, C scope);
// }
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/functions/FunctionNode.java
import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.ExprVisitor;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.lexer.Position;
import java.util.List;
import java.util.stream.Collectors;
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.ast.functions;
public class FunctionNode extends Single {
private final String name;
private final List<ParameterData> parameters;
private final Expr expr;
public FunctionNode(Position position, List<ParameterData> parameters, Expr expr) {
this(position, null, parameters, expr);
}
public FunctionNode(Position position, String name, List<ParameterData> parameters, Expr expr) {
super(position);
this.name = name;
this.parameters = parameters;
this.expr = expr;
}
public String getName() {
return name;
}
public List<ParameterData> getParameterExprs() {
return parameters;
}
public Expr getExpr() {
return expr;
}
@Override | public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) { |
Avarel/Kaiper | Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/flow/WhileExpr.java | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/ExprVisitor.java
// public interface ExprVisitor<R, C> {
// R visit(Statements expr, C scope);
//
// R visit(FunctionNode expr, C scope);
//
// R visit(Identifier expr, C scope);
//
// R visit(Invocation expr, C scope);
//
// R visit(BinaryOperation expr, C scope);
//
// R visit(UnaryOperation expr, C scope);
//
// R visit(RangeNode expr, C scope);
//
// R visit(ArrayNode expr, C scope);
//
// R visit(SliceOperation expr, C scope);
//
// R visit(AssignmentExpr expr, C scope);
//
// R visit(GetOperation expr, C scope);
//
// R visit(SetOperation expr, C scope);
//
// R visit(ReturnExpr expr, C scope);
//
// R visit(ConditionalExpr expr, C scope);
//
// R visit(ForEachExpr expr, C scope);
//
// R visit(DictionaryNode expr, C scope);
//
// R visit(NullNode expr, C scope);
//
// R visit(IntNode expr, C scope);
//
// R visit(DecimalNode expr, C scope);
//
// R visit(BooleanNode expr, C scope);
//
// R visit(StringNode expr, C scope);
//
// R visit(DeclarationExpr expr, C scope);
//
// R visit(ModuleNode expr, C scope);
//
// R visit(TypeNode expr, C scope);
//
// R visit(WhileExpr expr, C scope);
// }
| import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.ExprVisitor;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.lexer.Position; | /*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.ast.flow;
public class WhileExpr extends Single {
private final Single condition;
private final Expr action;
public WhileExpr(Position position, Single condition, Expr action) {
super(position);
this.condition = condition;
this.action = action;
}
public Single getCondition() {
return condition;
}
public Expr getAction() {
return action;
}
@Override | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/ExprVisitor.java
// public interface ExprVisitor<R, C> {
// R visit(Statements expr, C scope);
//
// R visit(FunctionNode expr, C scope);
//
// R visit(Identifier expr, C scope);
//
// R visit(Invocation expr, C scope);
//
// R visit(BinaryOperation expr, C scope);
//
// R visit(UnaryOperation expr, C scope);
//
// R visit(RangeNode expr, C scope);
//
// R visit(ArrayNode expr, C scope);
//
// R visit(SliceOperation expr, C scope);
//
// R visit(AssignmentExpr expr, C scope);
//
// R visit(GetOperation expr, C scope);
//
// R visit(SetOperation expr, C scope);
//
// R visit(ReturnExpr expr, C scope);
//
// R visit(ConditionalExpr expr, C scope);
//
// R visit(ForEachExpr expr, C scope);
//
// R visit(DictionaryNode expr, C scope);
//
// R visit(NullNode expr, C scope);
//
// R visit(IntNode expr, C scope);
//
// R visit(DecimalNode expr, C scope);
//
// R visit(BooleanNode expr, C scope);
//
// R visit(StringNode expr, C scope);
//
// R visit(DeclarationExpr expr, C scope);
//
// R visit(ModuleNode expr, C scope);
//
// R visit(TypeNode expr, C scope);
//
// R visit(WhileExpr expr, C scope);
// }
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/flow/WhileExpr.java
import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.ExprVisitor;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.lexer.Position;
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.ast.flow;
public class WhileExpr extends Single {
private final Single condition;
private final Expr action;
public WhileExpr(Position position, Single condition, Expr action) {
super(position);
this.condition = condition;
this.action = action;
}
public Single getCondition() {
return condition;
}
public Expr getAction() {
return action;
}
@Override | public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) { |
Avarel/Kaiper | Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/ExprVisitor.java | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/functions/FunctionNode.java
// public class FunctionNode extends Single {
// private final String name;
// private final List<ParameterData> parameters;
// private final Expr expr;
//
// public FunctionNode(Position position, List<ParameterData> parameters, Expr expr) {
// this(position, null, parameters, expr);
// }
//
// public FunctionNode(Position position, String name, List<ParameterData> parameters, Expr expr) {
// super(position);
// this.name = name;
// this.parameters = parameters;
// this.expr = expr;
// }
//
// public String getName() {
// return name;
// }
//
// public List<ParameterData> getParameterExprs() {
// return parameters;
// }
//
// public Expr getExpr() {
// return expr;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// builder.append(indent).append(isTail ? "└── " : "├── ")
// .append("func").append(name != null ? " " + name : "")
// .append('(')
// .append(getParameterExprs().stream().map(Object::toString)
// .collect(Collectors.joining(", ")))
// .append(')');
//
// builder.append('\n');
// expr.ast(builder, indent + (isTail ? " " : "│ "), true);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/invocation/Invocation.java
// public class Invocation extends Single {
// private final Single left;
// private final List<Single> arguments;
//
// public Invocation(Position position, Single left, List<Single> arguments) {
// super(position);
// this.left = left;
// this.arguments = arguments;
// }
//
// public Single getLeft() {
// return left;
// }
//
// public List<Single> getArguments() {
// return arguments;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// builder.append(indent).append(isTail ? "└── " : "├── ").append("invoke");
//
// builder.append('\n');
// left.ast("target", builder, indent + (isTail ? " " : "│ "), false);
//
// builder.append('\n');
// if (arguments.isEmpty()) {
// builder.append(indent).append(isTail ? " " : "│ ").append("└── ").append("*");
// } else {
// for (int i = 0; i < arguments.size() - 1; i++) {
// arguments.get(i).ast(builder, indent + (isTail ? " " : "│ "), false);
// builder.append('\n');
// }
// if (arguments.size() > 0) {
// arguments.get(arguments.size() - 1).ast(builder, indent + (isTail ? " " : "│ "), true);
// }
// }
// }
// }
| import xyz.avarel.kaiper.ast.collections.*;
import xyz.avarel.kaiper.ast.flow.*;
import xyz.avarel.kaiper.ast.functions.FunctionNode;
import xyz.avarel.kaiper.ast.invocation.Invocation;
import xyz.avarel.kaiper.ast.operations.BinaryOperation;
import xyz.avarel.kaiper.ast.operations.SliceOperation;
import xyz.avarel.kaiper.ast.operations.UnaryOperation;
import xyz.avarel.kaiper.ast.value.*;
import xyz.avarel.kaiper.ast.variables.AssignmentExpr;
import xyz.avarel.kaiper.ast.variables.DeclarationExpr;
import xyz.avarel.kaiper.ast.variables.Identifier; | /*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.ast;
public interface ExprVisitor<R, C> {
R visit(Statements expr, C scope);
| // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/functions/FunctionNode.java
// public class FunctionNode extends Single {
// private final String name;
// private final List<ParameterData> parameters;
// private final Expr expr;
//
// public FunctionNode(Position position, List<ParameterData> parameters, Expr expr) {
// this(position, null, parameters, expr);
// }
//
// public FunctionNode(Position position, String name, List<ParameterData> parameters, Expr expr) {
// super(position);
// this.name = name;
// this.parameters = parameters;
// this.expr = expr;
// }
//
// public String getName() {
// return name;
// }
//
// public List<ParameterData> getParameterExprs() {
// return parameters;
// }
//
// public Expr getExpr() {
// return expr;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// builder.append(indent).append(isTail ? "└── " : "├── ")
// .append("func").append(name != null ? " " + name : "")
// .append('(')
// .append(getParameterExprs().stream().map(Object::toString)
// .collect(Collectors.joining(", ")))
// .append(')');
//
// builder.append('\n');
// expr.ast(builder, indent + (isTail ? " " : "│ "), true);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/invocation/Invocation.java
// public class Invocation extends Single {
// private final Single left;
// private final List<Single> arguments;
//
// public Invocation(Position position, Single left, List<Single> arguments) {
// super(position);
// this.left = left;
// this.arguments = arguments;
// }
//
// public Single getLeft() {
// return left;
// }
//
// public List<Single> getArguments() {
// return arguments;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// builder.append(indent).append(isTail ? "└── " : "├── ").append("invoke");
//
// builder.append('\n');
// left.ast("target", builder, indent + (isTail ? " " : "│ "), false);
//
// builder.append('\n');
// if (arguments.isEmpty()) {
// builder.append(indent).append(isTail ? " " : "│ ").append("└── ").append("*");
// } else {
// for (int i = 0; i < arguments.size() - 1; i++) {
// arguments.get(i).ast(builder, indent + (isTail ? " " : "│ "), false);
// builder.append('\n');
// }
// if (arguments.size() > 0) {
// arguments.get(arguments.size() - 1).ast(builder, indent + (isTail ? " " : "│ "), true);
// }
// }
// }
// }
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/ExprVisitor.java
import xyz.avarel.kaiper.ast.collections.*;
import xyz.avarel.kaiper.ast.flow.*;
import xyz.avarel.kaiper.ast.functions.FunctionNode;
import xyz.avarel.kaiper.ast.invocation.Invocation;
import xyz.avarel.kaiper.ast.operations.BinaryOperation;
import xyz.avarel.kaiper.ast.operations.SliceOperation;
import xyz.avarel.kaiper.ast.operations.UnaryOperation;
import xyz.avarel.kaiper.ast.value.*;
import xyz.avarel.kaiper.ast.variables.AssignmentExpr;
import xyz.avarel.kaiper.ast.variables.DeclarationExpr;
import xyz.avarel.kaiper.ast.variables.Identifier;
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.ast;
public interface ExprVisitor<R, C> {
R visit(Statements expr, C scope);
| R visit(FunctionNode expr, C scope); |
Avarel/Kaiper | Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/ExprVisitor.java | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/functions/FunctionNode.java
// public class FunctionNode extends Single {
// private final String name;
// private final List<ParameterData> parameters;
// private final Expr expr;
//
// public FunctionNode(Position position, List<ParameterData> parameters, Expr expr) {
// this(position, null, parameters, expr);
// }
//
// public FunctionNode(Position position, String name, List<ParameterData> parameters, Expr expr) {
// super(position);
// this.name = name;
// this.parameters = parameters;
// this.expr = expr;
// }
//
// public String getName() {
// return name;
// }
//
// public List<ParameterData> getParameterExprs() {
// return parameters;
// }
//
// public Expr getExpr() {
// return expr;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// builder.append(indent).append(isTail ? "└── " : "├── ")
// .append("func").append(name != null ? " " + name : "")
// .append('(')
// .append(getParameterExprs().stream().map(Object::toString)
// .collect(Collectors.joining(", ")))
// .append(')');
//
// builder.append('\n');
// expr.ast(builder, indent + (isTail ? " " : "│ "), true);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/invocation/Invocation.java
// public class Invocation extends Single {
// private final Single left;
// private final List<Single> arguments;
//
// public Invocation(Position position, Single left, List<Single> arguments) {
// super(position);
// this.left = left;
// this.arguments = arguments;
// }
//
// public Single getLeft() {
// return left;
// }
//
// public List<Single> getArguments() {
// return arguments;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// builder.append(indent).append(isTail ? "└── " : "├── ").append("invoke");
//
// builder.append('\n');
// left.ast("target", builder, indent + (isTail ? " " : "│ "), false);
//
// builder.append('\n');
// if (arguments.isEmpty()) {
// builder.append(indent).append(isTail ? " " : "│ ").append("└── ").append("*");
// } else {
// for (int i = 0; i < arguments.size() - 1; i++) {
// arguments.get(i).ast(builder, indent + (isTail ? " " : "│ "), false);
// builder.append('\n');
// }
// if (arguments.size() > 0) {
// arguments.get(arguments.size() - 1).ast(builder, indent + (isTail ? " " : "│ "), true);
// }
// }
// }
// }
| import xyz.avarel.kaiper.ast.collections.*;
import xyz.avarel.kaiper.ast.flow.*;
import xyz.avarel.kaiper.ast.functions.FunctionNode;
import xyz.avarel.kaiper.ast.invocation.Invocation;
import xyz.avarel.kaiper.ast.operations.BinaryOperation;
import xyz.avarel.kaiper.ast.operations.SliceOperation;
import xyz.avarel.kaiper.ast.operations.UnaryOperation;
import xyz.avarel.kaiper.ast.value.*;
import xyz.avarel.kaiper.ast.variables.AssignmentExpr;
import xyz.avarel.kaiper.ast.variables.DeclarationExpr;
import xyz.avarel.kaiper.ast.variables.Identifier; | /*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.ast;
public interface ExprVisitor<R, C> {
R visit(Statements expr, C scope);
R visit(FunctionNode expr, C scope);
R visit(Identifier expr, C scope);
| // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/functions/FunctionNode.java
// public class FunctionNode extends Single {
// private final String name;
// private final List<ParameterData> parameters;
// private final Expr expr;
//
// public FunctionNode(Position position, List<ParameterData> parameters, Expr expr) {
// this(position, null, parameters, expr);
// }
//
// public FunctionNode(Position position, String name, List<ParameterData> parameters, Expr expr) {
// super(position);
// this.name = name;
// this.parameters = parameters;
// this.expr = expr;
// }
//
// public String getName() {
// return name;
// }
//
// public List<ParameterData> getParameterExprs() {
// return parameters;
// }
//
// public Expr getExpr() {
// return expr;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// builder.append(indent).append(isTail ? "└── " : "├── ")
// .append("func").append(name != null ? " " + name : "")
// .append('(')
// .append(getParameterExprs().stream().map(Object::toString)
// .collect(Collectors.joining(", ")))
// .append(')');
//
// builder.append('\n');
// expr.ast(builder, indent + (isTail ? " " : "│ "), true);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/invocation/Invocation.java
// public class Invocation extends Single {
// private final Single left;
// private final List<Single> arguments;
//
// public Invocation(Position position, Single left, List<Single> arguments) {
// super(position);
// this.left = left;
// this.arguments = arguments;
// }
//
// public Single getLeft() {
// return left;
// }
//
// public List<Single> getArguments() {
// return arguments;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// builder.append(indent).append(isTail ? "└── " : "├── ").append("invoke");
//
// builder.append('\n');
// left.ast("target", builder, indent + (isTail ? " " : "│ "), false);
//
// builder.append('\n');
// if (arguments.isEmpty()) {
// builder.append(indent).append(isTail ? " " : "│ ").append("└── ").append("*");
// } else {
// for (int i = 0; i < arguments.size() - 1; i++) {
// arguments.get(i).ast(builder, indent + (isTail ? " " : "│ "), false);
// builder.append('\n');
// }
// if (arguments.size() > 0) {
// arguments.get(arguments.size() - 1).ast(builder, indent + (isTail ? " " : "│ "), true);
// }
// }
// }
// }
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/ExprVisitor.java
import xyz.avarel.kaiper.ast.collections.*;
import xyz.avarel.kaiper.ast.flow.*;
import xyz.avarel.kaiper.ast.functions.FunctionNode;
import xyz.avarel.kaiper.ast.invocation.Invocation;
import xyz.avarel.kaiper.ast.operations.BinaryOperation;
import xyz.avarel.kaiper.ast.operations.SliceOperation;
import xyz.avarel.kaiper.ast.operations.UnaryOperation;
import xyz.avarel.kaiper.ast.value.*;
import xyz.avarel.kaiper.ast.variables.AssignmentExpr;
import xyz.avarel.kaiper.ast.variables.DeclarationExpr;
import xyz.avarel.kaiper.ast.variables.Identifier;
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.ast;
public interface ExprVisitor<R, C> {
R visit(Statements expr, C scope);
R visit(FunctionNode expr, C scope);
R visit(Identifier expr, C scope);
| R visit(Invocation expr, C scope); |
Avarel/Kaiper | Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/value/IntNode.java | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/ExprVisitor.java
// public interface ExprVisitor<R, C> {
// R visit(Statements expr, C scope);
//
// R visit(FunctionNode expr, C scope);
//
// R visit(Identifier expr, C scope);
//
// R visit(Invocation expr, C scope);
//
// R visit(BinaryOperation expr, C scope);
//
// R visit(UnaryOperation expr, C scope);
//
// R visit(RangeNode expr, C scope);
//
// R visit(ArrayNode expr, C scope);
//
// R visit(SliceOperation expr, C scope);
//
// R visit(AssignmentExpr expr, C scope);
//
// R visit(GetOperation expr, C scope);
//
// R visit(SetOperation expr, C scope);
//
// R visit(ReturnExpr expr, C scope);
//
// R visit(ConditionalExpr expr, C scope);
//
// R visit(ForEachExpr expr, C scope);
//
// R visit(DictionaryNode expr, C scope);
//
// R visit(NullNode expr, C scope);
//
// R visit(IntNode expr, C scope);
//
// R visit(DecimalNode expr, C scope);
//
// R visit(BooleanNode expr, C scope);
//
// R visit(StringNode expr, C scope);
//
// R visit(DeclarationExpr expr, C scope);
//
// R visit(ModuleNode expr, C scope);
//
// R visit(TypeNode expr, C scope);
//
// R visit(WhileExpr expr, C scope);
// }
| import xyz.avarel.kaiper.ast.ExprVisitor;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.lexer.Position; | /*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.ast.value;
public class IntNode extends Single {
private final int value;
public IntNode(Position position, int value) {
super(position);
this.value = value;
}
public int getValue() {
return value;
}
@Override | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/ExprVisitor.java
// public interface ExprVisitor<R, C> {
// R visit(Statements expr, C scope);
//
// R visit(FunctionNode expr, C scope);
//
// R visit(Identifier expr, C scope);
//
// R visit(Invocation expr, C scope);
//
// R visit(BinaryOperation expr, C scope);
//
// R visit(UnaryOperation expr, C scope);
//
// R visit(RangeNode expr, C scope);
//
// R visit(ArrayNode expr, C scope);
//
// R visit(SliceOperation expr, C scope);
//
// R visit(AssignmentExpr expr, C scope);
//
// R visit(GetOperation expr, C scope);
//
// R visit(SetOperation expr, C scope);
//
// R visit(ReturnExpr expr, C scope);
//
// R visit(ConditionalExpr expr, C scope);
//
// R visit(ForEachExpr expr, C scope);
//
// R visit(DictionaryNode expr, C scope);
//
// R visit(NullNode expr, C scope);
//
// R visit(IntNode expr, C scope);
//
// R visit(DecimalNode expr, C scope);
//
// R visit(BooleanNode expr, C scope);
//
// R visit(StringNode expr, C scope);
//
// R visit(DeclarationExpr expr, C scope);
//
// R visit(ModuleNode expr, C scope);
//
// R visit(TypeNode expr, C scope);
//
// R visit(WhileExpr expr, C scope);
// }
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/value/IntNode.java
import xyz.avarel.kaiper.ast.ExprVisitor;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.lexer.Position;
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.ast.value;
public class IntNode extends Single {
private final int value;
public IntNode(Position position, int value) {
super(position);
this.value = value;
}
public int getValue() {
return value;
}
@Override | public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) { |
Avarel/Kaiper | Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/value/NullNode.java | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/ExprVisitor.java
// public interface ExprVisitor<R, C> {
// R visit(Statements expr, C scope);
//
// R visit(FunctionNode expr, C scope);
//
// R visit(Identifier expr, C scope);
//
// R visit(Invocation expr, C scope);
//
// R visit(BinaryOperation expr, C scope);
//
// R visit(UnaryOperation expr, C scope);
//
// R visit(RangeNode expr, C scope);
//
// R visit(ArrayNode expr, C scope);
//
// R visit(SliceOperation expr, C scope);
//
// R visit(AssignmentExpr expr, C scope);
//
// R visit(GetOperation expr, C scope);
//
// R visit(SetOperation expr, C scope);
//
// R visit(ReturnExpr expr, C scope);
//
// R visit(ConditionalExpr expr, C scope);
//
// R visit(ForEachExpr expr, C scope);
//
// R visit(DictionaryNode expr, C scope);
//
// R visit(NullNode expr, C scope);
//
// R visit(IntNode expr, C scope);
//
// R visit(DecimalNode expr, C scope);
//
// R visit(BooleanNode expr, C scope);
//
// R visit(StringNode expr, C scope);
//
// R visit(DeclarationExpr expr, C scope);
//
// R visit(ModuleNode expr, C scope);
//
// R visit(TypeNode expr, C scope);
//
// R visit(WhileExpr expr, C scope);
// }
| import xyz.avarel.kaiper.ast.ExprVisitor;
import xyz.avarel.kaiper.ast.Single; | /*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.ast.value;
public class NullNode extends Single {
public static final NullNode VALUE = new NullNode();
private NullNode() {
super(null);
}
@Override | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/ExprVisitor.java
// public interface ExprVisitor<R, C> {
// R visit(Statements expr, C scope);
//
// R visit(FunctionNode expr, C scope);
//
// R visit(Identifier expr, C scope);
//
// R visit(Invocation expr, C scope);
//
// R visit(BinaryOperation expr, C scope);
//
// R visit(UnaryOperation expr, C scope);
//
// R visit(RangeNode expr, C scope);
//
// R visit(ArrayNode expr, C scope);
//
// R visit(SliceOperation expr, C scope);
//
// R visit(AssignmentExpr expr, C scope);
//
// R visit(GetOperation expr, C scope);
//
// R visit(SetOperation expr, C scope);
//
// R visit(ReturnExpr expr, C scope);
//
// R visit(ConditionalExpr expr, C scope);
//
// R visit(ForEachExpr expr, C scope);
//
// R visit(DictionaryNode expr, C scope);
//
// R visit(NullNode expr, C scope);
//
// R visit(IntNode expr, C scope);
//
// R visit(DecimalNode expr, C scope);
//
// R visit(BooleanNode expr, C scope);
//
// R visit(StringNode expr, C scope);
//
// R visit(DeclarationExpr expr, C scope);
//
// R visit(ModuleNode expr, C scope);
//
// R visit(TypeNode expr, C scope);
//
// R visit(WhileExpr expr, C scope);
// }
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/value/NullNode.java
import xyz.avarel.kaiper.ast.ExprVisitor;
import xyz.avarel.kaiper.ast.Single;
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.ast.value;
public class NullNode extends Single {
public static final NullNode VALUE = new NullNode();
private NullNode() {
super(null);
}
@Override | public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) { |
Avarel/Kaiper | Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/invocation/Invocation.java | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/ExprVisitor.java
// public interface ExprVisitor<R, C> {
// R visit(Statements expr, C scope);
//
// R visit(FunctionNode expr, C scope);
//
// R visit(Identifier expr, C scope);
//
// R visit(Invocation expr, C scope);
//
// R visit(BinaryOperation expr, C scope);
//
// R visit(UnaryOperation expr, C scope);
//
// R visit(RangeNode expr, C scope);
//
// R visit(ArrayNode expr, C scope);
//
// R visit(SliceOperation expr, C scope);
//
// R visit(AssignmentExpr expr, C scope);
//
// R visit(GetOperation expr, C scope);
//
// R visit(SetOperation expr, C scope);
//
// R visit(ReturnExpr expr, C scope);
//
// R visit(ConditionalExpr expr, C scope);
//
// R visit(ForEachExpr expr, C scope);
//
// R visit(DictionaryNode expr, C scope);
//
// R visit(NullNode expr, C scope);
//
// R visit(IntNode expr, C scope);
//
// R visit(DecimalNode expr, C scope);
//
// R visit(BooleanNode expr, C scope);
//
// R visit(StringNode expr, C scope);
//
// R visit(DeclarationExpr expr, C scope);
//
// R visit(ModuleNode expr, C scope);
//
// R visit(TypeNode expr, C scope);
//
// R visit(WhileExpr expr, C scope);
// }
| import xyz.avarel.kaiper.ast.ExprVisitor;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.lexer.Position;
import java.util.List; | /*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.ast.invocation;
public class Invocation extends Single {
private final Single left;
private final List<Single> arguments;
public Invocation(Position position, Single left, List<Single> arguments) {
super(position);
this.left = left;
this.arguments = arguments;
}
public Single getLeft() {
return left;
}
public List<Single> getArguments() {
return arguments;
}
@Override | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/ExprVisitor.java
// public interface ExprVisitor<R, C> {
// R visit(Statements expr, C scope);
//
// R visit(FunctionNode expr, C scope);
//
// R visit(Identifier expr, C scope);
//
// R visit(Invocation expr, C scope);
//
// R visit(BinaryOperation expr, C scope);
//
// R visit(UnaryOperation expr, C scope);
//
// R visit(RangeNode expr, C scope);
//
// R visit(ArrayNode expr, C scope);
//
// R visit(SliceOperation expr, C scope);
//
// R visit(AssignmentExpr expr, C scope);
//
// R visit(GetOperation expr, C scope);
//
// R visit(SetOperation expr, C scope);
//
// R visit(ReturnExpr expr, C scope);
//
// R visit(ConditionalExpr expr, C scope);
//
// R visit(ForEachExpr expr, C scope);
//
// R visit(DictionaryNode expr, C scope);
//
// R visit(NullNode expr, C scope);
//
// R visit(IntNode expr, C scope);
//
// R visit(DecimalNode expr, C scope);
//
// R visit(BooleanNode expr, C scope);
//
// R visit(StringNode expr, C scope);
//
// R visit(DeclarationExpr expr, C scope);
//
// R visit(ModuleNode expr, C scope);
//
// R visit(TypeNode expr, C scope);
//
// R visit(WhileExpr expr, C scope);
// }
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/invocation/Invocation.java
import xyz.avarel.kaiper.ast.ExprVisitor;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.lexer.Position;
import java.util.List;
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.ast.invocation;
public class Invocation extends Single {
private final Single left;
private final List<Single> arguments;
public Invocation(Position position, Single left, List<Single> arguments) {
super(position);
this.left = left;
this.arguments = arguments;
}
public Single getLeft() {
return left;
}
public List<Single> getArguments() {
return arguments;
}
@Override | public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) { |
Avarel/Kaiper | Kaiper-Compiler/src/main/java/xyz/avarel/kaiper/compiler/ExprCompiler.java | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/functions/FunctionNode.java
// public class FunctionNode extends Single {
// private final String name;
// private final List<ParameterData> parameters;
// private final Expr expr;
//
// public FunctionNode(Position position, List<ParameterData> parameters, Expr expr) {
// this(position, null, parameters, expr);
// }
//
// public FunctionNode(Position position, String name, List<ParameterData> parameters, Expr expr) {
// super(position);
// this.name = name;
// this.parameters = parameters;
// this.expr = expr;
// }
//
// public String getName() {
// return name;
// }
//
// public List<ParameterData> getParameterExprs() {
// return parameters;
// }
//
// public Expr getExpr() {
// return expr;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// builder.append(indent).append(isTail ? "└── " : "├── ")
// .append("func").append(name != null ? " " + name : "")
// .append('(')
// .append(getParameterExprs().stream().map(Object::toString)
// .collect(Collectors.joining(", ")))
// .append(')');
//
// builder.append('\n');
// expr.ast(builder, indent + (isTail ? " " : "│ "), true);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/invocation/Invocation.java
// public class Invocation extends Single {
// private final Single left;
// private final List<Single> arguments;
//
// public Invocation(Position position, Single left, List<Single> arguments) {
// super(position);
// this.left = left;
// this.arguments = arguments;
// }
//
// public Single getLeft() {
// return left;
// }
//
// public List<Single> getArguments() {
// return arguments;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// builder.append(indent).append(isTail ? "└── " : "├── ").append("invoke");
//
// builder.append('\n');
// left.ast("target", builder, indent + (isTail ? " " : "│ "), false);
//
// builder.append('\n');
// if (arguments.isEmpty()) {
// builder.append(indent).append(isTail ? " " : "│ ").append("└── ").append("*");
// } else {
// for (int i = 0; i < arguments.size() - 1; i++) {
// arguments.get(i).ast(builder, indent + (isTail ? " " : "│ "), false);
// builder.append('\n');
// }
// if (arguments.size() > 0) {
// arguments.get(arguments.size() - 1).ast(builder, indent + (isTail ? " " : "│ "), true);
// }
// }
// }
// }
//
// Path: Kaiper-Bytecode/src/main/java/xyz/avarel/kaiper/bytecode/DataOutputConsumer.java
// @FunctionalInterface
// public interface DataOutputConsumer {
// void writeInto(DataOutput output) throws IOException;
//
// default DataOutputConsumer andThen(DataOutputConsumer after) {
// Objects.requireNonNull(after);
// return (DataOutput t) -> {
// writeInto(t);
// after.writeInto(t);
// };
// }
// }
| import xyz.avarel.kaiper.ast.*;
import xyz.avarel.kaiper.ast.collections.*;
import xyz.avarel.kaiper.ast.flow.*;
import xyz.avarel.kaiper.ast.functions.FunctionNode;
import xyz.avarel.kaiper.ast.functions.ParameterData;
import xyz.avarel.kaiper.ast.invocation.Invocation;
import xyz.avarel.kaiper.ast.operations.BinaryOperation;
import xyz.avarel.kaiper.ast.operations.SliceOperation;
import xyz.avarel.kaiper.ast.operations.UnaryOperation;
import xyz.avarel.kaiper.ast.value.*;
import xyz.avarel.kaiper.ast.variables.AssignmentExpr;
import xyz.avarel.kaiper.ast.variables.DeclarationExpr;
import xyz.avarel.kaiper.ast.variables.Identifier;
import xyz.avarel.kaiper.bytecode.DataOutputConsumer;
import java.util.*;
import java.util.stream.Collectors;
import static xyz.avarel.kaiper.bytecode.Opcodes.*; | public DataOutputConsumer stringPool() {
ArrayList<String> strings = new ArrayList<>(stringPool);
return out -> {
out.writeShort(strings.size());
for (String s : strings) {
out.writeUTF(s);
}
};
}
@Override
public DataOutputConsumer visit(Statements expr, Void scope) {
Iterator<Expr> iterator = expr.getExprs().iterator();
if (!iterator.hasNext()) return NO_OP_CONSUMER;
DataOutputConsumer consumer = iterator.next().accept(this, null);
if (!iterator.hasNext()) return consumer;
consumer = consumer.andThen(POP);
while (iterator.hasNext()) {
consumer = consumer.andThen(iterator.next().accept(this, null));
if (iterator.hasNext()) consumer = consumer.andThen(POP);
}
return consumer;
}
@Override | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/functions/FunctionNode.java
// public class FunctionNode extends Single {
// private final String name;
// private final List<ParameterData> parameters;
// private final Expr expr;
//
// public FunctionNode(Position position, List<ParameterData> parameters, Expr expr) {
// this(position, null, parameters, expr);
// }
//
// public FunctionNode(Position position, String name, List<ParameterData> parameters, Expr expr) {
// super(position);
// this.name = name;
// this.parameters = parameters;
// this.expr = expr;
// }
//
// public String getName() {
// return name;
// }
//
// public List<ParameterData> getParameterExprs() {
// return parameters;
// }
//
// public Expr getExpr() {
// return expr;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// builder.append(indent).append(isTail ? "└── " : "├── ")
// .append("func").append(name != null ? " " + name : "")
// .append('(')
// .append(getParameterExprs().stream().map(Object::toString)
// .collect(Collectors.joining(", ")))
// .append(')');
//
// builder.append('\n');
// expr.ast(builder, indent + (isTail ? " " : "│ "), true);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/invocation/Invocation.java
// public class Invocation extends Single {
// private final Single left;
// private final List<Single> arguments;
//
// public Invocation(Position position, Single left, List<Single> arguments) {
// super(position);
// this.left = left;
// this.arguments = arguments;
// }
//
// public Single getLeft() {
// return left;
// }
//
// public List<Single> getArguments() {
// return arguments;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// builder.append(indent).append(isTail ? "└── " : "├── ").append("invoke");
//
// builder.append('\n');
// left.ast("target", builder, indent + (isTail ? " " : "│ "), false);
//
// builder.append('\n');
// if (arguments.isEmpty()) {
// builder.append(indent).append(isTail ? " " : "│ ").append("└── ").append("*");
// } else {
// for (int i = 0; i < arguments.size() - 1; i++) {
// arguments.get(i).ast(builder, indent + (isTail ? " " : "│ "), false);
// builder.append('\n');
// }
// if (arguments.size() > 0) {
// arguments.get(arguments.size() - 1).ast(builder, indent + (isTail ? " " : "│ "), true);
// }
// }
// }
// }
//
// Path: Kaiper-Bytecode/src/main/java/xyz/avarel/kaiper/bytecode/DataOutputConsumer.java
// @FunctionalInterface
// public interface DataOutputConsumer {
// void writeInto(DataOutput output) throws IOException;
//
// default DataOutputConsumer andThen(DataOutputConsumer after) {
// Objects.requireNonNull(after);
// return (DataOutput t) -> {
// writeInto(t);
// after.writeInto(t);
// };
// }
// }
// Path: Kaiper-Compiler/src/main/java/xyz/avarel/kaiper/compiler/ExprCompiler.java
import xyz.avarel.kaiper.ast.*;
import xyz.avarel.kaiper.ast.collections.*;
import xyz.avarel.kaiper.ast.flow.*;
import xyz.avarel.kaiper.ast.functions.FunctionNode;
import xyz.avarel.kaiper.ast.functions.ParameterData;
import xyz.avarel.kaiper.ast.invocation.Invocation;
import xyz.avarel.kaiper.ast.operations.BinaryOperation;
import xyz.avarel.kaiper.ast.operations.SliceOperation;
import xyz.avarel.kaiper.ast.operations.UnaryOperation;
import xyz.avarel.kaiper.ast.value.*;
import xyz.avarel.kaiper.ast.variables.AssignmentExpr;
import xyz.avarel.kaiper.ast.variables.DeclarationExpr;
import xyz.avarel.kaiper.ast.variables.Identifier;
import xyz.avarel.kaiper.bytecode.DataOutputConsumer;
import java.util.*;
import java.util.stream.Collectors;
import static xyz.avarel.kaiper.bytecode.Opcodes.*;
public DataOutputConsumer stringPool() {
ArrayList<String> strings = new ArrayList<>(stringPool);
return out -> {
out.writeShort(strings.size());
for (String s : strings) {
out.writeUTF(s);
}
};
}
@Override
public DataOutputConsumer visit(Statements expr, Void scope) {
Iterator<Expr> iterator = expr.getExprs().iterator();
if (!iterator.hasNext()) return NO_OP_CONSUMER;
DataOutputConsumer consumer = iterator.next().accept(this, null);
if (!iterator.hasNext()) return consumer;
consumer = consumer.andThen(POP);
while (iterator.hasNext()) {
consumer = consumer.andThen(iterator.next().accept(this, null));
if (iterator.hasNext()) consumer = consumer.andThen(POP);
}
return consumer;
}
@Override | public DataOutputConsumer visit(FunctionNode expr, Void scope) { |
Avarel/Kaiper | Kaiper-Compiler/src/main/java/xyz/avarel/kaiper/compiler/ExprCompiler.java | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/functions/FunctionNode.java
// public class FunctionNode extends Single {
// private final String name;
// private final List<ParameterData> parameters;
// private final Expr expr;
//
// public FunctionNode(Position position, List<ParameterData> parameters, Expr expr) {
// this(position, null, parameters, expr);
// }
//
// public FunctionNode(Position position, String name, List<ParameterData> parameters, Expr expr) {
// super(position);
// this.name = name;
// this.parameters = parameters;
// this.expr = expr;
// }
//
// public String getName() {
// return name;
// }
//
// public List<ParameterData> getParameterExprs() {
// return parameters;
// }
//
// public Expr getExpr() {
// return expr;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// builder.append(indent).append(isTail ? "└── " : "├── ")
// .append("func").append(name != null ? " " + name : "")
// .append('(')
// .append(getParameterExprs().stream().map(Object::toString)
// .collect(Collectors.joining(", ")))
// .append(')');
//
// builder.append('\n');
// expr.ast(builder, indent + (isTail ? " " : "│ "), true);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/invocation/Invocation.java
// public class Invocation extends Single {
// private final Single left;
// private final List<Single> arguments;
//
// public Invocation(Position position, Single left, List<Single> arguments) {
// super(position);
// this.left = left;
// this.arguments = arguments;
// }
//
// public Single getLeft() {
// return left;
// }
//
// public List<Single> getArguments() {
// return arguments;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// builder.append(indent).append(isTail ? "└── " : "├── ").append("invoke");
//
// builder.append('\n');
// left.ast("target", builder, indent + (isTail ? " " : "│ "), false);
//
// builder.append('\n');
// if (arguments.isEmpty()) {
// builder.append(indent).append(isTail ? " " : "│ ").append("└── ").append("*");
// } else {
// for (int i = 0; i < arguments.size() - 1; i++) {
// arguments.get(i).ast(builder, indent + (isTail ? " " : "│ "), false);
// builder.append('\n');
// }
// if (arguments.size() > 0) {
// arguments.get(arguments.size() - 1).ast(builder, indent + (isTail ? " " : "│ "), true);
// }
// }
// }
// }
//
// Path: Kaiper-Bytecode/src/main/java/xyz/avarel/kaiper/bytecode/DataOutputConsumer.java
// @FunctionalInterface
// public interface DataOutputConsumer {
// void writeInto(DataOutput output) throws IOException;
//
// default DataOutputConsumer andThen(DataOutputConsumer after) {
// Objects.requireNonNull(after);
// return (DataOutput t) -> {
// writeInto(t);
// after.writeInto(t);
// };
// }
// }
| import xyz.avarel.kaiper.ast.*;
import xyz.avarel.kaiper.ast.collections.*;
import xyz.avarel.kaiper.ast.flow.*;
import xyz.avarel.kaiper.ast.functions.FunctionNode;
import xyz.avarel.kaiper.ast.functions.ParameterData;
import xyz.avarel.kaiper.ast.invocation.Invocation;
import xyz.avarel.kaiper.ast.operations.BinaryOperation;
import xyz.avarel.kaiper.ast.operations.SliceOperation;
import xyz.avarel.kaiper.ast.operations.UnaryOperation;
import xyz.avarel.kaiper.ast.value.*;
import xyz.avarel.kaiper.ast.variables.AssignmentExpr;
import xyz.avarel.kaiper.ast.variables.DeclarationExpr;
import xyz.avarel.kaiper.ast.variables.Identifier;
import xyz.avarel.kaiper.bytecode.DataOutputConsumer;
import java.util.*;
import java.util.stream.Collectors;
import static xyz.avarel.kaiper.bytecode.Opcodes.*; | out.writeShort(id);
});
}
return consumer;
}
@Override
public DataOutputConsumer visit(Identifier expr, Void scope) {
int name = stringConst(expr.getName());
if (expr.getParent() == null) {
return out -> {
IDENTIFIER.writeInto(out);
out.writeBoolean(false);
out.writeShort(name);
};
}
DataOutputConsumer parent = expr.getParent().accept(this, null);
return out -> {
parent.writeInto(out);
IDENTIFIER.writeInto(out);
out.writeBoolean(true);
out.writeShort(name);
};
}
@Override | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/functions/FunctionNode.java
// public class FunctionNode extends Single {
// private final String name;
// private final List<ParameterData> parameters;
// private final Expr expr;
//
// public FunctionNode(Position position, List<ParameterData> parameters, Expr expr) {
// this(position, null, parameters, expr);
// }
//
// public FunctionNode(Position position, String name, List<ParameterData> parameters, Expr expr) {
// super(position);
// this.name = name;
// this.parameters = parameters;
// this.expr = expr;
// }
//
// public String getName() {
// return name;
// }
//
// public List<ParameterData> getParameterExprs() {
// return parameters;
// }
//
// public Expr getExpr() {
// return expr;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// builder.append(indent).append(isTail ? "└── " : "├── ")
// .append("func").append(name != null ? " " + name : "")
// .append('(')
// .append(getParameterExprs().stream().map(Object::toString)
// .collect(Collectors.joining(", ")))
// .append(')');
//
// builder.append('\n');
// expr.ast(builder, indent + (isTail ? " " : "│ "), true);
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/invocation/Invocation.java
// public class Invocation extends Single {
// private final Single left;
// private final List<Single> arguments;
//
// public Invocation(Position position, Single left, List<Single> arguments) {
// super(position);
// this.left = left;
// this.arguments = arguments;
// }
//
// public Single getLeft() {
// return left;
// }
//
// public List<Single> getArguments() {
// return arguments;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// builder.append(indent).append(isTail ? "└── " : "├── ").append("invoke");
//
// builder.append('\n');
// left.ast("target", builder, indent + (isTail ? " " : "│ "), false);
//
// builder.append('\n');
// if (arguments.isEmpty()) {
// builder.append(indent).append(isTail ? " " : "│ ").append("└── ").append("*");
// } else {
// for (int i = 0; i < arguments.size() - 1; i++) {
// arguments.get(i).ast(builder, indent + (isTail ? " " : "│ "), false);
// builder.append('\n');
// }
// if (arguments.size() > 0) {
// arguments.get(arguments.size() - 1).ast(builder, indent + (isTail ? " " : "│ "), true);
// }
// }
// }
// }
//
// Path: Kaiper-Bytecode/src/main/java/xyz/avarel/kaiper/bytecode/DataOutputConsumer.java
// @FunctionalInterface
// public interface DataOutputConsumer {
// void writeInto(DataOutput output) throws IOException;
//
// default DataOutputConsumer andThen(DataOutputConsumer after) {
// Objects.requireNonNull(after);
// return (DataOutput t) -> {
// writeInto(t);
// after.writeInto(t);
// };
// }
// }
// Path: Kaiper-Compiler/src/main/java/xyz/avarel/kaiper/compiler/ExprCompiler.java
import xyz.avarel.kaiper.ast.*;
import xyz.avarel.kaiper.ast.collections.*;
import xyz.avarel.kaiper.ast.flow.*;
import xyz.avarel.kaiper.ast.functions.FunctionNode;
import xyz.avarel.kaiper.ast.functions.ParameterData;
import xyz.avarel.kaiper.ast.invocation.Invocation;
import xyz.avarel.kaiper.ast.operations.BinaryOperation;
import xyz.avarel.kaiper.ast.operations.SliceOperation;
import xyz.avarel.kaiper.ast.operations.UnaryOperation;
import xyz.avarel.kaiper.ast.value.*;
import xyz.avarel.kaiper.ast.variables.AssignmentExpr;
import xyz.avarel.kaiper.ast.variables.DeclarationExpr;
import xyz.avarel.kaiper.ast.variables.Identifier;
import xyz.avarel.kaiper.bytecode.DataOutputConsumer;
import java.util.*;
import java.util.stream.Collectors;
import static xyz.avarel.kaiper.bytecode.Opcodes.*;
out.writeShort(id);
});
}
return consumer;
}
@Override
public DataOutputConsumer visit(Identifier expr, Void scope) {
int name = stringConst(expr.getName());
if (expr.getParent() == null) {
return out -> {
IDENTIFIER.writeInto(out);
out.writeBoolean(false);
out.writeShort(name);
};
}
DataOutputConsumer parent = expr.getParent().accept(this, null);
return out -> {
parent.writeInto(out);
IDENTIFIER.writeInto(out);
out.writeBoolean(true);
out.writeShort(name);
};
}
@Override | public DataOutputConsumer visit(Invocation expr, Void scope) { |
Avarel/Kaiper | Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/flow/ForEachExpr.java | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/ExprVisitor.java
// public interface ExprVisitor<R, C> {
// R visit(Statements expr, C scope);
//
// R visit(FunctionNode expr, C scope);
//
// R visit(Identifier expr, C scope);
//
// R visit(Invocation expr, C scope);
//
// R visit(BinaryOperation expr, C scope);
//
// R visit(UnaryOperation expr, C scope);
//
// R visit(RangeNode expr, C scope);
//
// R visit(ArrayNode expr, C scope);
//
// R visit(SliceOperation expr, C scope);
//
// R visit(AssignmentExpr expr, C scope);
//
// R visit(GetOperation expr, C scope);
//
// R visit(SetOperation expr, C scope);
//
// R visit(ReturnExpr expr, C scope);
//
// R visit(ConditionalExpr expr, C scope);
//
// R visit(ForEachExpr expr, C scope);
//
// R visit(DictionaryNode expr, C scope);
//
// R visit(NullNode expr, C scope);
//
// R visit(IntNode expr, C scope);
//
// R visit(DecimalNode expr, C scope);
//
// R visit(BooleanNode expr, C scope);
//
// R visit(StringNode expr, C scope);
//
// R visit(DeclarationExpr expr, C scope);
//
// R visit(ModuleNode expr, C scope);
//
// R visit(TypeNode expr, C scope);
//
// R visit(WhileExpr expr, C scope);
// }
| import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.ExprVisitor;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.lexer.Position; | /*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.ast.flow;
public class ForEachExpr extends Single {
private final String variant;
private final Single iterable;
private final Expr action;
public ForEachExpr(Position position, String variant, Single iterable, Expr action) {
super(position);
this.variant = variant;
this.iterable = iterable;
this.action = action;
}
public String getVariant() {
return variant;
}
public Single getIterable() {
return iterable;
}
public Expr getAction() {
return action;
}
@Override | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/ExprVisitor.java
// public interface ExprVisitor<R, C> {
// R visit(Statements expr, C scope);
//
// R visit(FunctionNode expr, C scope);
//
// R visit(Identifier expr, C scope);
//
// R visit(Invocation expr, C scope);
//
// R visit(BinaryOperation expr, C scope);
//
// R visit(UnaryOperation expr, C scope);
//
// R visit(RangeNode expr, C scope);
//
// R visit(ArrayNode expr, C scope);
//
// R visit(SliceOperation expr, C scope);
//
// R visit(AssignmentExpr expr, C scope);
//
// R visit(GetOperation expr, C scope);
//
// R visit(SetOperation expr, C scope);
//
// R visit(ReturnExpr expr, C scope);
//
// R visit(ConditionalExpr expr, C scope);
//
// R visit(ForEachExpr expr, C scope);
//
// R visit(DictionaryNode expr, C scope);
//
// R visit(NullNode expr, C scope);
//
// R visit(IntNode expr, C scope);
//
// R visit(DecimalNode expr, C scope);
//
// R visit(BooleanNode expr, C scope);
//
// R visit(StringNode expr, C scope);
//
// R visit(DeclarationExpr expr, C scope);
//
// R visit(ModuleNode expr, C scope);
//
// R visit(TypeNode expr, C scope);
//
// R visit(WhileExpr expr, C scope);
// }
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/flow/ForEachExpr.java
import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.ExprVisitor;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.lexer.Position;
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.ast.flow;
public class ForEachExpr extends Single {
private final String variant;
private final Single iterable;
private final Expr action;
public ForEachExpr(Position position, String variant, Single iterable, Expr action) {
super(position);
this.variant = variant;
this.iterable = iterable;
this.action = action;
}
public String getVariant() {
return variant;
}
public Single getIterable() {
return iterable;
}
public Expr getAction() {
return action;
}
@Override | public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) { |
Avarel/Kaiper | Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/value/StringNode.java | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/ExprVisitor.java
// public interface ExprVisitor<R, C> {
// R visit(Statements expr, C scope);
//
// R visit(FunctionNode expr, C scope);
//
// R visit(Identifier expr, C scope);
//
// R visit(Invocation expr, C scope);
//
// R visit(BinaryOperation expr, C scope);
//
// R visit(UnaryOperation expr, C scope);
//
// R visit(RangeNode expr, C scope);
//
// R visit(ArrayNode expr, C scope);
//
// R visit(SliceOperation expr, C scope);
//
// R visit(AssignmentExpr expr, C scope);
//
// R visit(GetOperation expr, C scope);
//
// R visit(SetOperation expr, C scope);
//
// R visit(ReturnExpr expr, C scope);
//
// R visit(ConditionalExpr expr, C scope);
//
// R visit(ForEachExpr expr, C scope);
//
// R visit(DictionaryNode expr, C scope);
//
// R visit(NullNode expr, C scope);
//
// R visit(IntNode expr, C scope);
//
// R visit(DecimalNode expr, C scope);
//
// R visit(BooleanNode expr, C scope);
//
// R visit(StringNode expr, C scope);
//
// R visit(DeclarationExpr expr, C scope);
//
// R visit(ModuleNode expr, C scope);
//
// R visit(TypeNode expr, C scope);
//
// R visit(WhileExpr expr, C scope);
// }
| import xyz.avarel.kaiper.ast.ExprVisitor;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.lexer.Position; | /*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.ast.value;
public class StringNode extends Single {
private final String value;
public StringNode(Position position, String value) {
super(position);
this.value = value;
}
public String getValue() {
return value;
}
@Override | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/ExprVisitor.java
// public interface ExprVisitor<R, C> {
// R visit(Statements expr, C scope);
//
// R visit(FunctionNode expr, C scope);
//
// R visit(Identifier expr, C scope);
//
// R visit(Invocation expr, C scope);
//
// R visit(BinaryOperation expr, C scope);
//
// R visit(UnaryOperation expr, C scope);
//
// R visit(RangeNode expr, C scope);
//
// R visit(ArrayNode expr, C scope);
//
// R visit(SliceOperation expr, C scope);
//
// R visit(AssignmentExpr expr, C scope);
//
// R visit(GetOperation expr, C scope);
//
// R visit(SetOperation expr, C scope);
//
// R visit(ReturnExpr expr, C scope);
//
// R visit(ConditionalExpr expr, C scope);
//
// R visit(ForEachExpr expr, C scope);
//
// R visit(DictionaryNode expr, C scope);
//
// R visit(NullNode expr, C scope);
//
// R visit(IntNode expr, C scope);
//
// R visit(DecimalNode expr, C scope);
//
// R visit(BooleanNode expr, C scope);
//
// R visit(StringNode expr, C scope);
//
// R visit(DeclarationExpr expr, C scope);
//
// R visit(ModuleNode expr, C scope);
//
// R visit(TypeNode expr, C scope);
//
// R visit(WhileExpr expr, C scope);
// }
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/value/StringNode.java
import xyz.avarel.kaiper.ast.ExprVisitor;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.lexer.Position;
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.ast.value;
public class StringNode extends Single {
private final String value;
public StringNode(Position position, String value) {
super(position);
this.value = value;
}
public String getValue() {
return value;
}
@Override | public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) { |
Avarel/Kaiper | Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/parslets/functions/InvocationParser.java | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/invocation/Invocation.java
// public class Invocation extends Single {
// private final Single left;
// private final List<Single> arguments;
//
// public Invocation(Position position, Single left, List<Single> arguments) {
// super(position);
// this.left = left;
// this.arguments = arguments;
// }
//
// public Single getLeft() {
// return left;
// }
//
// public List<Single> getArguments() {
// return arguments;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// builder.append(indent).append(isTail ? "└── " : "├── ").append("invoke");
//
// builder.append('\n');
// left.ast("target", builder, indent + (isTail ? " " : "│ "), false);
//
// builder.append('\n');
// if (arguments.isEmpty()) {
// builder.append(indent).append(isTail ? " " : "│ ").append("└── ").append("*");
// } else {
// for (int i = 0; i < arguments.size() - 1; i++) {
// arguments.get(i).ast(builder, indent + (isTail ? " " : "│ "), false);
// builder.append('\n');
// }
// if (arguments.size() > 0) {
// arguments.get(arguments.size() - 1).ast(builder, indent + (isTail ? " " : "│ "), true);
// }
// }
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/lexer/TokenType.java
// public enum TokenType {
// // PAIRS
// LEFT_PAREN,
// RIGHT_PAREN,
//
// LEFT_BRACKET,
// RIGHT_BRACKET,
//
// LEFT_BRACE,
// RIGHT_BRACE,
//
// OPTIONAL_ASSIGN,
// ELVIS,
//
// // ASSIGNMENT
// ASSIGN,
//
// // TYPES
// INT,
// NUMBER,
// BOOLEAN,
// FUNCTION,
// STRING,
// ATOM,
//
// // ARITHMETIC
// PLUS,
// MINUS,
// ASTERISK,
// SLASH,
// BACKSLASH,
// CARET,
// PERCENT,
//
// // RELATIONAL
// EQUALS,
// NOT_EQUAL,
// GT,
// GTE,
// LT,
// LTE,
// OR,
// AND,
//
// // BOOLEAN
// AMPERSAND,
// VERTICAL_BAR,
//
// // MISC
// REST,
// RANGE_TO,
// PIPE_FORWARD,
// PIPE_BACKWARD,
// SHIFT_RIGHT,
// SHIFT_LEFT,
// ARROW,
// TILDE,
// BANG,
// QUESTION,
// COLON,
// COMMA,
// DOT,
//
// UNDERSCORE,
//
// // SCRIPT
// MODULE,
// TYPE,
// IDENTIFIER,
// NULL,
// LET,
// RETURN,
// IF,
// ELSE,
// FOR,
//
// LINE,
// EOF,
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/BinaryParser.java
// public abstract class BinaryParser implements InfixParser {
// private final int precedence;
// private final boolean leftAssoc;
//
// public BinaryParser(int precedence) {
// this(precedence, true);
// }
//
// public BinaryParser(int precedence, boolean leftAssoc) {
// this.precedence = precedence;
// this.leftAssoc = leftAssoc;
// }
//
// @Override
// public Expr parse(KaiperParser parser, Expr left, Token token) {
// if (!(left instanceof Single)) {
// throw new SyntaxException("Internal compiler error", token.getPosition());
// }
// return parse(parser, (Single) left, token);
// }
//
// public abstract Expr parse(KaiperParser parser, Single left, Token token);
//
// @Override
// public int getPrecedence() {
// return precedence;
// }
//
// public boolean isLeftAssoc() {
// return leftAssoc;
// }
// }
| import xyz.avarel.kaiper.Precedence;
import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.ast.invocation.Invocation;
import xyz.avarel.kaiper.exceptions.SyntaxException;
import xyz.avarel.kaiper.lexer.Token;
import xyz.avarel.kaiper.lexer.TokenType;
import xyz.avarel.kaiper.parser.BinaryParser;
import xyz.avarel.kaiper.parser.KaiperParser;
import java.util.ArrayList;
import java.util.List; | /*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.parser.parslets.functions;
public class InvocationParser extends BinaryParser {
public InvocationParser() {
super(Precedence.POSTFIX);
}
@Override
public Expr parse(KaiperParser parser, Single left, Token token) {
if (!parser.getParserFlags().allowInvocation()) {
throw new SyntaxException("Function creation are disabled");
}
List<Single> arguments = new ArrayList<>();
| // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/invocation/Invocation.java
// public class Invocation extends Single {
// private final Single left;
// private final List<Single> arguments;
//
// public Invocation(Position position, Single left, List<Single> arguments) {
// super(position);
// this.left = left;
// this.arguments = arguments;
// }
//
// public Single getLeft() {
// return left;
// }
//
// public List<Single> getArguments() {
// return arguments;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// builder.append(indent).append(isTail ? "└── " : "├── ").append("invoke");
//
// builder.append('\n');
// left.ast("target", builder, indent + (isTail ? " " : "│ "), false);
//
// builder.append('\n');
// if (arguments.isEmpty()) {
// builder.append(indent).append(isTail ? " " : "│ ").append("└── ").append("*");
// } else {
// for (int i = 0; i < arguments.size() - 1; i++) {
// arguments.get(i).ast(builder, indent + (isTail ? " " : "│ "), false);
// builder.append('\n');
// }
// if (arguments.size() > 0) {
// arguments.get(arguments.size() - 1).ast(builder, indent + (isTail ? " " : "│ "), true);
// }
// }
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/lexer/TokenType.java
// public enum TokenType {
// // PAIRS
// LEFT_PAREN,
// RIGHT_PAREN,
//
// LEFT_BRACKET,
// RIGHT_BRACKET,
//
// LEFT_BRACE,
// RIGHT_BRACE,
//
// OPTIONAL_ASSIGN,
// ELVIS,
//
// // ASSIGNMENT
// ASSIGN,
//
// // TYPES
// INT,
// NUMBER,
// BOOLEAN,
// FUNCTION,
// STRING,
// ATOM,
//
// // ARITHMETIC
// PLUS,
// MINUS,
// ASTERISK,
// SLASH,
// BACKSLASH,
// CARET,
// PERCENT,
//
// // RELATIONAL
// EQUALS,
// NOT_EQUAL,
// GT,
// GTE,
// LT,
// LTE,
// OR,
// AND,
//
// // BOOLEAN
// AMPERSAND,
// VERTICAL_BAR,
//
// // MISC
// REST,
// RANGE_TO,
// PIPE_FORWARD,
// PIPE_BACKWARD,
// SHIFT_RIGHT,
// SHIFT_LEFT,
// ARROW,
// TILDE,
// BANG,
// QUESTION,
// COLON,
// COMMA,
// DOT,
//
// UNDERSCORE,
//
// // SCRIPT
// MODULE,
// TYPE,
// IDENTIFIER,
// NULL,
// LET,
// RETURN,
// IF,
// ELSE,
// FOR,
//
// LINE,
// EOF,
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/BinaryParser.java
// public abstract class BinaryParser implements InfixParser {
// private final int precedence;
// private final boolean leftAssoc;
//
// public BinaryParser(int precedence) {
// this(precedence, true);
// }
//
// public BinaryParser(int precedence, boolean leftAssoc) {
// this.precedence = precedence;
// this.leftAssoc = leftAssoc;
// }
//
// @Override
// public Expr parse(KaiperParser parser, Expr left, Token token) {
// if (!(left instanceof Single)) {
// throw new SyntaxException("Internal compiler error", token.getPosition());
// }
// return parse(parser, (Single) left, token);
// }
//
// public abstract Expr parse(KaiperParser parser, Single left, Token token);
//
// @Override
// public int getPrecedence() {
// return precedence;
// }
//
// public boolean isLeftAssoc() {
// return leftAssoc;
// }
// }
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/parslets/functions/InvocationParser.java
import xyz.avarel.kaiper.Precedence;
import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.ast.invocation.Invocation;
import xyz.avarel.kaiper.exceptions.SyntaxException;
import xyz.avarel.kaiper.lexer.Token;
import xyz.avarel.kaiper.lexer.TokenType;
import xyz.avarel.kaiper.parser.BinaryParser;
import xyz.avarel.kaiper.parser.KaiperParser;
import java.util.ArrayList;
import java.util.List;
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.parser.parslets.functions;
public class InvocationParser extends BinaryParser {
public InvocationParser() {
super(Precedence.POSTFIX);
}
@Override
public Expr parse(KaiperParser parser, Single left, Token token) {
if (!parser.getParserFlags().allowInvocation()) {
throw new SyntaxException("Function creation are disabled");
}
List<Single> arguments = new ArrayList<>();
| if (!parser.match(TokenType.RIGHT_PAREN)) { |
Avarel/Kaiper | Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/parslets/functions/InvocationParser.java | // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/invocation/Invocation.java
// public class Invocation extends Single {
// private final Single left;
// private final List<Single> arguments;
//
// public Invocation(Position position, Single left, List<Single> arguments) {
// super(position);
// this.left = left;
// this.arguments = arguments;
// }
//
// public Single getLeft() {
// return left;
// }
//
// public List<Single> getArguments() {
// return arguments;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// builder.append(indent).append(isTail ? "└── " : "├── ").append("invoke");
//
// builder.append('\n');
// left.ast("target", builder, indent + (isTail ? " " : "│ "), false);
//
// builder.append('\n');
// if (arguments.isEmpty()) {
// builder.append(indent).append(isTail ? " " : "│ ").append("└── ").append("*");
// } else {
// for (int i = 0; i < arguments.size() - 1; i++) {
// arguments.get(i).ast(builder, indent + (isTail ? " " : "│ "), false);
// builder.append('\n');
// }
// if (arguments.size() > 0) {
// arguments.get(arguments.size() - 1).ast(builder, indent + (isTail ? " " : "│ "), true);
// }
// }
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/lexer/TokenType.java
// public enum TokenType {
// // PAIRS
// LEFT_PAREN,
// RIGHT_PAREN,
//
// LEFT_BRACKET,
// RIGHT_BRACKET,
//
// LEFT_BRACE,
// RIGHT_BRACE,
//
// OPTIONAL_ASSIGN,
// ELVIS,
//
// // ASSIGNMENT
// ASSIGN,
//
// // TYPES
// INT,
// NUMBER,
// BOOLEAN,
// FUNCTION,
// STRING,
// ATOM,
//
// // ARITHMETIC
// PLUS,
// MINUS,
// ASTERISK,
// SLASH,
// BACKSLASH,
// CARET,
// PERCENT,
//
// // RELATIONAL
// EQUALS,
// NOT_EQUAL,
// GT,
// GTE,
// LT,
// LTE,
// OR,
// AND,
//
// // BOOLEAN
// AMPERSAND,
// VERTICAL_BAR,
//
// // MISC
// REST,
// RANGE_TO,
// PIPE_FORWARD,
// PIPE_BACKWARD,
// SHIFT_RIGHT,
// SHIFT_LEFT,
// ARROW,
// TILDE,
// BANG,
// QUESTION,
// COLON,
// COMMA,
// DOT,
//
// UNDERSCORE,
//
// // SCRIPT
// MODULE,
// TYPE,
// IDENTIFIER,
// NULL,
// LET,
// RETURN,
// IF,
// ELSE,
// FOR,
//
// LINE,
// EOF,
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/BinaryParser.java
// public abstract class BinaryParser implements InfixParser {
// private final int precedence;
// private final boolean leftAssoc;
//
// public BinaryParser(int precedence) {
// this(precedence, true);
// }
//
// public BinaryParser(int precedence, boolean leftAssoc) {
// this.precedence = precedence;
// this.leftAssoc = leftAssoc;
// }
//
// @Override
// public Expr parse(KaiperParser parser, Expr left, Token token) {
// if (!(left instanceof Single)) {
// throw new SyntaxException("Internal compiler error", token.getPosition());
// }
// return parse(parser, (Single) left, token);
// }
//
// public abstract Expr parse(KaiperParser parser, Single left, Token token);
//
// @Override
// public int getPrecedence() {
// return precedence;
// }
//
// public boolean isLeftAssoc() {
// return leftAssoc;
// }
// }
| import xyz.avarel.kaiper.Precedence;
import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.ast.invocation.Invocation;
import xyz.avarel.kaiper.exceptions.SyntaxException;
import xyz.avarel.kaiper.lexer.Token;
import xyz.avarel.kaiper.lexer.TokenType;
import xyz.avarel.kaiper.parser.BinaryParser;
import xyz.avarel.kaiper.parser.KaiperParser;
import java.util.ArrayList;
import java.util.List; | /*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.parser.parslets.functions;
public class InvocationParser extends BinaryParser {
public InvocationParser() {
super(Precedence.POSTFIX);
}
@Override
public Expr parse(KaiperParser parser, Single left, Token token) {
if (!parser.getParserFlags().allowInvocation()) {
throw new SyntaxException("Function creation are disabled");
}
List<Single> arguments = new ArrayList<>();
if (!parser.match(TokenType.RIGHT_PAREN)) {
do {
arguments.add(parser.parseSingle());
} while (parser.match(TokenType.COMMA));
parser.eat(TokenType.RIGHT_PAREN);
}
| // Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/ast/invocation/Invocation.java
// public class Invocation extends Single {
// private final Single left;
// private final List<Single> arguments;
//
// public Invocation(Position position, Single left, List<Single> arguments) {
// super(position);
// this.left = left;
// this.arguments = arguments;
// }
//
// public Single getLeft() {
// return left;
// }
//
// public List<Single> getArguments() {
// return arguments;
// }
//
// @Override
// public <R, C> R accept(ExprVisitor<R, C> visitor, C scope) {
// return visitor.visit(this, scope);
// }
//
// @Override
// public void ast(StringBuilder builder, String indent, boolean isTail) {
// builder.append(indent).append(isTail ? "└── " : "├── ").append("invoke");
//
// builder.append('\n');
// left.ast("target", builder, indent + (isTail ? " " : "│ "), false);
//
// builder.append('\n');
// if (arguments.isEmpty()) {
// builder.append(indent).append(isTail ? " " : "│ ").append("└── ").append("*");
// } else {
// for (int i = 0; i < arguments.size() - 1; i++) {
// arguments.get(i).ast(builder, indent + (isTail ? " " : "│ "), false);
// builder.append('\n');
// }
// if (arguments.size() > 0) {
// arguments.get(arguments.size() - 1).ast(builder, indent + (isTail ? " " : "│ "), true);
// }
// }
// }
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/lexer/TokenType.java
// public enum TokenType {
// // PAIRS
// LEFT_PAREN,
// RIGHT_PAREN,
//
// LEFT_BRACKET,
// RIGHT_BRACKET,
//
// LEFT_BRACE,
// RIGHT_BRACE,
//
// OPTIONAL_ASSIGN,
// ELVIS,
//
// // ASSIGNMENT
// ASSIGN,
//
// // TYPES
// INT,
// NUMBER,
// BOOLEAN,
// FUNCTION,
// STRING,
// ATOM,
//
// // ARITHMETIC
// PLUS,
// MINUS,
// ASTERISK,
// SLASH,
// BACKSLASH,
// CARET,
// PERCENT,
//
// // RELATIONAL
// EQUALS,
// NOT_EQUAL,
// GT,
// GTE,
// LT,
// LTE,
// OR,
// AND,
//
// // BOOLEAN
// AMPERSAND,
// VERTICAL_BAR,
//
// // MISC
// REST,
// RANGE_TO,
// PIPE_FORWARD,
// PIPE_BACKWARD,
// SHIFT_RIGHT,
// SHIFT_LEFT,
// ARROW,
// TILDE,
// BANG,
// QUESTION,
// COLON,
// COMMA,
// DOT,
//
// UNDERSCORE,
//
// // SCRIPT
// MODULE,
// TYPE,
// IDENTIFIER,
// NULL,
// LET,
// RETURN,
// IF,
// ELSE,
// FOR,
//
// LINE,
// EOF,
// }
//
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/BinaryParser.java
// public abstract class BinaryParser implements InfixParser {
// private final int precedence;
// private final boolean leftAssoc;
//
// public BinaryParser(int precedence) {
// this(precedence, true);
// }
//
// public BinaryParser(int precedence, boolean leftAssoc) {
// this.precedence = precedence;
// this.leftAssoc = leftAssoc;
// }
//
// @Override
// public Expr parse(KaiperParser parser, Expr left, Token token) {
// if (!(left instanceof Single)) {
// throw new SyntaxException("Internal compiler error", token.getPosition());
// }
// return parse(parser, (Single) left, token);
// }
//
// public abstract Expr parse(KaiperParser parser, Single left, Token token);
//
// @Override
// public int getPrecedence() {
// return precedence;
// }
//
// public boolean isLeftAssoc() {
// return leftAssoc;
// }
// }
// Path: Kaiper-AST/src/main/java/xyz/avarel/kaiper/parser/parslets/functions/InvocationParser.java
import xyz.avarel.kaiper.Precedence;
import xyz.avarel.kaiper.ast.Expr;
import xyz.avarel.kaiper.ast.Single;
import xyz.avarel.kaiper.ast.invocation.Invocation;
import xyz.avarel.kaiper.exceptions.SyntaxException;
import xyz.avarel.kaiper.lexer.Token;
import xyz.avarel.kaiper.lexer.TokenType;
import xyz.avarel.kaiper.parser.BinaryParser;
import xyz.avarel.kaiper.parser.KaiperParser;
import java.util.ArrayList;
import java.util.List;
/*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package xyz.avarel.kaiper.parser.parslets.functions;
public class InvocationParser extends BinaryParser {
public InvocationParser() {
super(Precedence.POSTFIX);
}
@Override
public Expr parse(KaiperParser parser, Single left, Token token) {
if (!parser.getParserFlags().allowInvocation()) {
throw new SyntaxException("Function creation are disabled");
}
List<Single> arguments = new ArrayList<>();
if (!parser.match(TokenType.RIGHT_PAREN)) {
do {
arguments.add(parser.parseSingle());
} while (parser.match(TokenType.COMMA));
parser.eat(TokenType.RIGHT_PAREN);
}
| return new Invocation(token.getPosition(), left, arguments); |
olabini/yecht | ext/ruby/src/java/org/yecht/ruby/Seq.java | // Path: src/main/org/yecht/Data.java
// public abstract class Data {
// public abstract Data copy();
//
// public static class Map extends Data {
// public MapStyle style;
// public Object[] keys;
// public Object[] values;
// public int capa;
// public int idx;
//
// public String toString() {
// return "{idx=" + idx + ", capa=" + capa + ", keys=" + java.util.Arrays.asList(keys) + ", values=" + java.util.Arrays.asList(values) + "}";
// }
//
// public Map copy() {
// Map m = new Map();
// m.style = this.style;
// m.keys = new Object[this.keys.length];
// System.arraycopy(this.keys, 0, m.keys, 0, this.keys.length);
// m.values = new Object[this.values.length];
// System.arraycopy(this.values, 0, m.values, 0, this.values.length);
// m.capa = this.capa;
// m.idx = this.idx;
// return m;
// }
// }
//
// public static class Seq extends Data {
// public SeqStyle style;
// public Object[] items;
// public int capa;
// public int idx;
//
// public String toString() {
// return "[idx=" + idx + ", capa=" + capa + ", items=" + java.util.Arrays.asList(items) + "]";
// }
//
// public Seq copy() {
// Seq m = new Seq();
// m.style = this.style;
// m.items = new Object[this.items.length];
// System.arraycopy(this.items, 0, m.items, 0, this.items.length);
// m.capa = this.capa;
// m.idx = this.idx;
// return m;
// }
// }
//
// public static class Str extends Data {
// public ScalarStyle style;
// public Pointer ptr;
// public int len;
//
// public String toString() {
// return "\"" + new String(ptr.buffer, ptr.start, len) + "\"";
// }
//
// public Str copy() {
// Str m = new Str();
// m.ptr = Pointer.create(this.ptr.buffer, this.ptr.start);
// m.len = this.len;
// return m;
// }
// }
// }// Data
//
// Path: src/main/org/yecht/SeqStyle.java
// public enum SeqStyle {
// None, Inline
// }// SeqStyle
| import org.yecht.Data;
import org.yecht.SeqStyle;
import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.RubyClass;
import org.jruby.RubyHash;
import org.jruby.RubyObject;
import org.jruby.anno.JRubyMethod;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject; | package org.yecht.ruby;
public class Seq {
public static final ObjectAllocator Allocator = new ObjectAllocator() {
// syck_seq_alloc
public IRubyObject allocate(Ruby runtime, RubyClass klass) {
// System.err.println("ALLOCATING SEQ");
org.yecht.Node node = org.yecht.Node.allocSeq();
IRubyObject obj = new Node(runtime, klass, node, (YAMLExtra)runtime.getModule("YAML").dataGetStruct());
node.id = obj;
// System.err.println("syck_seq_alloc() -> setting id");
return obj;
}
};
// syck_seq_initialize
@JRubyMethod
public static IRubyObject initialize(IRubyObject self, IRubyObject type_id, IRubyObject val, IRubyObject style) {
Ruby runtime = self.getRuntime();
ThreadContext ctx = runtime.getCurrentContext();
((RubyObject)self).fastSetInstanceVariable("@kind", ((Node)self).x.seq);
self.callMethod(ctx, "type_id=", type_id);
self.callMethod(ctx, "value=", val);
self.callMethod(ctx, "style=", style);
return self;
}
// syck_seq_value_set
@JRubyMethod(name = "value=")
public static IRubyObject value_set(IRubyObject self, IRubyObject val) {
org.yecht.Node node = (org.yecht.Node)self.dataGetStructChecked();
Ruby runtime = self.getRuntime();
val = val.checkArrayType();
if(!val.isNil()) {
node.seqEmpty(); | // Path: src/main/org/yecht/Data.java
// public abstract class Data {
// public abstract Data copy();
//
// public static class Map extends Data {
// public MapStyle style;
// public Object[] keys;
// public Object[] values;
// public int capa;
// public int idx;
//
// public String toString() {
// return "{idx=" + idx + ", capa=" + capa + ", keys=" + java.util.Arrays.asList(keys) + ", values=" + java.util.Arrays.asList(values) + "}";
// }
//
// public Map copy() {
// Map m = new Map();
// m.style = this.style;
// m.keys = new Object[this.keys.length];
// System.arraycopy(this.keys, 0, m.keys, 0, this.keys.length);
// m.values = new Object[this.values.length];
// System.arraycopy(this.values, 0, m.values, 0, this.values.length);
// m.capa = this.capa;
// m.idx = this.idx;
// return m;
// }
// }
//
// public static class Seq extends Data {
// public SeqStyle style;
// public Object[] items;
// public int capa;
// public int idx;
//
// public String toString() {
// return "[idx=" + idx + ", capa=" + capa + ", items=" + java.util.Arrays.asList(items) + "]";
// }
//
// public Seq copy() {
// Seq m = new Seq();
// m.style = this.style;
// m.items = new Object[this.items.length];
// System.arraycopy(this.items, 0, m.items, 0, this.items.length);
// m.capa = this.capa;
// m.idx = this.idx;
// return m;
// }
// }
//
// public static class Str extends Data {
// public ScalarStyle style;
// public Pointer ptr;
// public int len;
//
// public String toString() {
// return "\"" + new String(ptr.buffer, ptr.start, len) + "\"";
// }
//
// public Str copy() {
// Str m = new Str();
// m.ptr = Pointer.create(this.ptr.buffer, this.ptr.start);
// m.len = this.len;
// return m;
// }
// }
// }// Data
//
// Path: src/main/org/yecht/SeqStyle.java
// public enum SeqStyle {
// None, Inline
// }// SeqStyle
// Path: ext/ruby/src/java/org/yecht/ruby/Seq.java
import org.yecht.Data;
import org.yecht.SeqStyle;
import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.RubyClass;
import org.jruby.RubyHash;
import org.jruby.RubyObject;
import org.jruby.anno.JRubyMethod;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
package org.yecht.ruby;
public class Seq {
public static final ObjectAllocator Allocator = new ObjectAllocator() {
// syck_seq_alloc
public IRubyObject allocate(Ruby runtime, RubyClass klass) {
// System.err.println("ALLOCATING SEQ");
org.yecht.Node node = org.yecht.Node.allocSeq();
IRubyObject obj = new Node(runtime, klass, node, (YAMLExtra)runtime.getModule("YAML").dataGetStruct());
node.id = obj;
// System.err.println("syck_seq_alloc() -> setting id");
return obj;
}
};
// syck_seq_initialize
@JRubyMethod
public static IRubyObject initialize(IRubyObject self, IRubyObject type_id, IRubyObject val, IRubyObject style) {
Ruby runtime = self.getRuntime();
ThreadContext ctx = runtime.getCurrentContext();
((RubyObject)self).fastSetInstanceVariable("@kind", ((Node)self).x.seq);
self.callMethod(ctx, "type_id=", type_id);
self.callMethod(ctx, "value=", val);
self.callMethod(ctx, "style=", style);
return self;
}
// syck_seq_value_set
@JRubyMethod(name = "value=")
public static IRubyObject value_set(IRubyObject self, IRubyObject val) {
org.yecht.Node node = (org.yecht.Node)self.dataGetStructChecked();
Ruby runtime = self.getRuntime();
val = val.checkArrayType();
if(!val.isNil()) {
node.seqEmpty(); | Data.Seq ds = (Data.Seq)node.data; |
olabini/yecht | ext/ruby/src/java/org/yecht/ruby/Seq.java | // Path: src/main/org/yecht/Data.java
// public abstract class Data {
// public abstract Data copy();
//
// public static class Map extends Data {
// public MapStyle style;
// public Object[] keys;
// public Object[] values;
// public int capa;
// public int idx;
//
// public String toString() {
// return "{idx=" + idx + ", capa=" + capa + ", keys=" + java.util.Arrays.asList(keys) + ", values=" + java.util.Arrays.asList(values) + "}";
// }
//
// public Map copy() {
// Map m = new Map();
// m.style = this.style;
// m.keys = new Object[this.keys.length];
// System.arraycopy(this.keys, 0, m.keys, 0, this.keys.length);
// m.values = new Object[this.values.length];
// System.arraycopy(this.values, 0, m.values, 0, this.values.length);
// m.capa = this.capa;
// m.idx = this.idx;
// return m;
// }
// }
//
// public static class Seq extends Data {
// public SeqStyle style;
// public Object[] items;
// public int capa;
// public int idx;
//
// public String toString() {
// return "[idx=" + idx + ", capa=" + capa + ", items=" + java.util.Arrays.asList(items) + "]";
// }
//
// public Seq copy() {
// Seq m = new Seq();
// m.style = this.style;
// m.items = new Object[this.items.length];
// System.arraycopy(this.items, 0, m.items, 0, this.items.length);
// m.capa = this.capa;
// m.idx = this.idx;
// return m;
// }
// }
//
// public static class Str extends Data {
// public ScalarStyle style;
// public Pointer ptr;
// public int len;
//
// public String toString() {
// return "\"" + new String(ptr.buffer, ptr.start, len) + "\"";
// }
//
// public Str copy() {
// Str m = new Str();
// m.ptr = Pointer.create(this.ptr.buffer, this.ptr.start);
// m.len = this.len;
// return m;
// }
// }
// }// Data
//
// Path: src/main/org/yecht/SeqStyle.java
// public enum SeqStyle {
// None, Inline
// }// SeqStyle
| import org.yecht.Data;
import org.yecht.SeqStyle;
import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.RubyClass;
import org.jruby.RubyHash;
import org.jruby.RubyObject;
import org.jruby.anno.JRubyMethod;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject; | self.callMethod(ctx, "style=", style);
return self;
}
// syck_seq_value_set
@JRubyMethod(name = "value=")
public static IRubyObject value_set(IRubyObject self, IRubyObject val) {
org.yecht.Node node = (org.yecht.Node)self.dataGetStructChecked();
Ruby runtime = self.getRuntime();
val = val.checkArrayType();
if(!val.isNil()) {
node.seqEmpty();
Data.Seq ds = (Data.Seq)node.data;
for(int i=0; i<((RubyArray)val).getLength(); i++) {
node.seqAdd(((RubyArray)val).entry(i));
}
}
((RubyObject)self).fastSetInstanceVariable("@value", val);
return val;
}
// syck_seq_style_set
@JRubyMethod(name = "style=")
public static IRubyObject style_set(IRubyObject self, IRubyObject style) {
org.yecht.Node node = (org.yecht.Node)self.dataGetStructChecked();
Ruby runtime = self.getRuntime();
Data.Seq ds = (Data.Seq)node.data;
if(style == runtime.newSymbol("inline")) { | // Path: src/main/org/yecht/Data.java
// public abstract class Data {
// public abstract Data copy();
//
// public static class Map extends Data {
// public MapStyle style;
// public Object[] keys;
// public Object[] values;
// public int capa;
// public int idx;
//
// public String toString() {
// return "{idx=" + idx + ", capa=" + capa + ", keys=" + java.util.Arrays.asList(keys) + ", values=" + java.util.Arrays.asList(values) + "}";
// }
//
// public Map copy() {
// Map m = new Map();
// m.style = this.style;
// m.keys = new Object[this.keys.length];
// System.arraycopy(this.keys, 0, m.keys, 0, this.keys.length);
// m.values = new Object[this.values.length];
// System.arraycopy(this.values, 0, m.values, 0, this.values.length);
// m.capa = this.capa;
// m.idx = this.idx;
// return m;
// }
// }
//
// public static class Seq extends Data {
// public SeqStyle style;
// public Object[] items;
// public int capa;
// public int idx;
//
// public String toString() {
// return "[idx=" + idx + ", capa=" + capa + ", items=" + java.util.Arrays.asList(items) + "]";
// }
//
// public Seq copy() {
// Seq m = new Seq();
// m.style = this.style;
// m.items = new Object[this.items.length];
// System.arraycopy(this.items, 0, m.items, 0, this.items.length);
// m.capa = this.capa;
// m.idx = this.idx;
// return m;
// }
// }
//
// public static class Str extends Data {
// public ScalarStyle style;
// public Pointer ptr;
// public int len;
//
// public String toString() {
// return "\"" + new String(ptr.buffer, ptr.start, len) + "\"";
// }
//
// public Str copy() {
// Str m = new Str();
// m.ptr = Pointer.create(this.ptr.buffer, this.ptr.start);
// m.len = this.len;
// return m;
// }
// }
// }// Data
//
// Path: src/main/org/yecht/SeqStyle.java
// public enum SeqStyle {
// None, Inline
// }// SeqStyle
// Path: ext/ruby/src/java/org/yecht/ruby/Seq.java
import org.yecht.Data;
import org.yecht.SeqStyle;
import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.RubyClass;
import org.jruby.RubyHash;
import org.jruby.RubyObject;
import org.jruby.anno.JRubyMethod;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
self.callMethod(ctx, "style=", style);
return self;
}
// syck_seq_value_set
@JRubyMethod(name = "value=")
public static IRubyObject value_set(IRubyObject self, IRubyObject val) {
org.yecht.Node node = (org.yecht.Node)self.dataGetStructChecked();
Ruby runtime = self.getRuntime();
val = val.checkArrayType();
if(!val.isNil()) {
node.seqEmpty();
Data.Seq ds = (Data.Seq)node.data;
for(int i=0; i<((RubyArray)val).getLength(); i++) {
node.seqAdd(((RubyArray)val).entry(i));
}
}
((RubyObject)self).fastSetInstanceVariable("@value", val);
return val;
}
// syck_seq_style_set
@JRubyMethod(name = "style=")
public static IRubyObject style_set(IRubyObject self, IRubyObject style) {
org.yecht.Node node = (org.yecht.Node)self.dataGetStructChecked();
Ruby runtime = self.getRuntime();
Data.Seq ds = (Data.Seq)node.data;
if(style == runtime.newSymbol("inline")) { | ds.style = SeqStyle.Inline; |
olabini/yecht | ext/ruby/src/java/org/yecht/ruby/Scalar.java | // Path: src/main/org/yecht/Data.java
// public abstract class Data {
// public abstract Data copy();
//
// public static class Map extends Data {
// public MapStyle style;
// public Object[] keys;
// public Object[] values;
// public int capa;
// public int idx;
//
// public String toString() {
// return "{idx=" + idx + ", capa=" + capa + ", keys=" + java.util.Arrays.asList(keys) + ", values=" + java.util.Arrays.asList(values) + "}";
// }
//
// public Map copy() {
// Map m = new Map();
// m.style = this.style;
// m.keys = new Object[this.keys.length];
// System.arraycopy(this.keys, 0, m.keys, 0, this.keys.length);
// m.values = new Object[this.values.length];
// System.arraycopy(this.values, 0, m.values, 0, this.values.length);
// m.capa = this.capa;
// m.idx = this.idx;
// return m;
// }
// }
//
// public static class Seq extends Data {
// public SeqStyle style;
// public Object[] items;
// public int capa;
// public int idx;
//
// public String toString() {
// return "[idx=" + idx + ", capa=" + capa + ", items=" + java.util.Arrays.asList(items) + "]";
// }
//
// public Seq copy() {
// Seq m = new Seq();
// m.style = this.style;
// m.items = new Object[this.items.length];
// System.arraycopy(this.items, 0, m.items, 0, this.items.length);
// m.capa = this.capa;
// m.idx = this.idx;
// return m;
// }
// }
//
// public static class Str extends Data {
// public ScalarStyle style;
// public Pointer ptr;
// public int len;
//
// public String toString() {
// return "\"" + new String(ptr.buffer, ptr.start, len) + "\"";
// }
//
// public Str copy() {
// Str m = new Str();
// m.ptr = Pointer.create(this.ptr.buffer, this.ptr.start);
// m.len = this.len;
// return m;
// }
// }
// }// Data
| import org.yecht.Data;
import org.yecht.Pointer;
import org.yecht.ScalarStyle;
import org.jruby.Ruby;
import org.jruby.RubyClass;
import org.jruby.RubyObject;
import org.jruby.RubyString;
import org.jruby.anno.JRubyMethod;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.ByteList; | package org.yecht.ruby;
public class Scalar {
public static final ObjectAllocator Allocator = new ObjectAllocator() {
// syck_scalar_alloc
public IRubyObject allocate(Ruby runtime, RubyClass klass) {
// System.err.println("ALLOCATING SCALAR");
org.yecht.Node node = org.yecht.Node.allocStr();
IRubyObject obj = new Node(runtime, klass, node, (YAMLExtra)runtime.getModule("YAML").dataGetStruct());
node.id = obj;
// System.err.println("syck_scalar_alloc() -> setting id: " + node.id);
return obj;
}
};
// syck_scalar_initialize
@JRubyMethod
public static IRubyObject initialize(IRubyObject self, IRubyObject type_id, IRubyObject val, IRubyObject style) {
Ruby runtime = self.getRuntime();
ThreadContext ctx = runtime.getCurrentContext();
((RubyObject)self).fastSetInstanceVariable("@kind", ((Node)self).x.scalar);
self.callMethod(ctx, "type_id=", type_id);
self.callMethod(ctx, "value=", val);
self.callMethod(ctx, "style=", style);
return self;
}
// syck_scalar_style_set
@JRubyMethod(name = "style=")
public static IRubyObject style_set(IRubyObject self, IRubyObject style) {
YAMLExtra x = ((Node)self).x;
Ruby runtime = self.getRuntime(); | // Path: src/main/org/yecht/Data.java
// public abstract class Data {
// public abstract Data copy();
//
// public static class Map extends Data {
// public MapStyle style;
// public Object[] keys;
// public Object[] values;
// public int capa;
// public int idx;
//
// public String toString() {
// return "{idx=" + idx + ", capa=" + capa + ", keys=" + java.util.Arrays.asList(keys) + ", values=" + java.util.Arrays.asList(values) + "}";
// }
//
// public Map copy() {
// Map m = new Map();
// m.style = this.style;
// m.keys = new Object[this.keys.length];
// System.arraycopy(this.keys, 0, m.keys, 0, this.keys.length);
// m.values = new Object[this.values.length];
// System.arraycopy(this.values, 0, m.values, 0, this.values.length);
// m.capa = this.capa;
// m.idx = this.idx;
// return m;
// }
// }
//
// public static class Seq extends Data {
// public SeqStyle style;
// public Object[] items;
// public int capa;
// public int idx;
//
// public String toString() {
// return "[idx=" + idx + ", capa=" + capa + ", items=" + java.util.Arrays.asList(items) + "]";
// }
//
// public Seq copy() {
// Seq m = new Seq();
// m.style = this.style;
// m.items = new Object[this.items.length];
// System.arraycopy(this.items, 0, m.items, 0, this.items.length);
// m.capa = this.capa;
// m.idx = this.idx;
// return m;
// }
// }
//
// public static class Str extends Data {
// public ScalarStyle style;
// public Pointer ptr;
// public int len;
//
// public String toString() {
// return "\"" + new String(ptr.buffer, ptr.start, len) + "\"";
// }
//
// public Str copy() {
// Str m = new Str();
// m.ptr = Pointer.create(this.ptr.buffer, this.ptr.start);
// m.len = this.len;
// return m;
// }
// }
// }// Data
// Path: ext/ruby/src/java/org/yecht/ruby/Scalar.java
import org.yecht.Data;
import org.yecht.Pointer;
import org.yecht.ScalarStyle;
import org.jruby.Ruby;
import org.jruby.RubyClass;
import org.jruby.RubyObject;
import org.jruby.RubyString;
import org.jruby.anno.JRubyMethod;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.ByteList;
package org.yecht.ruby;
public class Scalar {
public static final ObjectAllocator Allocator = new ObjectAllocator() {
// syck_scalar_alloc
public IRubyObject allocate(Ruby runtime, RubyClass klass) {
// System.err.println("ALLOCATING SCALAR");
org.yecht.Node node = org.yecht.Node.allocStr();
IRubyObject obj = new Node(runtime, klass, node, (YAMLExtra)runtime.getModule("YAML").dataGetStruct());
node.id = obj;
// System.err.println("syck_scalar_alloc() -> setting id: " + node.id);
return obj;
}
};
// syck_scalar_initialize
@JRubyMethod
public static IRubyObject initialize(IRubyObject self, IRubyObject type_id, IRubyObject val, IRubyObject style) {
Ruby runtime = self.getRuntime();
ThreadContext ctx = runtime.getCurrentContext();
((RubyObject)self).fastSetInstanceVariable("@kind", ((Node)self).x.scalar);
self.callMethod(ctx, "type_id=", type_id);
self.callMethod(ctx, "value=", val);
self.callMethod(ctx, "style=", style);
return self;
}
// syck_scalar_style_set
@JRubyMethod(name = "style=")
public static IRubyObject style_set(IRubyObject self, IRubyObject style) {
YAMLExtra x = ((Node)self).x;
Ruby runtime = self.getRuntime(); | Data.Str ds = (Data.Str)((org.yecht.Node)self.dataGetStructChecked()).data; |
olabini/yecht | ext/ruby/src/java/org/yecht/ruby/GenericResolver.java | // Path: src/main/org/yecht/Data.java
// public abstract class Data {
// public abstract Data copy();
//
// public static class Map extends Data {
// public MapStyle style;
// public Object[] keys;
// public Object[] values;
// public int capa;
// public int idx;
//
// public String toString() {
// return "{idx=" + idx + ", capa=" + capa + ", keys=" + java.util.Arrays.asList(keys) + ", values=" + java.util.Arrays.asList(values) + "}";
// }
//
// public Map copy() {
// Map m = new Map();
// m.style = this.style;
// m.keys = new Object[this.keys.length];
// System.arraycopy(this.keys, 0, m.keys, 0, this.keys.length);
// m.values = new Object[this.values.length];
// System.arraycopy(this.values, 0, m.values, 0, this.values.length);
// m.capa = this.capa;
// m.idx = this.idx;
// return m;
// }
// }
//
// public static class Seq extends Data {
// public SeqStyle style;
// public Object[] items;
// public int capa;
// public int idx;
//
// public String toString() {
// return "[idx=" + idx + ", capa=" + capa + ", items=" + java.util.Arrays.asList(items) + "]";
// }
//
// public Seq copy() {
// Seq m = new Seq();
// m.style = this.style;
// m.items = new Object[this.items.length];
// System.arraycopy(this.items, 0, m.items, 0, this.items.length);
// m.capa = this.capa;
// m.idx = this.idx;
// return m;
// }
// }
//
// public static class Str extends Data {
// public ScalarStyle style;
// public Pointer ptr;
// public int len;
//
// public String toString() {
// return "\"" + new String(ptr.buffer, ptr.start, len) + "\"";
// }
//
// public Str copy() {
// Str m = new Str();
// m.ptr = Pointer.create(this.ptr.buffer, this.ptr.start);
// m.len = this.len;
// return m;
// }
// }
// }// Data
//
// Path: src/main/org/yecht/MapStyle.java
// public enum MapStyle {
// None, Inline
// }
//
// Path: src/main/org/yecht/MapPart.java
// public enum MapPart {
// Key, Value
// }// MapPart
//
// Path: src/main/org/yecht/SeqStyle.java
// public enum SeqStyle {
// None, Inline
// }// SeqStyle
| import org.yecht.Data;
import org.yecht.MapStyle;
import org.yecht.MapPart;
import org.yecht.SeqStyle;
import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.RubyHash;
import org.jruby.RubyModule;
import org.jruby.RubyObject;
import org.jruby.RubyString;
import org.jruby.anno.JRubyMethod;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.CallSite;
import org.jruby.runtime.MethodIndex; | public IRubyObject fold;
public IRubyObject literal;
public IRubyObject plain;
public IRubyObject map;
public IRubyObject seq;
public IRubyObject inline;
public IRubyObject Scalar;
public IRubyObject Seq;
public IRubyObject Map;
public Ruby runtime;
private final CallSite newScalarAdapter = MethodIndex.getFunctionalCallSite("new");
private final CallSite newSeqAdapter = MethodIndex.getFunctionalCallSite("new");
private final CallSite newMapAdapter = MethodIndex.getFunctionalCallSite("new");
public Extra(Ruby runtime) {
quote1 = runtime.newSymbol("quote1");
quote2 = runtime.newSymbol("quote2");
fold = runtime.newSymbol("fold");
literal = runtime.newSymbol("literal");
plain = runtime.newSymbol("plain");
map = runtime.newSymbol("map");
seq = runtime.newSymbol("seq");
inline = runtime.newSymbol("inline");
Scalar = ((RubyModule)((RubyModule)runtime.getModule("YAML")).getConstant("Yecht")).getConstant("Scalar");
Seq = ((RubyModule)((RubyModule)runtime.getModule("YAML")).getConstant("Yecht")).getConstant("Seq");
Map = ((RubyModule)((RubyModule)runtime.getModule("YAML")).getConstant("Yecht")).getConstant("Map");
this.runtime = runtime;
}
public IRubyObject scalar(IRubyObject t, org.yecht.Node n, ThreadContext ctx) { | // Path: src/main/org/yecht/Data.java
// public abstract class Data {
// public abstract Data copy();
//
// public static class Map extends Data {
// public MapStyle style;
// public Object[] keys;
// public Object[] values;
// public int capa;
// public int idx;
//
// public String toString() {
// return "{idx=" + idx + ", capa=" + capa + ", keys=" + java.util.Arrays.asList(keys) + ", values=" + java.util.Arrays.asList(values) + "}";
// }
//
// public Map copy() {
// Map m = new Map();
// m.style = this.style;
// m.keys = new Object[this.keys.length];
// System.arraycopy(this.keys, 0, m.keys, 0, this.keys.length);
// m.values = new Object[this.values.length];
// System.arraycopy(this.values, 0, m.values, 0, this.values.length);
// m.capa = this.capa;
// m.idx = this.idx;
// return m;
// }
// }
//
// public static class Seq extends Data {
// public SeqStyle style;
// public Object[] items;
// public int capa;
// public int idx;
//
// public String toString() {
// return "[idx=" + idx + ", capa=" + capa + ", items=" + java.util.Arrays.asList(items) + "]";
// }
//
// public Seq copy() {
// Seq m = new Seq();
// m.style = this.style;
// m.items = new Object[this.items.length];
// System.arraycopy(this.items, 0, m.items, 0, this.items.length);
// m.capa = this.capa;
// m.idx = this.idx;
// return m;
// }
// }
//
// public static class Str extends Data {
// public ScalarStyle style;
// public Pointer ptr;
// public int len;
//
// public String toString() {
// return "\"" + new String(ptr.buffer, ptr.start, len) + "\"";
// }
//
// public Str copy() {
// Str m = new Str();
// m.ptr = Pointer.create(this.ptr.buffer, this.ptr.start);
// m.len = this.len;
// return m;
// }
// }
// }// Data
//
// Path: src/main/org/yecht/MapStyle.java
// public enum MapStyle {
// None, Inline
// }
//
// Path: src/main/org/yecht/MapPart.java
// public enum MapPart {
// Key, Value
// }// MapPart
//
// Path: src/main/org/yecht/SeqStyle.java
// public enum SeqStyle {
// None, Inline
// }// SeqStyle
// Path: ext/ruby/src/java/org/yecht/ruby/GenericResolver.java
import org.yecht.Data;
import org.yecht.MapStyle;
import org.yecht.MapPart;
import org.yecht.SeqStyle;
import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.RubyHash;
import org.jruby.RubyModule;
import org.jruby.RubyObject;
import org.jruby.RubyString;
import org.jruby.anno.JRubyMethod;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.CallSite;
import org.jruby.runtime.MethodIndex;
public IRubyObject fold;
public IRubyObject literal;
public IRubyObject plain;
public IRubyObject map;
public IRubyObject seq;
public IRubyObject inline;
public IRubyObject Scalar;
public IRubyObject Seq;
public IRubyObject Map;
public Ruby runtime;
private final CallSite newScalarAdapter = MethodIndex.getFunctionalCallSite("new");
private final CallSite newSeqAdapter = MethodIndex.getFunctionalCallSite("new");
private final CallSite newMapAdapter = MethodIndex.getFunctionalCallSite("new");
public Extra(Ruby runtime) {
quote1 = runtime.newSymbol("quote1");
quote2 = runtime.newSymbol("quote2");
fold = runtime.newSymbol("fold");
literal = runtime.newSymbol("literal");
plain = runtime.newSymbol("plain");
map = runtime.newSymbol("map");
seq = runtime.newSymbol("seq");
inline = runtime.newSymbol("inline");
Scalar = ((RubyModule)((RubyModule)runtime.getModule("YAML")).getConstant("Yecht")).getConstant("Scalar");
Seq = ((RubyModule)((RubyModule)runtime.getModule("YAML")).getConstant("Yecht")).getConstant("Seq");
Map = ((RubyModule)((RubyModule)runtime.getModule("YAML")).getConstant("Yecht")).getConstant("Map");
this.runtime = runtime;
}
public IRubyObject scalar(IRubyObject t, org.yecht.Node n, ThreadContext ctx) { | Data.Str dd = (Data.Str)n.data; |
olabini/yecht | ext/ruby/src/java/org/yecht/ruby/GenericResolver.java | // Path: src/main/org/yecht/Data.java
// public abstract class Data {
// public abstract Data copy();
//
// public static class Map extends Data {
// public MapStyle style;
// public Object[] keys;
// public Object[] values;
// public int capa;
// public int idx;
//
// public String toString() {
// return "{idx=" + idx + ", capa=" + capa + ", keys=" + java.util.Arrays.asList(keys) + ", values=" + java.util.Arrays.asList(values) + "}";
// }
//
// public Map copy() {
// Map m = new Map();
// m.style = this.style;
// m.keys = new Object[this.keys.length];
// System.arraycopy(this.keys, 0, m.keys, 0, this.keys.length);
// m.values = new Object[this.values.length];
// System.arraycopy(this.values, 0, m.values, 0, this.values.length);
// m.capa = this.capa;
// m.idx = this.idx;
// return m;
// }
// }
//
// public static class Seq extends Data {
// public SeqStyle style;
// public Object[] items;
// public int capa;
// public int idx;
//
// public String toString() {
// return "[idx=" + idx + ", capa=" + capa + ", items=" + java.util.Arrays.asList(items) + "]";
// }
//
// public Seq copy() {
// Seq m = new Seq();
// m.style = this.style;
// m.items = new Object[this.items.length];
// System.arraycopy(this.items, 0, m.items, 0, this.items.length);
// m.capa = this.capa;
// m.idx = this.idx;
// return m;
// }
// }
//
// public static class Str extends Data {
// public ScalarStyle style;
// public Pointer ptr;
// public int len;
//
// public String toString() {
// return "\"" + new String(ptr.buffer, ptr.start, len) + "\"";
// }
//
// public Str copy() {
// Str m = new Str();
// m.ptr = Pointer.create(this.ptr.buffer, this.ptr.start);
// m.len = this.len;
// return m;
// }
// }
// }// Data
//
// Path: src/main/org/yecht/MapStyle.java
// public enum MapStyle {
// None, Inline
// }
//
// Path: src/main/org/yecht/MapPart.java
// public enum MapPart {
// Key, Value
// }// MapPart
//
// Path: src/main/org/yecht/SeqStyle.java
// public enum SeqStyle {
// None, Inline
// }// SeqStyle
| import org.yecht.Data;
import org.yecht.MapStyle;
import org.yecht.MapPart;
import org.yecht.SeqStyle;
import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.RubyHash;
import org.jruby.RubyModule;
import org.jruby.RubyObject;
import org.jruby.RubyString;
import org.jruby.anno.JRubyMethod;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.CallSite;
import org.jruby.runtime.MethodIndex; | IRubyObject v = RubyString.newStringShared(runtime, dd.ptr.buffer, dd.ptr.start, dd.len);
IRubyObject style = runtime.getNil();
switch(dd.style) {
case OneQuote:
style = quote1;
break;
case TwoQuote:
style = quote2;
break;
case Fold:
style = fold;
break;
case Literal:
style = literal;
break;
case Plain:
style = plain;
break;
}
return newScalarAdapter.call(ctx, Scalar, Scalar, t, v, style);
}
public IRubyObject sequence(IRubyObject t, org.yecht.Node n, ThreadContext ctx) {
Data.Seq ds = (Data.Seq)n.data;
Object[] items = ds.items;
IRubyObject v = RubyArray.newArray(runtime, ds.idx);
for(int i = 0; i < ds.idx; i++) {
((RubyArray)v).store(i, (IRubyObject)items[i]);
}
IRubyObject style = runtime.getNil(); | // Path: src/main/org/yecht/Data.java
// public abstract class Data {
// public abstract Data copy();
//
// public static class Map extends Data {
// public MapStyle style;
// public Object[] keys;
// public Object[] values;
// public int capa;
// public int idx;
//
// public String toString() {
// return "{idx=" + idx + ", capa=" + capa + ", keys=" + java.util.Arrays.asList(keys) + ", values=" + java.util.Arrays.asList(values) + "}";
// }
//
// public Map copy() {
// Map m = new Map();
// m.style = this.style;
// m.keys = new Object[this.keys.length];
// System.arraycopy(this.keys, 0, m.keys, 0, this.keys.length);
// m.values = new Object[this.values.length];
// System.arraycopy(this.values, 0, m.values, 0, this.values.length);
// m.capa = this.capa;
// m.idx = this.idx;
// return m;
// }
// }
//
// public static class Seq extends Data {
// public SeqStyle style;
// public Object[] items;
// public int capa;
// public int idx;
//
// public String toString() {
// return "[idx=" + idx + ", capa=" + capa + ", items=" + java.util.Arrays.asList(items) + "]";
// }
//
// public Seq copy() {
// Seq m = new Seq();
// m.style = this.style;
// m.items = new Object[this.items.length];
// System.arraycopy(this.items, 0, m.items, 0, this.items.length);
// m.capa = this.capa;
// m.idx = this.idx;
// return m;
// }
// }
//
// public static class Str extends Data {
// public ScalarStyle style;
// public Pointer ptr;
// public int len;
//
// public String toString() {
// return "\"" + new String(ptr.buffer, ptr.start, len) + "\"";
// }
//
// public Str copy() {
// Str m = new Str();
// m.ptr = Pointer.create(this.ptr.buffer, this.ptr.start);
// m.len = this.len;
// return m;
// }
// }
// }// Data
//
// Path: src/main/org/yecht/MapStyle.java
// public enum MapStyle {
// None, Inline
// }
//
// Path: src/main/org/yecht/MapPart.java
// public enum MapPart {
// Key, Value
// }// MapPart
//
// Path: src/main/org/yecht/SeqStyle.java
// public enum SeqStyle {
// None, Inline
// }// SeqStyle
// Path: ext/ruby/src/java/org/yecht/ruby/GenericResolver.java
import org.yecht.Data;
import org.yecht.MapStyle;
import org.yecht.MapPart;
import org.yecht.SeqStyle;
import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.RubyHash;
import org.jruby.RubyModule;
import org.jruby.RubyObject;
import org.jruby.RubyString;
import org.jruby.anno.JRubyMethod;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.CallSite;
import org.jruby.runtime.MethodIndex;
IRubyObject v = RubyString.newStringShared(runtime, dd.ptr.buffer, dd.ptr.start, dd.len);
IRubyObject style = runtime.getNil();
switch(dd.style) {
case OneQuote:
style = quote1;
break;
case TwoQuote:
style = quote2;
break;
case Fold:
style = fold;
break;
case Literal:
style = literal;
break;
case Plain:
style = plain;
break;
}
return newScalarAdapter.call(ctx, Scalar, Scalar, t, v, style);
}
public IRubyObject sequence(IRubyObject t, org.yecht.Node n, ThreadContext ctx) {
Data.Seq ds = (Data.Seq)n.data;
Object[] items = ds.items;
IRubyObject v = RubyArray.newArray(runtime, ds.idx);
for(int i = 0; i < ds.idx; i++) {
((RubyArray)v).store(i, (IRubyObject)items[i]);
}
IRubyObject style = runtime.getNil(); | if(((Data.Seq)n.data).style == SeqStyle.Inline) { |
olabini/yecht | ext/ruby/src/java/org/yecht/ruby/GenericResolver.java | // Path: src/main/org/yecht/Data.java
// public abstract class Data {
// public abstract Data copy();
//
// public static class Map extends Data {
// public MapStyle style;
// public Object[] keys;
// public Object[] values;
// public int capa;
// public int idx;
//
// public String toString() {
// return "{idx=" + idx + ", capa=" + capa + ", keys=" + java.util.Arrays.asList(keys) + ", values=" + java.util.Arrays.asList(values) + "}";
// }
//
// public Map copy() {
// Map m = new Map();
// m.style = this.style;
// m.keys = new Object[this.keys.length];
// System.arraycopy(this.keys, 0, m.keys, 0, this.keys.length);
// m.values = new Object[this.values.length];
// System.arraycopy(this.values, 0, m.values, 0, this.values.length);
// m.capa = this.capa;
// m.idx = this.idx;
// return m;
// }
// }
//
// public static class Seq extends Data {
// public SeqStyle style;
// public Object[] items;
// public int capa;
// public int idx;
//
// public String toString() {
// return "[idx=" + idx + ", capa=" + capa + ", items=" + java.util.Arrays.asList(items) + "]";
// }
//
// public Seq copy() {
// Seq m = new Seq();
// m.style = this.style;
// m.items = new Object[this.items.length];
// System.arraycopy(this.items, 0, m.items, 0, this.items.length);
// m.capa = this.capa;
// m.idx = this.idx;
// return m;
// }
// }
//
// public static class Str extends Data {
// public ScalarStyle style;
// public Pointer ptr;
// public int len;
//
// public String toString() {
// return "\"" + new String(ptr.buffer, ptr.start, len) + "\"";
// }
//
// public Str copy() {
// Str m = new Str();
// m.ptr = Pointer.create(this.ptr.buffer, this.ptr.start);
// m.len = this.len;
// return m;
// }
// }
// }// Data
//
// Path: src/main/org/yecht/MapStyle.java
// public enum MapStyle {
// None, Inline
// }
//
// Path: src/main/org/yecht/MapPart.java
// public enum MapPart {
// Key, Value
// }// MapPart
//
// Path: src/main/org/yecht/SeqStyle.java
// public enum SeqStyle {
// None, Inline
// }// SeqStyle
| import org.yecht.Data;
import org.yecht.MapStyle;
import org.yecht.MapPart;
import org.yecht.SeqStyle;
import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.RubyHash;
import org.jruby.RubyModule;
import org.jruby.RubyObject;
import org.jruby.RubyString;
import org.jruby.anno.JRubyMethod;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.CallSite;
import org.jruby.runtime.MethodIndex; | Data.Seq ds = (Data.Seq)n.data;
Object[] items = ds.items;
IRubyObject v = RubyArray.newArray(runtime, ds.idx);
for(int i = 0; i < ds.idx; i++) {
((RubyArray)v).store(i, (IRubyObject)items[i]);
}
IRubyObject style = runtime.getNil();
if(((Data.Seq)n.data).style == SeqStyle.Inline) {
style = inline;
}
IRubyObject obj = newSeqAdapter.call(ctx, Seq, Seq, t, v, style);
((RubyObject)obj).fastSetInstanceVariable("@kind", seq);
return obj;
}
public IRubyObject mapping(IRubyObject t, org.yecht.Node n, ThreadContext ctx) {
Data.Map dm = (Data.Map)n.data;
Object[] keys = dm.keys;
Object[] vals = dm.values;
IRubyObject v = RubyHash.newHash(runtime);
for(int i = 0; i < dm.idx; i++) {
IRubyObject k3 = (IRubyObject)keys[i];
IRubyObject v3 = (IRubyObject)vals[i];
if(null == v3) {
v3 = runtime.getNil();
}
((RubyHash)v).fastASet(k3, v3);
}
IRubyObject style = runtime.getNil(); | // Path: src/main/org/yecht/Data.java
// public abstract class Data {
// public abstract Data copy();
//
// public static class Map extends Data {
// public MapStyle style;
// public Object[] keys;
// public Object[] values;
// public int capa;
// public int idx;
//
// public String toString() {
// return "{idx=" + idx + ", capa=" + capa + ", keys=" + java.util.Arrays.asList(keys) + ", values=" + java.util.Arrays.asList(values) + "}";
// }
//
// public Map copy() {
// Map m = new Map();
// m.style = this.style;
// m.keys = new Object[this.keys.length];
// System.arraycopy(this.keys, 0, m.keys, 0, this.keys.length);
// m.values = new Object[this.values.length];
// System.arraycopy(this.values, 0, m.values, 0, this.values.length);
// m.capa = this.capa;
// m.idx = this.idx;
// return m;
// }
// }
//
// public static class Seq extends Data {
// public SeqStyle style;
// public Object[] items;
// public int capa;
// public int idx;
//
// public String toString() {
// return "[idx=" + idx + ", capa=" + capa + ", items=" + java.util.Arrays.asList(items) + "]";
// }
//
// public Seq copy() {
// Seq m = new Seq();
// m.style = this.style;
// m.items = new Object[this.items.length];
// System.arraycopy(this.items, 0, m.items, 0, this.items.length);
// m.capa = this.capa;
// m.idx = this.idx;
// return m;
// }
// }
//
// public static class Str extends Data {
// public ScalarStyle style;
// public Pointer ptr;
// public int len;
//
// public String toString() {
// return "\"" + new String(ptr.buffer, ptr.start, len) + "\"";
// }
//
// public Str copy() {
// Str m = new Str();
// m.ptr = Pointer.create(this.ptr.buffer, this.ptr.start);
// m.len = this.len;
// return m;
// }
// }
// }// Data
//
// Path: src/main/org/yecht/MapStyle.java
// public enum MapStyle {
// None, Inline
// }
//
// Path: src/main/org/yecht/MapPart.java
// public enum MapPart {
// Key, Value
// }// MapPart
//
// Path: src/main/org/yecht/SeqStyle.java
// public enum SeqStyle {
// None, Inline
// }// SeqStyle
// Path: ext/ruby/src/java/org/yecht/ruby/GenericResolver.java
import org.yecht.Data;
import org.yecht.MapStyle;
import org.yecht.MapPart;
import org.yecht.SeqStyle;
import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.RubyHash;
import org.jruby.RubyModule;
import org.jruby.RubyObject;
import org.jruby.RubyString;
import org.jruby.anno.JRubyMethod;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.CallSite;
import org.jruby.runtime.MethodIndex;
Data.Seq ds = (Data.Seq)n.data;
Object[] items = ds.items;
IRubyObject v = RubyArray.newArray(runtime, ds.idx);
for(int i = 0; i < ds.idx; i++) {
((RubyArray)v).store(i, (IRubyObject)items[i]);
}
IRubyObject style = runtime.getNil();
if(((Data.Seq)n.data).style == SeqStyle.Inline) {
style = inline;
}
IRubyObject obj = newSeqAdapter.call(ctx, Seq, Seq, t, v, style);
((RubyObject)obj).fastSetInstanceVariable("@kind", seq);
return obj;
}
public IRubyObject mapping(IRubyObject t, org.yecht.Node n, ThreadContext ctx) {
Data.Map dm = (Data.Map)n.data;
Object[] keys = dm.keys;
Object[] vals = dm.values;
IRubyObject v = RubyHash.newHash(runtime);
for(int i = 0; i < dm.idx; i++) {
IRubyObject k3 = (IRubyObject)keys[i];
IRubyObject v3 = (IRubyObject)vals[i];
if(null == v3) {
v3 = runtime.getNil();
}
((RubyHash)v).fastASet(k3, v3);
}
IRubyObject style = runtime.getNil(); | if(((Data.Map)n.data).style == MapStyle.Inline) { |
olabini/yecht | ext/ruby/src/java/org/yecht/ruby/RubyIoStrRead.java | // Path: src/main/org/yecht/IoStrRead.java
// public interface IoStrRead {
// public int read(Pointer buf, JechtIO.Str str, int max_size, int skip);
//
// public static class Default implements IoStrRead {
// // syck_io_str_read
// public int read(Pointer buf, JechtIO.Str str, int max_size, int skip) {
// int beg = str.ptr.start;
// if(max_size >= 0) {
// max_size -= skip;
// if(max_size <= 0) {
// max_size = 0;
// } else {
// str.ptr.start += max_size;
// }
//
// if(str.ptr.start > str.end) {
// str.ptr.start = str.end;
// }
// } else {
// while(str.ptr.start < str.end) {
// if(str.ptr.buffer[str.ptr.start++] == '\n') {
// break;
// }
// }
// }
// int len = 0;
// if(beg < str.ptr.start) {
// len = str.ptr.start - beg;
// System.arraycopy(str.ptr.buffer, beg, buf.buffer, buf.start + skip, len);
// }
// len += skip;
// buf.buffer[buf.start+len] = 0;
// return len;
// }
// }
// }// IoStrRead
//
// Path: src/main/org/yecht/JechtIO.java
// public abstract class JechtIO {
// public static class File extends JechtIO {
// public java.io.InputStream ptr;
// public IoFileRead read;
// public File(java.io.InputStream is, IoFileRead read) {
// this.ptr = is;
// this.read = read;
// }
// }
//
// public static class Str extends JechtIO {
// public Pointer ptr;
// public int beg;
// public int end;
// public IoStrRead read;
// }
// }// JechtIO
| import org.yecht.IoStrRead;
import org.yecht.JechtIO;
import org.yecht.Pointer;
import org.jruby.RubyNumeric;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.ByteList; | package org.yecht.ruby;
public class RubyIoStrRead implements IoStrRead {
private IRubyObject port;
public RubyIoStrRead(IRubyObject port) {
this.port = port;
}
// rb_syck_io_str_read | // Path: src/main/org/yecht/IoStrRead.java
// public interface IoStrRead {
// public int read(Pointer buf, JechtIO.Str str, int max_size, int skip);
//
// public static class Default implements IoStrRead {
// // syck_io_str_read
// public int read(Pointer buf, JechtIO.Str str, int max_size, int skip) {
// int beg = str.ptr.start;
// if(max_size >= 0) {
// max_size -= skip;
// if(max_size <= 0) {
// max_size = 0;
// } else {
// str.ptr.start += max_size;
// }
//
// if(str.ptr.start > str.end) {
// str.ptr.start = str.end;
// }
// } else {
// while(str.ptr.start < str.end) {
// if(str.ptr.buffer[str.ptr.start++] == '\n') {
// break;
// }
// }
// }
// int len = 0;
// if(beg < str.ptr.start) {
// len = str.ptr.start - beg;
// System.arraycopy(str.ptr.buffer, beg, buf.buffer, buf.start + skip, len);
// }
// len += skip;
// buf.buffer[buf.start+len] = 0;
// return len;
// }
// }
// }// IoStrRead
//
// Path: src/main/org/yecht/JechtIO.java
// public abstract class JechtIO {
// public static class File extends JechtIO {
// public java.io.InputStream ptr;
// public IoFileRead read;
// public File(java.io.InputStream is, IoFileRead read) {
// this.ptr = is;
// this.read = read;
// }
// }
//
// public static class Str extends JechtIO {
// public Pointer ptr;
// public int beg;
// public int end;
// public IoStrRead read;
// }
// }// JechtIO
// Path: ext/ruby/src/java/org/yecht/ruby/RubyIoStrRead.java
import org.yecht.IoStrRead;
import org.yecht.JechtIO;
import org.yecht.Pointer;
import org.jruby.RubyNumeric;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.ByteList;
package org.yecht.ruby;
public class RubyIoStrRead implements IoStrRead {
private IRubyObject port;
public RubyIoStrRead(IRubyObject port) {
this.port = port;
}
// rb_syck_io_str_read | public int read(Pointer buf, JechtIO.Str str, int max_size, int skip) { |
olabini/yecht | ext/ruby/src/java/org/yecht/ruby/Map.java | // Path: src/main/org/yecht/Data.java
// public abstract class Data {
// public abstract Data copy();
//
// public static class Map extends Data {
// public MapStyle style;
// public Object[] keys;
// public Object[] values;
// public int capa;
// public int idx;
//
// public String toString() {
// return "{idx=" + idx + ", capa=" + capa + ", keys=" + java.util.Arrays.asList(keys) + ", values=" + java.util.Arrays.asList(values) + "}";
// }
//
// public Map copy() {
// Map m = new Map();
// m.style = this.style;
// m.keys = new Object[this.keys.length];
// System.arraycopy(this.keys, 0, m.keys, 0, this.keys.length);
// m.values = new Object[this.values.length];
// System.arraycopy(this.values, 0, m.values, 0, this.values.length);
// m.capa = this.capa;
// m.idx = this.idx;
// return m;
// }
// }
//
// public static class Seq extends Data {
// public SeqStyle style;
// public Object[] items;
// public int capa;
// public int idx;
//
// public String toString() {
// return "[idx=" + idx + ", capa=" + capa + ", items=" + java.util.Arrays.asList(items) + "]";
// }
//
// public Seq copy() {
// Seq m = new Seq();
// m.style = this.style;
// m.items = new Object[this.items.length];
// System.arraycopy(this.items, 0, m.items, 0, this.items.length);
// m.capa = this.capa;
// m.idx = this.idx;
// return m;
// }
// }
//
// public static class Str extends Data {
// public ScalarStyle style;
// public Pointer ptr;
// public int len;
//
// public String toString() {
// return "\"" + new String(ptr.buffer, ptr.start, len) + "\"";
// }
//
// public Str copy() {
// Str m = new Str();
// m.ptr = Pointer.create(this.ptr.buffer, this.ptr.start);
// m.len = this.len;
// return m;
// }
// }
// }// Data
//
// Path: src/main/org/yecht/MapStyle.java
// public enum MapStyle {
// None, Inline
// }
| import org.yecht.Data;
import org.yecht.MapStyle;
import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.RubyClass;
import org.jruby.RubyHash;
import org.jruby.RubyObject;
import org.jruby.anno.JRubyMethod;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.TypeConverter; | package org.yecht.ruby;
public class Map {
public static final ObjectAllocator Allocator = new ObjectAllocator() {
// syck_map_alloc
public IRubyObject allocate(Ruby runtime, RubyClass klass) {
// System.err.println("ALLOCATING MAP");
org.yecht.Node node = org.yecht.Node.allocMap();
IRubyObject obj = new Node(runtime, klass, node, (YAMLExtra)runtime.getModule("YAML").dataGetStruct());
node.id = obj;
// System.err.println("syck_map_alloc() -> setting id");
return obj;
}
};
// syck_map_initialize
@JRubyMethod
public static IRubyObject initialize(IRubyObject self, IRubyObject type_id, IRubyObject val, IRubyObject style) {
org.yecht.Node node = (org.yecht.Node)self.dataGetStructChecked();
Ruby runtime = self.getRuntime();
ThreadContext ctx = runtime.getCurrentContext(); | // Path: src/main/org/yecht/Data.java
// public abstract class Data {
// public abstract Data copy();
//
// public static class Map extends Data {
// public MapStyle style;
// public Object[] keys;
// public Object[] values;
// public int capa;
// public int idx;
//
// public String toString() {
// return "{idx=" + idx + ", capa=" + capa + ", keys=" + java.util.Arrays.asList(keys) + ", values=" + java.util.Arrays.asList(values) + "}";
// }
//
// public Map copy() {
// Map m = new Map();
// m.style = this.style;
// m.keys = new Object[this.keys.length];
// System.arraycopy(this.keys, 0, m.keys, 0, this.keys.length);
// m.values = new Object[this.values.length];
// System.arraycopy(this.values, 0, m.values, 0, this.values.length);
// m.capa = this.capa;
// m.idx = this.idx;
// return m;
// }
// }
//
// public static class Seq extends Data {
// public SeqStyle style;
// public Object[] items;
// public int capa;
// public int idx;
//
// public String toString() {
// return "[idx=" + idx + ", capa=" + capa + ", items=" + java.util.Arrays.asList(items) + "]";
// }
//
// public Seq copy() {
// Seq m = new Seq();
// m.style = this.style;
// m.items = new Object[this.items.length];
// System.arraycopy(this.items, 0, m.items, 0, this.items.length);
// m.capa = this.capa;
// m.idx = this.idx;
// return m;
// }
// }
//
// public static class Str extends Data {
// public ScalarStyle style;
// public Pointer ptr;
// public int len;
//
// public String toString() {
// return "\"" + new String(ptr.buffer, ptr.start, len) + "\"";
// }
//
// public Str copy() {
// Str m = new Str();
// m.ptr = Pointer.create(this.ptr.buffer, this.ptr.start);
// m.len = this.len;
// return m;
// }
// }
// }// Data
//
// Path: src/main/org/yecht/MapStyle.java
// public enum MapStyle {
// None, Inline
// }
// Path: ext/ruby/src/java/org/yecht/ruby/Map.java
import org.yecht.Data;
import org.yecht.MapStyle;
import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.RubyClass;
import org.jruby.RubyHash;
import org.jruby.RubyObject;
import org.jruby.anno.JRubyMethod;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.TypeConverter;
package org.yecht.ruby;
public class Map {
public static final ObjectAllocator Allocator = new ObjectAllocator() {
// syck_map_alloc
public IRubyObject allocate(Ruby runtime, RubyClass klass) {
// System.err.println("ALLOCATING MAP");
org.yecht.Node node = org.yecht.Node.allocMap();
IRubyObject obj = new Node(runtime, klass, node, (YAMLExtra)runtime.getModule("YAML").dataGetStruct());
node.id = obj;
// System.err.println("syck_map_alloc() -> setting id");
return obj;
}
};
// syck_map_initialize
@JRubyMethod
public static IRubyObject initialize(IRubyObject self, IRubyObject type_id, IRubyObject val, IRubyObject style) {
org.yecht.Node node = (org.yecht.Node)self.dataGetStructChecked();
Ruby runtime = self.getRuntime();
ThreadContext ctx = runtime.getCurrentContext(); | Data.Map ds = (Data.Map)node.data; |
olabini/yecht | ext/ruby/src/java/org/yecht/ruby/Map.java | // Path: src/main/org/yecht/Data.java
// public abstract class Data {
// public abstract Data copy();
//
// public static class Map extends Data {
// public MapStyle style;
// public Object[] keys;
// public Object[] values;
// public int capa;
// public int idx;
//
// public String toString() {
// return "{idx=" + idx + ", capa=" + capa + ", keys=" + java.util.Arrays.asList(keys) + ", values=" + java.util.Arrays.asList(values) + "}";
// }
//
// public Map copy() {
// Map m = new Map();
// m.style = this.style;
// m.keys = new Object[this.keys.length];
// System.arraycopy(this.keys, 0, m.keys, 0, this.keys.length);
// m.values = new Object[this.values.length];
// System.arraycopy(this.values, 0, m.values, 0, this.values.length);
// m.capa = this.capa;
// m.idx = this.idx;
// return m;
// }
// }
//
// public static class Seq extends Data {
// public SeqStyle style;
// public Object[] items;
// public int capa;
// public int idx;
//
// public String toString() {
// return "[idx=" + idx + ", capa=" + capa + ", items=" + java.util.Arrays.asList(items) + "]";
// }
//
// public Seq copy() {
// Seq m = new Seq();
// m.style = this.style;
// m.items = new Object[this.items.length];
// System.arraycopy(this.items, 0, m.items, 0, this.items.length);
// m.capa = this.capa;
// m.idx = this.idx;
// return m;
// }
// }
//
// public static class Str extends Data {
// public ScalarStyle style;
// public Pointer ptr;
// public int len;
//
// public String toString() {
// return "\"" + new String(ptr.buffer, ptr.start, len) + "\"";
// }
//
// public Str copy() {
// Str m = new Str();
// m.ptr = Pointer.create(this.ptr.buffer, this.ptr.start);
// m.len = this.len;
// return m;
// }
// }
// }// Data
//
// Path: src/main/org/yecht/MapStyle.java
// public enum MapStyle {
// None, Inline
// }
| import org.yecht.Data;
import org.yecht.MapStyle;
import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.RubyClass;
import org.jruby.RubyHash;
import org.jruby.RubyObject;
import org.jruby.anno.JRubyMethod;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.TypeConverter; | IRubyObject key = ((RubyArray)keys).entry(i);
node.mapAdd(key, ((RubyHash)hsh).op_aref(ctx, key));
}
}
((RubyObject)self).fastSetInstanceVariable("@value", val);
return val;
}
// syck_map_add_m
@JRubyMethod
public static IRubyObject add(IRubyObject self, IRubyObject key, IRubyObject val) {
IRubyObject emitter = (IRubyObject)((RubyObject)self).fastGetInstanceVariable("@emitter");
org.yecht.Node node = (org.yecht.Node)self.dataGetStructChecked();
if(emitter.respondsTo("node_export")) {
key = emitter.callMethod(self.getRuntime().getCurrentContext(), "node_export", key);
val = emitter.callMethod(self.getRuntime().getCurrentContext(), "node_export", val);
}
node.mapAdd(key, val);
((RubyHash)((RubyObject)self).fastGetInstanceVariable("@value")).fastASet(key, val);
return self;
}
// syck_map_style_set
@JRubyMethod(name = "style=")
public static IRubyObject style_set(IRubyObject self, IRubyObject style) {
org.yecht.Node node = (org.yecht.Node)self.dataGetStructChecked();
Ruby runtime = self.getRuntime();
Data.Map ds = (Data.Map)node.data;
if(style == ((Node)self).x.inline) { | // Path: src/main/org/yecht/Data.java
// public abstract class Data {
// public abstract Data copy();
//
// public static class Map extends Data {
// public MapStyle style;
// public Object[] keys;
// public Object[] values;
// public int capa;
// public int idx;
//
// public String toString() {
// return "{idx=" + idx + ", capa=" + capa + ", keys=" + java.util.Arrays.asList(keys) + ", values=" + java.util.Arrays.asList(values) + "}";
// }
//
// public Map copy() {
// Map m = new Map();
// m.style = this.style;
// m.keys = new Object[this.keys.length];
// System.arraycopy(this.keys, 0, m.keys, 0, this.keys.length);
// m.values = new Object[this.values.length];
// System.arraycopy(this.values, 0, m.values, 0, this.values.length);
// m.capa = this.capa;
// m.idx = this.idx;
// return m;
// }
// }
//
// public static class Seq extends Data {
// public SeqStyle style;
// public Object[] items;
// public int capa;
// public int idx;
//
// public String toString() {
// return "[idx=" + idx + ", capa=" + capa + ", items=" + java.util.Arrays.asList(items) + "]";
// }
//
// public Seq copy() {
// Seq m = new Seq();
// m.style = this.style;
// m.items = new Object[this.items.length];
// System.arraycopy(this.items, 0, m.items, 0, this.items.length);
// m.capa = this.capa;
// m.idx = this.idx;
// return m;
// }
// }
//
// public static class Str extends Data {
// public ScalarStyle style;
// public Pointer ptr;
// public int len;
//
// public String toString() {
// return "\"" + new String(ptr.buffer, ptr.start, len) + "\"";
// }
//
// public Str copy() {
// Str m = new Str();
// m.ptr = Pointer.create(this.ptr.buffer, this.ptr.start);
// m.len = this.len;
// return m;
// }
// }
// }// Data
//
// Path: src/main/org/yecht/MapStyle.java
// public enum MapStyle {
// None, Inline
// }
// Path: ext/ruby/src/java/org/yecht/ruby/Map.java
import org.yecht.Data;
import org.yecht.MapStyle;
import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.RubyClass;
import org.jruby.RubyHash;
import org.jruby.RubyObject;
import org.jruby.anno.JRubyMethod;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.TypeConverter;
IRubyObject key = ((RubyArray)keys).entry(i);
node.mapAdd(key, ((RubyHash)hsh).op_aref(ctx, key));
}
}
((RubyObject)self).fastSetInstanceVariable("@value", val);
return val;
}
// syck_map_add_m
@JRubyMethod
public static IRubyObject add(IRubyObject self, IRubyObject key, IRubyObject val) {
IRubyObject emitter = (IRubyObject)((RubyObject)self).fastGetInstanceVariable("@emitter");
org.yecht.Node node = (org.yecht.Node)self.dataGetStructChecked();
if(emitter.respondsTo("node_export")) {
key = emitter.callMethod(self.getRuntime().getCurrentContext(), "node_export", key);
val = emitter.callMethod(self.getRuntime().getCurrentContext(), "node_export", val);
}
node.mapAdd(key, val);
((RubyHash)((RubyObject)self).fastGetInstanceVariable("@value")).fastASet(key, val);
return self;
}
// syck_map_style_set
@JRubyMethod(name = "style=")
public static IRubyObject style_set(IRubyObject self, IRubyObject style) {
org.yecht.Node node = (org.yecht.Node)self.dataGetStructChecked();
Ruby runtime = self.getRuntime();
Data.Map ds = (Data.Map)node.data;
if(style == ((Node)self).x.inline) { | ds.style = MapStyle.Inline; |
olabini/yecht | ext/ruby/src/java/org/yecht/ruby/Node.java | // Path: src/main/org/yecht/MapPart.java
// public enum MapPart {
// Key, Value
// }// MapPart
| import org.yecht.MapPart;
import org.jruby.Ruby;
import org.jruby.RubyClass;
import org.jruby.RubyString;
import org.jruby.RubyObject;
import org.jruby.anno.JRubyMethod;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject; | }
// syck_node_type_id_set
@JRubyMethod(name = "type_id=")
public static IRubyObject set_type_id(IRubyObject self, IRubyObject type_id) {
org.yecht.Node node = (org.yecht.Node)self.dataGetStructChecked();
if(!type_id.isNil()) {
node.type_id = type_id.convertToString().toString();
}
((RubyObject)self).fastSetInstanceVariable("@type_id", type_id);
return type_id;
}
// syck_node_transform
@JRubyMethod
public static IRubyObject transform(IRubyObject self) {
// System.err.println("syck_node_transform()");
Ruby runtime = self.getRuntime();
ThreadContext ctx = runtime.getCurrentContext();
org.yecht.Node orig_n = (org.yecht.Node)self.dataGetStructChecked();
YAMLExtra x = ((Node)self).x;
IRubyObject t = new Node(runtime, self.getType(), null, x);
org.yecht.Node n = null;
switch(orig_n.kind) {
case Map:
n = org.yecht.Node.allocMap();
t.dataWrapStruct(n);
org.yecht.Data.Map dm = (org.yecht.Data.Map)orig_n.data;
for(int i=0; i < dm.idx; i++) { | // Path: src/main/org/yecht/MapPart.java
// public enum MapPart {
// Key, Value
// }// MapPart
// Path: ext/ruby/src/java/org/yecht/ruby/Node.java
import org.yecht.MapPart;
import org.jruby.Ruby;
import org.jruby.RubyClass;
import org.jruby.RubyString;
import org.jruby.RubyObject;
import org.jruby.anno.JRubyMethod;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
}
// syck_node_type_id_set
@JRubyMethod(name = "type_id=")
public static IRubyObject set_type_id(IRubyObject self, IRubyObject type_id) {
org.yecht.Node node = (org.yecht.Node)self.dataGetStructChecked();
if(!type_id.isNil()) {
node.type_id = type_id.convertToString().toString();
}
((RubyObject)self).fastSetInstanceVariable("@type_id", type_id);
return type_id;
}
// syck_node_transform
@JRubyMethod
public static IRubyObject transform(IRubyObject self) {
// System.err.println("syck_node_transform()");
Ruby runtime = self.getRuntime();
ThreadContext ctx = runtime.getCurrentContext();
org.yecht.Node orig_n = (org.yecht.Node)self.dataGetStructChecked();
YAMLExtra x = ((Node)self).x;
IRubyObject t = new Node(runtime, self.getType(), null, x);
org.yecht.Node n = null;
switch(orig_n.kind) {
case Map:
n = org.yecht.Node.allocMap();
t.dataWrapStruct(n);
org.yecht.Data.Map dm = (org.yecht.Data.Map)orig_n.data;
for(int i=0; i < dm.idx; i++) { | IRubyObject k = ((IRubyObject)orig_n.mapRead(MapPart.Key, i)).callMethod(ctx, "transform"); |
olabini/yecht | ext/ruby/src/java/org/yecht/ruby/Resolver.java | // Path: src/main/org/yecht/Data.java
// public abstract class Data {
// public abstract Data copy();
//
// public static class Map extends Data {
// public MapStyle style;
// public Object[] keys;
// public Object[] values;
// public int capa;
// public int idx;
//
// public String toString() {
// return "{idx=" + idx + ", capa=" + capa + ", keys=" + java.util.Arrays.asList(keys) + ", values=" + java.util.Arrays.asList(values) + "}";
// }
//
// public Map copy() {
// Map m = new Map();
// m.style = this.style;
// m.keys = new Object[this.keys.length];
// System.arraycopy(this.keys, 0, m.keys, 0, this.keys.length);
// m.values = new Object[this.values.length];
// System.arraycopy(this.values, 0, m.values, 0, this.values.length);
// m.capa = this.capa;
// m.idx = this.idx;
// return m;
// }
// }
//
// public static class Seq extends Data {
// public SeqStyle style;
// public Object[] items;
// public int capa;
// public int idx;
//
// public String toString() {
// return "[idx=" + idx + ", capa=" + capa + ", items=" + java.util.Arrays.asList(items) + "]";
// }
//
// public Seq copy() {
// Seq m = new Seq();
// m.style = this.style;
// m.items = new Object[this.items.length];
// System.arraycopy(this.items, 0, m.items, 0, this.items.length);
// m.capa = this.capa;
// m.idx = this.idx;
// return m;
// }
// }
//
// public static class Str extends Data {
// public ScalarStyle style;
// public Pointer ptr;
// public int len;
//
// public String toString() {
// return "\"" + new String(ptr.buffer, ptr.start, len) + "\"";
// }
//
// public Str copy() {
// Str m = new Str();
// m.ptr = Pointer.create(this.ptr.buffer, this.ptr.start);
// m.len = this.len;
// return m;
// }
// }
// }// Data
//
// Path: src/main/org/yecht/MapPart.java
// public enum MapPart {
// Key, Value
// }// MapPart
| import java.util.List;
import org.yecht.Data;
import org.yecht.ImplicitScanner;
import org.yecht.MapPart;
import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.RubyClass;
import org.jruby.RubyEnumerable;
import org.jruby.RubyHash;
import org.jruby.RubyModule;
import org.jruby.RubyNumeric;
import org.jruby.RubyObject;
import org.jruby.RubyString;
import org.jruby.anno.JRubyMethod;
import org.jruby.runtime.Block;
import org.jruby.runtime.BlockCallback;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.TypeConverter; | IRubyObject scheme = parts.shift(ctx);
if(scheme.convertToString().toString().equals("x-private")) {
IRubyObject name = parts.join(ctx, colon);
obj = ((RubyModule)((RubyModule)runtime.getModule("YAML")).getConstant("Yecht")).getConstant("PrivateType").callMethod(ctx, "new", new IRubyObject[]{name, val});
} else {
IRubyObject domain = parts.shift(ctx);
IRubyObject name = parts.join(ctx, colon);
obj = ((RubyModule)((RubyModule)runtime.getModule("YAML")).getConstant("Yecht")).getConstant("DomainType").callMethod(ctx, "new", new IRubyObject[]{domain, name, val});
}
}
}
val = obj;
}
return val;
}
// syck_resolver_node_import
@JRubyMethod
public static IRubyObject node_import(IRubyObject self, IRubyObject node) {
// System.err.println("syck_resolver_node_import()");
final Ruby runtime = self.getRuntime();
final ThreadContext ctx = runtime.getCurrentContext();
org.yecht.Node n = (org.yecht.Node)node.dataGetStructChecked();
YAMLExtra x = ((Node)node).x;
IRubyObject obj = null;
switch(n.kind) {
case Str: | // Path: src/main/org/yecht/Data.java
// public abstract class Data {
// public abstract Data copy();
//
// public static class Map extends Data {
// public MapStyle style;
// public Object[] keys;
// public Object[] values;
// public int capa;
// public int idx;
//
// public String toString() {
// return "{idx=" + idx + ", capa=" + capa + ", keys=" + java.util.Arrays.asList(keys) + ", values=" + java.util.Arrays.asList(values) + "}";
// }
//
// public Map copy() {
// Map m = new Map();
// m.style = this.style;
// m.keys = new Object[this.keys.length];
// System.arraycopy(this.keys, 0, m.keys, 0, this.keys.length);
// m.values = new Object[this.values.length];
// System.arraycopy(this.values, 0, m.values, 0, this.values.length);
// m.capa = this.capa;
// m.idx = this.idx;
// return m;
// }
// }
//
// public static class Seq extends Data {
// public SeqStyle style;
// public Object[] items;
// public int capa;
// public int idx;
//
// public String toString() {
// return "[idx=" + idx + ", capa=" + capa + ", items=" + java.util.Arrays.asList(items) + "]";
// }
//
// public Seq copy() {
// Seq m = new Seq();
// m.style = this.style;
// m.items = new Object[this.items.length];
// System.arraycopy(this.items, 0, m.items, 0, this.items.length);
// m.capa = this.capa;
// m.idx = this.idx;
// return m;
// }
// }
//
// public static class Str extends Data {
// public ScalarStyle style;
// public Pointer ptr;
// public int len;
//
// public String toString() {
// return "\"" + new String(ptr.buffer, ptr.start, len) + "\"";
// }
//
// public Str copy() {
// Str m = new Str();
// m.ptr = Pointer.create(this.ptr.buffer, this.ptr.start);
// m.len = this.len;
// return m;
// }
// }
// }// Data
//
// Path: src/main/org/yecht/MapPart.java
// public enum MapPart {
// Key, Value
// }// MapPart
// Path: ext/ruby/src/java/org/yecht/ruby/Resolver.java
import java.util.List;
import org.yecht.Data;
import org.yecht.ImplicitScanner;
import org.yecht.MapPart;
import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.RubyClass;
import org.jruby.RubyEnumerable;
import org.jruby.RubyHash;
import org.jruby.RubyModule;
import org.jruby.RubyNumeric;
import org.jruby.RubyObject;
import org.jruby.RubyString;
import org.jruby.anno.JRubyMethod;
import org.jruby.runtime.Block;
import org.jruby.runtime.BlockCallback;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.TypeConverter;
IRubyObject scheme = parts.shift(ctx);
if(scheme.convertToString().toString().equals("x-private")) {
IRubyObject name = parts.join(ctx, colon);
obj = ((RubyModule)((RubyModule)runtime.getModule("YAML")).getConstant("Yecht")).getConstant("PrivateType").callMethod(ctx, "new", new IRubyObject[]{name, val});
} else {
IRubyObject domain = parts.shift(ctx);
IRubyObject name = parts.join(ctx, colon);
obj = ((RubyModule)((RubyModule)runtime.getModule("YAML")).getConstant("Yecht")).getConstant("DomainType").callMethod(ctx, "new", new IRubyObject[]{domain, name, val});
}
}
}
val = obj;
}
return val;
}
// syck_resolver_node_import
@JRubyMethod
public static IRubyObject node_import(IRubyObject self, IRubyObject node) {
// System.err.println("syck_resolver_node_import()");
final Ruby runtime = self.getRuntime();
final ThreadContext ctx = runtime.getCurrentContext();
org.yecht.Node n = (org.yecht.Node)node.dataGetStructChecked();
YAMLExtra x = ((Node)node).x;
IRubyObject obj = null;
switch(n.kind) {
case Str: | Data.Str dd = (Data.Str)n.data; |
olabini/yecht | ext/ruby/src/java/org/yecht/ruby/Resolver.java | // Path: src/main/org/yecht/Data.java
// public abstract class Data {
// public abstract Data copy();
//
// public static class Map extends Data {
// public MapStyle style;
// public Object[] keys;
// public Object[] values;
// public int capa;
// public int idx;
//
// public String toString() {
// return "{idx=" + idx + ", capa=" + capa + ", keys=" + java.util.Arrays.asList(keys) + ", values=" + java.util.Arrays.asList(values) + "}";
// }
//
// public Map copy() {
// Map m = new Map();
// m.style = this.style;
// m.keys = new Object[this.keys.length];
// System.arraycopy(this.keys, 0, m.keys, 0, this.keys.length);
// m.values = new Object[this.values.length];
// System.arraycopy(this.values, 0, m.values, 0, this.values.length);
// m.capa = this.capa;
// m.idx = this.idx;
// return m;
// }
// }
//
// public static class Seq extends Data {
// public SeqStyle style;
// public Object[] items;
// public int capa;
// public int idx;
//
// public String toString() {
// return "[idx=" + idx + ", capa=" + capa + ", items=" + java.util.Arrays.asList(items) + "]";
// }
//
// public Seq copy() {
// Seq m = new Seq();
// m.style = this.style;
// m.items = new Object[this.items.length];
// System.arraycopy(this.items, 0, m.items, 0, this.items.length);
// m.capa = this.capa;
// m.idx = this.idx;
// return m;
// }
// }
//
// public static class Str extends Data {
// public ScalarStyle style;
// public Pointer ptr;
// public int len;
//
// public String toString() {
// return "\"" + new String(ptr.buffer, ptr.start, len) + "\"";
// }
//
// public Str copy() {
// Str m = new Str();
// m.ptr = Pointer.create(this.ptr.buffer, this.ptr.start);
// m.len = this.len;
// return m;
// }
// }
// }// Data
//
// Path: src/main/org/yecht/MapPart.java
// public enum MapPart {
// Key, Value
// }// MapPart
| import java.util.List;
import org.yecht.Data;
import org.yecht.ImplicitScanner;
import org.yecht.MapPart;
import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.RubyClass;
import org.jruby.RubyEnumerable;
import org.jruby.RubyHash;
import org.jruby.RubyModule;
import org.jruby.RubyNumeric;
import org.jruby.RubyObject;
import org.jruby.RubyString;
import org.jruby.anno.JRubyMethod;
import org.jruby.runtime.Block;
import org.jruby.runtime.BlockCallback;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.TypeConverter; | @JRubyMethod
public static IRubyObject node_import(IRubyObject self, IRubyObject node) {
// System.err.println("syck_resolver_node_import()");
final Ruby runtime = self.getRuntime();
final ThreadContext ctx = runtime.getCurrentContext();
org.yecht.Node n = (org.yecht.Node)node.dataGetStructChecked();
YAMLExtra x = ((Node)node).x;
IRubyObject obj = null;
switch(n.kind) {
case Str:
Data.Str dd = (Data.Str)n.data;
obj = RubyString.newStringShared(runtime, dd.ptr.buffer, dd.ptr.start, dd.len);
break;
case Seq:
Data.Seq ds = (Data.Seq)n.data;
obj = RubyArray.newArray(runtime, ds.idx);
for(int i = 0; i < ds.idx; i++) {
IRubyObject obj2 = (IRubyObject)n.seqRead(i);
((RubyArray)obj).store(i, obj2);
}
break;
case Map:
Data.Map dm = (Data.Map)n.data;
obj = RubyHash.newHash(runtime);
RubyClass cMergeKey = x.MergeKey;
RubyClass cDefaultKey = x.DefaultKey;
RubyClass cHash = runtime.getHash();
RubyClass cArray = runtime.getArray();
for(int i = 0; i < dm.idx; i++) { | // Path: src/main/org/yecht/Data.java
// public abstract class Data {
// public abstract Data copy();
//
// public static class Map extends Data {
// public MapStyle style;
// public Object[] keys;
// public Object[] values;
// public int capa;
// public int idx;
//
// public String toString() {
// return "{idx=" + idx + ", capa=" + capa + ", keys=" + java.util.Arrays.asList(keys) + ", values=" + java.util.Arrays.asList(values) + "}";
// }
//
// public Map copy() {
// Map m = new Map();
// m.style = this.style;
// m.keys = new Object[this.keys.length];
// System.arraycopy(this.keys, 0, m.keys, 0, this.keys.length);
// m.values = new Object[this.values.length];
// System.arraycopy(this.values, 0, m.values, 0, this.values.length);
// m.capa = this.capa;
// m.idx = this.idx;
// return m;
// }
// }
//
// public static class Seq extends Data {
// public SeqStyle style;
// public Object[] items;
// public int capa;
// public int idx;
//
// public String toString() {
// return "[idx=" + idx + ", capa=" + capa + ", items=" + java.util.Arrays.asList(items) + "]";
// }
//
// public Seq copy() {
// Seq m = new Seq();
// m.style = this.style;
// m.items = new Object[this.items.length];
// System.arraycopy(this.items, 0, m.items, 0, this.items.length);
// m.capa = this.capa;
// m.idx = this.idx;
// return m;
// }
// }
//
// public static class Str extends Data {
// public ScalarStyle style;
// public Pointer ptr;
// public int len;
//
// public String toString() {
// return "\"" + new String(ptr.buffer, ptr.start, len) + "\"";
// }
//
// public Str copy() {
// Str m = new Str();
// m.ptr = Pointer.create(this.ptr.buffer, this.ptr.start);
// m.len = this.len;
// return m;
// }
// }
// }// Data
//
// Path: src/main/org/yecht/MapPart.java
// public enum MapPart {
// Key, Value
// }// MapPart
// Path: ext/ruby/src/java/org/yecht/ruby/Resolver.java
import java.util.List;
import org.yecht.Data;
import org.yecht.ImplicitScanner;
import org.yecht.MapPart;
import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.RubyClass;
import org.jruby.RubyEnumerable;
import org.jruby.RubyHash;
import org.jruby.RubyModule;
import org.jruby.RubyNumeric;
import org.jruby.RubyObject;
import org.jruby.RubyString;
import org.jruby.anno.JRubyMethod;
import org.jruby.runtime.Block;
import org.jruby.runtime.BlockCallback;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.TypeConverter;
@JRubyMethod
public static IRubyObject node_import(IRubyObject self, IRubyObject node) {
// System.err.println("syck_resolver_node_import()");
final Ruby runtime = self.getRuntime();
final ThreadContext ctx = runtime.getCurrentContext();
org.yecht.Node n = (org.yecht.Node)node.dataGetStructChecked();
YAMLExtra x = ((Node)node).x;
IRubyObject obj = null;
switch(n.kind) {
case Str:
Data.Str dd = (Data.Str)n.data;
obj = RubyString.newStringShared(runtime, dd.ptr.buffer, dd.ptr.start, dd.len);
break;
case Seq:
Data.Seq ds = (Data.Seq)n.data;
obj = RubyArray.newArray(runtime, ds.idx);
for(int i = 0; i < ds.idx; i++) {
IRubyObject obj2 = (IRubyObject)n.seqRead(i);
((RubyArray)obj).store(i, obj2);
}
break;
case Map:
Data.Map dm = (Data.Map)n.data;
obj = RubyHash.newHash(runtime);
RubyClass cMergeKey = x.MergeKey;
RubyClass cDefaultKey = x.DefaultKey;
RubyClass cHash = runtime.getHash();
RubyClass cArray = runtime.getArray();
for(int i = 0; i < dm.idx; i++) { | IRubyObject k = (IRubyObject)n.mapRead(MapPart.Key, i); |
olabini/yecht | ext/ruby/src/java/YechtService.java | // Path: src/main/org/yecht/YAML.java
// public class YAML {
// public final static int BLOCK_FOLD = 10;
// public final static int BLOCK_LIT = 20;
// public final static int BLOCK_PLAIN = 30;
// public final static int NL_CHOMP = 40;
// public final static int NL_KEEP = 50;
//
// public final static int YAML_MAJOR = 1;
// public final static int YAML_MINOR = 0;
//
// public final static String YECHT_VERSION = "0.0.2";
// public final static String DOMAIN = "yaml.org,2002";
//
// public final static int ALLOC_CT = 8;
// public final static int BUFFERSIZE = 4096;
//
// public final static String DEFAULT_ANCHOR_FORMAT = "id%03d";
//
// /* specify list of bytecodes */
// public final static byte BYTE_FINISH = (byte) 0;
// public final static byte BYTE_DOCUMENT = (byte)'D';
// public final static byte BYTE_DIRECTIVE = (byte)'V';
// public final static byte BYTE_PAUSE = (byte)'P';
// public final static byte BYTE_MAPPING = (byte)'M';
// public final static byte BYTE_SEQUENCE = (byte)'Q';
// public final static byte BYTE_END_BRANCH = (byte)'E';
// public final static byte BYTE_SCALAR = (byte)'S';
// public final static byte BYTE_CONTINUE = (byte)'C';
// public final static byte BYTE_NEWLINE = (byte)'N';
// public final static byte BYTE_NULLCHAR = (byte)'Z';
// public final static byte BYTE_ANCHOR = (byte)'A';
// public final static byte BYTE_ALIAS = (byte)'R';
// public final static byte BYTE_TRANSFER = (byte)'T';
// /* formatting bytecodes */
// public final static byte BYTE_COMMENT = (byte)'c';
// public final static byte BYTE_INDENT = (byte)'i';
// public final static byte BYTE_STYLE = (byte)'s';
// /* other bytecodes */
// public final static byte BYTE_LINE_NUMBER = (byte)'#';
// public final static byte BYTE_WHOLE_SCALAR = (byte)'<';
// public final static byte BYTE_NOTICE = (byte)'!';
// public final static byte BYTE_SPAN = (byte)')';
// public final static byte BYTE_ALLOC = (byte)'@';
//
// /* second level style bytecodes, ie "s>" */
// public final static byte BYTE_FLOW = (byte)'>';
// public final static byte BYTE_LITERAL = (byte)'|';
// public final static byte BYTE_BLOCK = (byte)'b';
// public final static byte BYTE_PLAIN = (byte)'p';
// public final static byte BYTE_INLINE_MAPPING = (byte)'{';
// public final static byte BYTE_INLINE_SEQUENCE = (byte)'[';
// public final static byte BYTE_SINGLE_QUOTED = (byte)39;
// public final static byte BYTE_DOUBLE_QUOTED = (byte)'"';
//
//
//
// public static byte[] realloc(byte[] input, int size) {
// byte[] newArray = new byte[size];
// System.arraycopy(input, 0, newArray, 0, input.length);
// return newArray;
// }
//
// public static long[] realloc(long[] input, int size) {
// long[] newArray = new long[size];
// System.arraycopy(input, 0, newArray, 0, input.length);
// return newArray;
// }
//
// public static Level[] realloc(Level[] input, int size) {
// Level[] newArray = new Level[size];
// System.arraycopy(input, 0, newArray, 0, input.length);
// return newArray;
// }
//
// public static Object[] realloc(Object[] input, int size) {
// Object[] newArray = new Object[size];
// System.arraycopy(input, 0, newArray, 0, input.length);
// return newArray;
// }
//
// // syck_yaml2byte
// public static byte[] yaml2byte(byte[] yamlstr) {
// Parser parser = Parser.newParser();
// parser.str(Pointer.create(yamlstr, 0), null);
// parser.handler(new BytecodeNodeHandler());
// parser.errorHandler(null);
// parser.implicitTyping(true);
// parser.taguriExpansion(true);
// Bytestring sav = (Bytestring)parser.parse();
// if(null == sav) {
// return null;
// } else {
// byte[] ret = new byte[Bytestring.strlen(sav.buffer) + 2];
// ret[0] = 'D';
// ret[1] = '\n';
// System.arraycopy(sav.buffer, 0, ret, 2, ret.length-2);
// return ret;
// }
// }
//
// public static void main(String[] args) throws Exception {
// byte[] yaml = "test: 1\nand: \"with new\\nline\\n\"\nalso: &3 three\nmore: *3".getBytes("ISO-8859-1");
// System.out.println("--- # YAML ");
// System.out.print(new String(yaml, "ISO-8859-1"));
// System.out.print("\n...\n");
// System.out.print(new String(yaml2byte(yaml), "ISO-8859-1"));
// }
// }
| import java.io.IOException;
import org.jruby.Ruby;
import org.jruby.RubyClass;
import org.jruby.RubyModule;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.load.BasicLibraryService;
import org.yecht.YAML;
import org.yecht.ruby.*; |
public class YechtService implements BasicLibraryService {
public boolean basicLoad(final Ruby runtime) throws IOException {
ThreadContext ctx = runtime.getCurrentContext();
| // Path: src/main/org/yecht/YAML.java
// public class YAML {
// public final static int BLOCK_FOLD = 10;
// public final static int BLOCK_LIT = 20;
// public final static int BLOCK_PLAIN = 30;
// public final static int NL_CHOMP = 40;
// public final static int NL_KEEP = 50;
//
// public final static int YAML_MAJOR = 1;
// public final static int YAML_MINOR = 0;
//
// public final static String YECHT_VERSION = "0.0.2";
// public final static String DOMAIN = "yaml.org,2002";
//
// public final static int ALLOC_CT = 8;
// public final static int BUFFERSIZE = 4096;
//
// public final static String DEFAULT_ANCHOR_FORMAT = "id%03d";
//
// /* specify list of bytecodes */
// public final static byte BYTE_FINISH = (byte) 0;
// public final static byte BYTE_DOCUMENT = (byte)'D';
// public final static byte BYTE_DIRECTIVE = (byte)'V';
// public final static byte BYTE_PAUSE = (byte)'P';
// public final static byte BYTE_MAPPING = (byte)'M';
// public final static byte BYTE_SEQUENCE = (byte)'Q';
// public final static byte BYTE_END_BRANCH = (byte)'E';
// public final static byte BYTE_SCALAR = (byte)'S';
// public final static byte BYTE_CONTINUE = (byte)'C';
// public final static byte BYTE_NEWLINE = (byte)'N';
// public final static byte BYTE_NULLCHAR = (byte)'Z';
// public final static byte BYTE_ANCHOR = (byte)'A';
// public final static byte BYTE_ALIAS = (byte)'R';
// public final static byte BYTE_TRANSFER = (byte)'T';
// /* formatting bytecodes */
// public final static byte BYTE_COMMENT = (byte)'c';
// public final static byte BYTE_INDENT = (byte)'i';
// public final static byte BYTE_STYLE = (byte)'s';
// /* other bytecodes */
// public final static byte BYTE_LINE_NUMBER = (byte)'#';
// public final static byte BYTE_WHOLE_SCALAR = (byte)'<';
// public final static byte BYTE_NOTICE = (byte)'!';
// public final static byte BYTE_SPAN = (byte)')';
// public final static byte BYTE_ALLOC = (byte)'@';
//
// /* second level style bytecodes, ie "s>" */
// public final static byte BYTE_FLOW = (byte)'>';
// public final static byte BYTE_LITERAL = (byte)'|';
// public final static byte BYTE_BLOCK = (byte)'b';
// public final static byte BYTE_PLAIN = (byte)'p';
// public final static byte BYTE_INLINE_MAPPING = (byte)'{';
// public final static byte BYTE_INLINE_SEQUENCE = (byte)'[';
// public final static byte BYTE_SINGLE_QUOTED = (byte)39;
// public final static byte BYTE_DOUBLE_QUOTED = (byte)'"';
//
//
//
// public static byte[] realloc(byte[] input, int size) {
// byte[] newArray = new byte[size];
// System.arraycopy(input, 0, newArray, 0, input.length);
// return newArray;
// }
//
// public static long[] realloc(long[] input, int size) {
// long[] newArray = new long[size];
// System.arraycopy(input, 0, newArray, 0, input.length);
// return newArray;
// }
//
// public static Level[] realloc(Level[] input, int size) {
// Level[] newArray = new Level[size];
// System.arraycopy(input, 0, newArray, 0, input.length);
// return newArray;
// }
//
// public static Object[] realloc(Object[] input, int size) {
// Object[] newArray = new Object[size];
// System.arraycopy(input, 0, newArray, 0, input.length);
// return newArray;
// }
//
// // syck_yaml2byte
// public static byte[] yaml2byte(byte[] yamlstr) {
// Parser parser = Parser.newParser();
// parser.str(Pointer.create(yamlstr, 0), null);
// parser.handler(new BytecodeNodeHandler());
// parser.errorHandler(null);
// parser.implicitTyping(true);
// parser.taguriExpansion(true);
// Bytestring sav = (Bytestring)parser.parse();
// if(null == sav) {
// return null;
// } else {
// byte[] ret = new byte[Bytestring.strlen(sav.buffer) + 2];
// ret[0] = 'D';
// ret[1] = '\n';
// System.arraycopy(sav.buffer, 0, ret, 2, ret.length-2);
// return ret;
// }
// }
//
// public static void main(String[] args) throws Exception {
// byte[] yaml = "test: 1\nand: \"with new\\nline\\n\"\nalso: &3 three\nmore: *3".getBytes("ISO-8859-1");
// System.out.println("--- # YAML ");
// System.out.print(new String(yaml, "ISO-8859-1"));
// System.out.print("\n...\n");
// System.out.print(new String(yaml2byte(yaml), "ISO-8859-1"));
// }
// }
// Path: ext/ruby/src/java/YechtService.java
import java.io.IOException;
import org.jruby.Ruby;
import org.jruby.RubyClass;
import org.jruby.RubyModule;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.load.BasicLibraryService;
import org.yecht.YAML;
import org.yecht.ruby.*;
public class YechtService implements BasicLibraryService {
public boolean basicLoad(final Ruby runtime) throws IOException {
ThreadContext ctx = runtime.getCurrentContext();
| RubyModule rb_yaml = runtime.getOrCreateModule("YAML"); |
7upcat/agile-wroking-backend | src/test/java/org/catframework/agileworking/scheduling/SendNotifyMessageJobTest.java | // Path: src/main/java/org/catframework/agileworking/utils/DateUtils.java
// public final class DateUtils {
//
// /** 简单的日期格式: yyyy-MM-dd */
// public static final String PATTERN_SIMPLE_DATE = "yyyy-MM-dd";
//
// public static final Date parse(String source, String pattern) {
// try {
// return new SimpleDateFormat(pattern).parse(source);
// } catch (ParseException e) {
// throw new RuntimeException(e);
// }
// }
//
// public static final String format(Date date, String pattern) {
// return new SimpleDateFormat(pattern).format(date);
// }
//
// /**
// * 判断指定的两个日期的所属的星期是否相同.
// *
// * @return 当两个日期相同时返回 <code>true</code>
// */
// public static boolean isSameWeekOfday(Date d1, Date d2) {
// Calendar d1Cal = Calendar.getInstance();
// d1Cal.setTime(d1);
// Calendar d2Cal = Calendar.getInstance();
// d2Cal.setTime(d2);
// return d1Cal.get(Calendar.DAY_OF_WEEK) == d2Cal.get(Calendar.DAY_OF_WEEK);
// }
//
// }
| import java.util.Date;
import org.catframework.agileworking.utils.DateUtils;
import org.junit.Test; | package org.catframework.agileworking.scheduling;
public class SendNotifyMessageJobTest {
@Test
public void testIsNeedSendMessageNow() { | // Path: src/main/java/org/catframework/agileworking/utils/DateUtils.java
// public final class DateUtils {
//
// /** 简单的日期格式: yyyy-MM-dd */
// public static final String PATTERN_SIMPLE_DATE = "yyyy-MM-dd";
//
// public static final Date parse(String source, String pattern) {
// try {
// return new SimpleDateFormat(pattern).parse(source);
// } catch (ParseException e) {
// throw new RuntimeException(e);
// }
// }
//
// public static final String format(Date date, String pattern) {
// return new SimpleDateFormat(pattern).format(date);
// }
//
// /**
// * 判断指定的两个日期的所属的星期是否相同.
// *
// * @return 当两个日期相同时返回 <code>true</code>
// */
// public static boolean isSameWeekOfday(Date d1, Date d2) {
// Calendar d1Cal = Calendar.getInstance();
// d1Cal.setTime(d1);
// Calendar d2Cal = Calendar.getInstance();
// d2Cal.setTime(d2);
// return d1Cal.get(Calendar.DAY_OF_WEEK) == d2Cal.get(Calendar.DAY_OF_WEEK);
// }
//
// }
// Path: src/test/java/org/catframework/agileworking/scheduling/SendNotifyMessageJobTest.java
import java.util.Date;
import org.catframework.agileworking.utils.DateUtils;
import org.junit.Test;
package org.catframework.agileworking.scheduling;
public class SendNotifyMessageJobTest {
@Test
public void testIsNeedSendMessageNow() { | Date d =DateUtils.parse("2017-08-31" + " " + "10:20",DateUtils.PATTERN_SIMPLE_DATE + " HH:mm"); |
7upcat/agile-wroking-backend | src/main/java/org/catframework/agileworking/web/support/DefaultResult.java | // Path: src/main/java/org/catframework/agileworking/BusinessException.java
// public class BusinessException extends RuntimeException {
//
// private static final long serialVersionUID = 3999713779564898790L;
//
// private String code;
//
// public BusinessException(String code) {
// this.code = code;
// }
//
// public BusinessException(String code, String message) {
// super(message);
// this.code = code;
// }
//
// public BusinessException(String code, String message, Throwable cause) {
// super(message, cause);
// this.code = code;
// }
//
// public String getCode() {
// return code;
// }
//
// }
//
// Path: src/main/java/org/catframework/agileworking/common/ResponseCodes.java
// public final class ResponseCodes {
//
// /** 响应码:成功. */
// public static final String RESPONSE_CODE_SUCCESS = "SC0000";
//
// /** 响应码:默认的系统处理异常,用于非预期的运行时异常. */
// public static final String RESPONSE_CODE_SYSTEM_ERROR = "ER0001";
// }
| import java.util.HashMap;
import java.util.Map;
import org.catframework.agileworking.BusinessException;
import org.catframework.agileworking.common.ResponseCodes; | package org.catframework.agileworking.web.support;
public class DefaultResult<T> implements Result<T> {
/**
* 创建一个成功的结果,不含 payload
*/
public static Result<?> newResult() {
DefaultResult<?> result = new DefaultResult<>();
result.status = Result.STATUS_SUCCESS; | // Path: src/main/java/org/catframework/agileworking/BusinessException.java
// public class BusinessException extends RuntimeException {
//
// private static final long serialVersionUID = 3999713779564898790L;
//
// private String code;
//
// public BusinessException(String code) {
// this.code = code;
// }
//
// public BusinessException(String code, String message) {
// super(message);
// this.code = code;
// }
//
// public BusinessException(String code, String message, Throwable cause) {
// super(message, cause);
// this.code = code;
// }
//
// public String getCode() {
// return code;
// }
//
// }
//
// Path: src/main/java/org/catframework/agileworking/common/ResponseCodes.java
// public final class ResponseCodes {
//
// /** 响应码:成功. */
// public static final String RESPONSE_CODE_SUCCESS = "SC0000";
//
// /** 响应码:默认的系统处理异常,用于非预期的运行时异常. */
// public static final String RESPONSE_CODE_SYSTEM_ERROR = "ER0001";
// }
// Path: src/main/java/org/catframework/agileworking/web/support/DefaultResult.java
import java.util.HashMap;
import java.util.Map;
import org.catframework.agileworking.BusinessException;
import org.catframework.agileworking.common.ResponseCodes;
package org.catframework.agileworking.web.support;
public class DefaultResult<T> implements Result<T> {
/**
* 创建一个成功的结果,不含 payload
*/
public static Result<?> newResult() {
DefaultResult<?> result = new DefaultResult<>();
result.status = Result.STATUS_SUCCESS; | result.responseCode = ResponseCodes.RESPONSE_CODE_SUCCESS; |
7upcat/agile-wroking-backend | src/main/java/org/catframework/agileworking/web/support/DefaultResult.java | // Path: src/main/java/org/catframework/agileworking/BusinessException.java
// public class BusinessException extends RuntimeException {
//
// private static final long serialVersionUID = 3999713779564898790L;
//
// private String code;
//
// public BusinessException(String code) {
// this.code = code;
// }
//
// public BusinessException(String code, String message) {
// super(message);
// this.code = code;
// }
//
// public BusinessException(String code, String message, Throwable cause) {
// super(message, cause);
// this.code = code;
// }
//
// public String getCode() {
// return code;
// }
//
// }
//
// Path: src/main/java/org/catframework/agileworking/common/ResponseCodes.java
// public final class ResponseCodes {
//
// /** 响应码:成功. */
// public static final String RESPONSE_CODE_SUCCESS = "SC0000";
//
// /** 响应码:默认的系统处理异常,用于非预期的运行时异常. */
// public static final String RESPONSE_CODE_SYSTEM_ERROR = "ER0001";
// }
| import java.util.HashMap;
import java.util.Map;
import org.catframework.agileworking.BusinessException;
import org.catframework.agileworking.common.ResponseCodes; | package org.catframework.agileworking.web.support;
public class DefaultResult<T> implements Result<T> {
/**
* 创建一个成功的结果,不含 payload
*/
public static Result<?> newResult() {
DefaultResult<?> result = new DefaultResult<>();
result.status = Result.STATUS_SUCCESS;
result.responseCode = ResponseCodes.RESPONSE_CODE_SUCCESS;
return result;
}
/**
* 创建一个成功的结果
*
* @param payload 结果中的数据
* @return 新创建的交易结果
*/
public static <T> Result<T> newResult(T payload) {
DefaultResult<T> result = new DefaultResult<>();
result.status = Result.STATUS_SUCCESS;
result.responseCode = ResponseCodes.RESPONSE_CODE_SUCCESS;
result.payload = payload;
return result;
}
/**
* 创建一个失败的结果
*
* @param ex 导致交易失败的具体异常
* @return 新创建的交易结果
*/
public static <T> Result<T> newFailResult(Throwable ex) {
DefaultResult<T> result = new DefaultResult<>();
result.status = Result.STATUS_FAIL;
result.responseMessage = ex.getMessage(); | // Path: src/main/java/org/catframework/agileworking/BusinessException.java
// public class BusinessException extends RuntimeException {
//
// private static final long serialVersionUID = 3999713779564898790L;
//
// private String code;
//
// public BusinessException(String code) {
// this.code = code;
// }
//
// public BusinessException(String code, String message) {
// super(message);
// this.code = code;
// }
//
// public BusinessException(String code, String message, Throwable cause) {
// super(message, cause);
// this.code = code;
// }
//
// public String getCode() {
// return code;
// }
//
// }
//
// Path: src/main/java/org/catframework/agileworking/common/ResponseCodes.java
// public final class ResponseCodes {
//
// /** 响应码:成功. */
// public static final String RESPONSE_CODE_SUCCESS = "SC0000";
//
// /** 响应码:默认的系统处理异常,用于非预期的运行时异常. */
// public static final String RESPONSE_CODE_SYSTEM_ERROR = "ER0001";
// }
// Path: src/main/java/org/catframework/agileworking/web/support/DefaultResult.java
import java.util.HashMap;
import java.util.Map;
import org.catframework.agileworking.BusinessException;
import org.catframework.agileworking.common.ResponseCodes;
package org.catframework.agileworking.web.support;
public class DefaultResult<T> implements Result<T> {
/**
* 创建一个成功的结果,不含 payload
*/
public static Result<?> newResult() {
DefaultResult<?> result = new DefaultResult<>();
result.status = Result.STATUS_SUCCESS;
result.responseCode = ResponseCodes.RESPONSE_CODE_SUCCESS;
return result;
}
/**
* 创建一个成功的结果
*
* @param payload 结果中的数据
* @return 新创建的交易结果
*/
public static <T> Result<T> newResult(T payload) {
DefaultResult<T> result = new DefaultResult<>();
result.status = Result.STATUS_SUCCESS;
result.responseCode = ResponseCodes.RESPONSE_CODE_SUCCESS;
result.payload = payload;
return result;
}
/**
* 创建一个失败的结果
*
* @param ex 导致交易失败的具体异常
* @return 新创建的交易结果
*/
public static <T> Result<T> newFailResult(Throwable ex) {
DefaultResult<T> result = new DefaultResult<>();
result.status = Result.STATUS_FAIL;
result.responseMessage = ex.getMessage(); | result.responseCode = (ex instanceof BusinessException) ? ((BusinessException) ex).getCode() |
7upcat/agile-wroking-backend | src/test/java/org/catframework/agileworking/service/impl/WeChatApiIntegrationTest.java | // Path: src/main/java/org/catframework/agileworking/utils/JsonUtils.java
// public final class JsonUtils {
//
// @SuppressWarnings("unchecked")
// public static final Map<String, Object> decode(String jsonString) {
// ObjectMapper mapper = new ObjectMapper();
// try {
// return mapper.readValue(jsonString, Map.class);
// } catch (IOException e) {
// throw new RuntimeException("JSON解析失败", e);
// }
// }
// }
| import java.util.HashMap;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.catframework.agileworking.utils.JsonUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.client.RestTemplate; | package org.catframework.agileworking.service.impl;
/**
* 集成测试验证,需要提供 form_id 才可以进行测试.
* @author devzzm
*/
@RunWith(SpringRunner.class)
@SpringBootTest
public class WeChatApiIntegrationTest {
private static final Log logger = LogFactory.getLog(WeChatApiIntegrationTest.class);
@Value("${wechat.app-id}")
private String appId;
@Value("${wechat.app-secret}")
private String appSecret;
@Value("${wechat.notify.template-id}")
private String templateId;
private String accessToken;
private RestTemplate restTemplate = new RestTemplate();
@Before
public void init() {
String result = restTemplate.getForObject(
"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={appId}&secret={appSecret}",
String.class, appId, appSecret); | // Path: src/main/java/org/catframework/agileworking/utils/JsonUtils.java
// public final class JsonUtils {
//
// @SuppressWarnings("unchecked")
// public static final Map<String, Object> decode(String jsonString) {
// ObjectMapper mapper = new ObjectMapper();
// try {
// return mapper.readValue(jsonString, Map.class);
// } catch (IOException e) {
// throw new RuntimeException("JSON解析失败", e);
// }
// }
// }
// Path: src/test/java/org/catframework/agileworking/service/impl/WeChatApiIntegrationTest.java
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.catframework.agileworking.utils.JsonUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.client.RestTemplate;
package org.catframework.agileworking.service.impl;
/**
* 集成测试验证,需要提供 form_id 才可以进行测试.
* @author devzzm
*/
@RunWith(SpringRunner.class)
@SpringBootTest
public class WeChatApiIntegrationTest {
private static final Log logger = LogFactory.getLog(WeChatApiIntegrationTest.class);
@Value("${wechat.app-id}")
private String appId;
@Value("${wechat.app-secret}")
private String appSecret;
@Value("${wechat.notify.template-id}")
private String templateId;
private String accessToken;
private RestTemplate restTemplate = new RestTemplate();
@Before
public void init() {
String result = restTemplate.getForObject(
"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={appId}&secret={appSecret}",
String.class, appId, appSecret); | accessToken = (String) JsonUtils.decode(result).get("access_token"); |
7upcat/agile-wroking-backend | src/main/java/org/catframework/agileworking/web/support/GlobalExceptionHandler.java | // Path: src/main/java/org/catframework/agileworking/BusinessException.java
// public class BusinessException extends RuntimeException {
//
// private static final long serialVersionUID = 3999713779564898790L;
//
// private String code;
//
// public BusinessException(String code) {
// this.code = code;
// }
//
// public BusinessException(String code, String message) {
// super(message);
// this.code = code;
// }
//
// public BusinessException(String code, String message, Throwable cause) {
// super(message, cause);
// this.code = code;
// }
//
// public String getCode() {
// return code;
// }
//
// }
| import javax.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.catframework.agileworking.BusinessException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody; | package org.catframework.agileworking.web.support;
/**
* 全局异常处理器,统一将异常转换为 {@link Result}.
*
* @author devzzm
*/
@ControllerAdvice
public class GlobalExceptionHandler {
private static final Log logger = LogFactory.getLog(GlobalExceptionHandler.class);
| // Path: src/main/java/org/catframework/agileworking/BusinessException.java
// public class BusinessException extends RuntimeException {
//
// private static final long serialVersionUID = 3999713779564898790L;
//
// private String code;
//
// public BusinessException(String code) {
// this.code = code;
// }
//
// public BusinessException(String code, String message) {
// super(message);
// this.code = code;
// }
//
// public BusinessException(String code, String message, Throwable cause) {
// super(message, cause);
// this.code = code;
// }
//
// public String getCode() {
// return code;
// }
//
// }
// Path: src/main/java/org/catframework/agileworking/web/support/GlobalExceptionHandler.java
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.catframework.agileworking.BusinessException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
package org.catframework.agileworking.web.support;
/**
* 全局异常处理器,统一将异常转换为 {@link Result}.
*
* @author devzzm
*/
@ControllerAdvice
public class GlobalExceptionHandler {
private static final Log logger = LogFactory.getLog(GlobalExceptionHandler.class);
| @ExceptionHandler({ BusinessException.class, Exception.class }) |
7upcat/agile-wroking-backend | src/main/java/org/catframework/agileworking/web/support/WebTokenHandlerInterceptor.java | // Path: src/main/java/org/catframework/agileworking/service/WebTokenService.java
// public interface WebTokenService {
//
// /**
// * 使用指定的主题生成 token
// *
// * @param subject 指定的信息
// * @return 生成的 token
// */
// String generate(String subject);
//
// /**
// * 校验指定的主题的 token 是否福匹配
// *
// * @param token 被校验的 token
// * @return 当校验成功时返回 <code>true</code>
// */
// boolean verify(String subject, String token);
// }
| import java.util.Arrays;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.catframework.agileworking.service.WebTokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.Assert;
import org.springframework.util.PathMatcher;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView; | package org.catframework.agileworking.web.support;
/**
* 自定义拦截器实现了 WebToken 的校验.
*
* @author devzzm
*/
public class WebTokenHandlerInterceptor implements HandlerInterceptor {
@Autowired | // Path: src/main/java/org/catframework/agileworking/service/WebTokenService.java
// public interface WebTokenService {
//
// /**
// * 使用指定的主题生成 token
// *
// * @param subject 指定的信息
// * @return 生成的 token
// */
// String generate(String subject);
//
// /**
// * 校验指定的主题的 token 是否福匹配
// *
// * @param token 被校验的 token
// * @return 当校验成功时返回 <code>true</code>
// */
// boolean verify(String subject, String token);
// }
// Path: src/main/java/org/catframework/agileworking/web/support/WebTokenHandlerInterceptor.java
import java.util.Arrays;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.catframework.agileworking.service.WebTokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.Assert;
import org.springframework.util.PathMatcher;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
package org.catframework.agileworking.web.support;
/**
* 自定义拦截器实现了 WebToken 的校验.
*
* @author devzzm
*/
public class WebTokenHandlerInterceptor implements HandlerInterceptor {
@Autowired | private WebTokenService webTokenService; |
7upcat/agile-wroking-backend | src/test/java/org/catframework/agileworking/web/MeetingRoomControllerIntegrationTest.java | // Path: src/test/java/org/catframework/agileworking/domain/ScheduleFactory.java
// public final class ScheduleFactory {
//
// public static final String DEFAULT_CREATOR_AVATAR_URL = "http://baidu.com";
//
// public static Schedule newSchedule(String title, String creator, String date, String startTime, String endTime) {
// Schedule s = new Schedule();
// s.setTitle(title);
// s.setCreatorNickName(creator);
// s.setCreatorOpenId(creator);
// s.setCreatorAvatarUrl(ScheduleFactory.DEFAULT_CREATOR_AVATAR_URL);
// s.setDate(DateUtils.parse(date, DateUtils.PATTERN_SIMPLE_DATE));
// s.setStartTime(startTime);
// s.setEndTime(endTime);
// s.setRepeatMode(Schedule.REPEAT_MODE_NO);
// return s;
// }
//
// public static Schedule newWeeklySchedule(String title, String creator, String date, String startTime,
// String endTime) {
// Schedule s = newSchedule(title, creator, date, startTime, endTime);
// s.setRepeatMode(Schedule.REPEAT_MODE_WEEKLY);
// return s;
// }
//
// }
| import org.catframework.agileworking.domain.ScheduleFactory;
import org.junit.Test;
import org.springframework.web.client.RestTemplate; | package org.catframework.agileworking.web;
public class MeetingRoomControllerIntegrationTest {
private String url = "http://localhost:8080";
@Test
public void schedules() {
RestTemplate restTemplate= new RestTemplate(); | // Path: src/test/java/org/catframework/agileworking/domain/ScheduleFactory.java
// public final class ScheduleFactory {
//
// public static final String DEFAULT_CREATOR_AVATAR_URL = "http://baidu.com";
//
// public static Schedule newSchedule(String title, String creator, String date, String startTime, String endTime) {
// Schedule s = new Schedule();
// s.setTitle(title);
// s.setCreatorNickName(creator);
// s.setCreatorOpenId(creator);
// s.setCreatorAvatarUrl(ScheduleFactory.DEFAULT_CREATOR_AVATAR_URL);
// s.setDate(DateUtils.parse(date, DateUtils.PATTERN_SIMPLE_DATE));
// s.setStartTime(startTime);
// s.setEndTime(endTime);
// s.setRepeatMode(Schedule.REPEAT_MODE_NO);
// return s;
// }
//
// public static Schedule newWeeklySchedule(String title, String creator, String date, String startTime,
// String endTime) {
// Schedule s = newSchedule(title, creator, date, startTime, endTime);
// s.setRepeatMode(Schedule.REPEAT_MODE_WEEKLY);
// return s;
// }
//
// }
// Path: src/test/java/org/catframework/agileworking/web/MeetingRoomControllerIntegrationTest.java
import org.catframework.agileworking.domain.ScheduleFactory;
import org.junit.Test;
import org.springframework.web.client.RestTemplate;
package org.catframework.agileworking.web;
public class MeetingRoomControllerIntegrationTest {
private String url = "http://localhost:8080";
@Test
public void schedules() {
RestTemplate restTemplate= new RestTemplate(); | restTemplate.postForObject(url+"/meetingRooms/{id}/schedule", ScheduleFactory.newSchedule("测试排期", "7upcat", "2017-02-02", "12:00", "16:00"), String.class,"1"); |
7upcat/agile-wroking-backend | src/test/java/org/catframework/agileworking/domain/ScheduleFactory.java | // Path: src/main/java/org/catframework/agileworking/utils/DateUtils.java
// public final class DateUtils {
//
// /** 简单的日期格式: yyyy-MM-dd */
// public static final String PATTERN_SIMPLE_DATE = "yyyy-MM-dd";
//
// public static final Date parse(String source, String pattern) {
// try {
// return new SimpleDateFormat(pattern).parse(source);
// } catch (ParseException e) {
// throw new RuntimeException(e);
// }
// }
//
// public static final String format(Date date, String pattern) {
// return new SimpleDateFormat(pattern).format(date);
// }
//
// /**
// * 判断指定的两个日期的所属的星期是否相同.
// *
// * @return 当两个日期相同时返回 <code>true</code>
// */
// public static boolean isSameWeekOfday(Date d1, Date d2) {
// Calendar d1Cal = Calendar.getInstance();
// d1Cal.setTime(d1);
// Calendar d2Cal = Calendar.getInstance();
// d2Cal.setTime(d2);
// return d1Cal.get(Calendar.DAY_OF_WEEK) == d2Cal.get(Calendar.DAY_OF_WEEK);
// }
//
// }
| import org.catframework.agileworking.utils.DateUtils; | package org.catframework.agileworking.domain;
public final class ScheduleFactory {
public static final String DEFAULT_CREATOR_AVATAR_URL = "http://baidu.com";
public static Schedule newSchedule(String title, String creator, String date, String startTime, String endTime) {
Schedule s = new Schedule();
s.setTitle(title);
s.setCreatorNickName(creator);
s.setCreatorOpenId(creator);
s.setCreatorAvatarUrl(ScheduleFactory.DEFAULT_CREATOR_AVATAR_URL); | // Path: src/main/java/org/catframework/agileworking/utils/DateUtils.java
// public final class DateUtils {
//
// /** 简单的日期格式: yyyy-MM-dd */
// public static final String PATTERN_SIMPLE_DATE = "yyyy-MM-dd";
//
// public static final Date parse(String source, String pattern) {
// try {
// return new SimpleDateFormat(pattern).parse(source);
// } catch (ParseException e) {
// throw new RuntimeException(e);
// }
// }
//
// public static final String format(Date date, String pattern) {
// return new SimpleDateFormat(pattern).format(date);
// }
//
// /**
// * 判断指定的两个日期的所属的星期是否相同.
// *
// * @return 当两个日期相同时返回 <code>true</code>
// */
// public static boolean isSameWeekOfday(Date d1, Date d2) {
// Calendar d1Cal = Calendar.getInstance();
// d1Cal.setTime(d1);
// Calendar d2Cal = Calendar.getInstance();
// d2Cal.setTime(d2);
// return d1Cal.get(Calendar.DAY_OF_WEEK) == d2Cal.get(Calendar.DAY_OF_WEEK);
// }
//
// }
// Path: src/test/java/org/catframework/agileworking/domain/ScheduleFactory.java
import org.catframework.agileworking.utils.DateUtils;
package org.catframework.agileworking.domain;
public final class ScheduleFactory {
public static final String DEFAULT_CREATOR_AVATAR_URL = "http://baidu.com";
public static Schedule newSchedule(String title, String creator, String date, String startTime, String endTime) {
Schedule s = new Schedule();
s.setTitle(title);
s.setCreatorNickName(creator);
s.setCreatorOpenId(creator);
s.setCreatorAvatarUrl(ScheduleFactory.DEFAULT_CREATOR_AVATAR_URL); | s.setDate(DateUtils.parse(date, DateUtils.PATTERN_SIMPLE_DATE)); |
7upcat/agile-wroking-backend | src/main/java/org/catframework/agileworking/domain/ScheduleRepositoryImpl.java | // Path: src/main/java/org/catframework/agileworking/vo/ScheduleVO.java
// public class ScheduleVO implements Comparable<ScheduleVO> {
//
// private BigInteger scheduleId;
//
// private Date date;
//
// private BigInteger meetingRoomId;
//
// private String title;
//
// private String openId;
//
// private String roomNo;
//
// private String startTime;
//
// private String endTime;
//
// private String repeatMode;
//
// public BigInteger getScheduleId() {
// return scheduleId;
// }
//
// public void setScheduleId(BigInteger scheduleId) {
// this.scheduleId = scheduleId;
// }
//
// @JsonFormat(pattern = "yyyy-MM-dd")
// public Date getDate() {
// return date;
// }
//
// public void setDate(Date date) {
// this.date = date;
// }
//
// public BigInteger getMeetingRoomId() {
// return meetingRoomId;
// }
//
// public void setMeetingRoomId(BigInteger meetingRoomId) {
// this.meetingRoomId = meetingRoomId;
// }
//
// public String getTitle() {
// return title;
// }
//
// public void setTitle(String title) {
// this.title = title;
// }
//
// public String getOpenId() {
// return openId;
// }
//
// public void setOpenId(String openId) {
// this.openId = openId;
// }
//
// public String getRoomNo() {
// return roomNo;
// }
//
// public void setRoomNo(String roomNo) {
// this.roomNo = roomNo;
// }
//
// public String getStartTime() {
// return startTime;
// }
//
// public void setStartTime(String startTime) {
// this.startTime = startTime;
// }
//
// public String getEndTime() {
// return endTime;
// }
//
// public void setEndTime(String endTime) {
// this.endTime = endTime;
// }
//
// public String getRepeatMode() {
// return repeatMode;
// }
//
// public void setRepeatMode(String repeatMode) {
// this.repeatMode = repeatMode;
// }
//
// /**
// * 判断当前的排期值对象是否同指定的日期具有相同的星期属性且排期日期小于指定的日期. <br>
// * 此方法用于查询本人某一日的排期清单使用.
// *
// * @param date 指定日期
// * @return 当排期的日期同指定的日期的星期属性相同且日期小于指定的日期时返回 <code>true</code>
// */
// public boolean isNeedInclude(Date date) {
// if (getDate().equals(date)) {
// return true;
// }
// // 排除未来的排期
// if (getDate().compareTo(date) > 0) {
// return false;
// }
// return DateUtils.isSameWeekOfday(date, getDate());
// }
//
// @Override
// public int compareTo(ScheduleVO o) {
// int result = getStartTime().compareTo(o.getStartTime());
// if (result == 0) {
// return getRoomNo().compareTo(o.getRoomNo());
// }
// return result;
// }
// }
| import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import javax.persistence.EntityManager;
import javax.transaction.Transactional;
import org.catframework.agileworking.vo.ScheduleVO;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.transform.Transformers;
import org.springframework.beans.factory.annotation.Autowired; | package org.catframework.agileworking.domain;
public class ScheduleRepositoryImpl implements ScheduleRepositoryCustom {
@Autowired
private EntityManager entityManager;
/**
* 自定义 native query 查询 {@link ScheduleVO} ,略繁琐但是好像没有更好的办法.
*/
@Transactional
@Override | // Path: src/main/java/org/catframework/agileworking/vo/ScheduleVO.java
// public class ScheduleVO implements Comparable<ScheduleVO> {
//
// private BigInteger scheduleId;
//
// private Date date;
//
// private BigInteger meetingRoomId;
//
// private String title;
//
// private String openId;
//
// private String roomNo;
//
// private String startTime;
//
// private String endTime;
//
// private String repeatMode;
//
// public BigInteger getScheduleId() {
// return scheduleId;
// }
//
// public void setScheduleId(BigInteger scheduleId) {
// this.scheduleId = scheduleId;
// }
//
// @JsonFormat(pattern = "yyyy-MM-dd")
// public Date getDate() {
// return date;
// }
//
// public void setDate(Date date) {
// this.date = date;
// }
//
// public BigInteger getMeetingRoomId() {
// return meetingRoomId;
// }
//
// public void setMeetingRoomId(BigInteger meetingRoomId) {
// this.meetingRoomId = meetingRoomId;
// }
//
// public String getTitle() {
// return title;
// }
//
// public void setTitle(String title) {
// this.title = title;
// }
//
// public String getOpenId() {
// return openId;
// }
//
// public void setOpenId(String openId) {
// this.openId = openId;
// }
//
// public String getRoomNo() {
// return roomNo;
// }
//
// public void setRoomNo(String roomNo) {
// this.roomNo = roomNo;
// }
//
// public String getStartTime() {
// return startTime;
// }
//
// public void setStartTime(String startTime) {
// this.startTime = startTime;
// }
//
// public String getEndTime() {
// return endTime;
// }
//
// public void setEndTime(String endTime) {
// this.endTime = endTime;
// }
//
// public String getRepeatMode() {
// return repeatMode;
// }
//
// public void setRepeatMode(String repeatMode) {
// this.repeatMode = repeatMode;
// }
//
// /**
// * 判断当前的排期值对象是否同指定的日期具有相同的星期属性且排期日期小于指定的日期. <br>
// * 此方法用于查询本人某一日的排期清单使用.
// *
// * @param date 指定日期
// * @return 当排期的日期同指定的日期的星期属性相同且日期小于指定的日期时返回 <code>true</code>
// */
// public boolean isNeedInclude(Date date) {
// if (getDate().equals(date)) {
// return true;
// }
// // 排除未来的排期
// if (getDate().compareTo(date) > 0) {
// return false;
// }
// return DateUtils.isSameWeekOfday(date, getDate());
// }
//
// @Override
// public int compareTo(ScheduleVO o) {
// int result = getStartTime().compareTo(o.getStartTime());
// if (result == 0) {
// return getRoomNo().compareTo(o.getRoomNo());
// }
// return result;
// }
// }
// Path: src/main/java/org/catframework/agileworking/domain/ScheduleRepositoryImpl.java
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import javax.persistence.EntityManager;
import javax.transaction.Transactional;
import org.catframework.agileworking.vo.ScheduleVO;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.transform.Transformers;
import org.springframework.beans.factory.annotation.Autowired;
package org.catframework.agileworking.domain;
public class ScheduleRepositoryImpl implements ScheduleRepositoryCustom {
@Autowired
private EntityManager entityManager;
/**
* 自定义 native query 查询 {@link ScheduleVO} ,略繁琐但是好像没有更好的办法.
*/
@Transactional
@Override | public List<ScheduleVO> findByOpenIdAndDate(String openId, Date date) { |
7upcat/agile-wroking-backend | src/test/java/org/catframework/agileworking/web/WechatControllerIntegrationTest.java | // Path: src/main/java/org/catframework/agileworking/web/support/Result.java
// public interface Result<T> {
//
// /** 交易结果状态:成功. */
// public static final int STATUS_SUCCESS = 0;
//
// /** 交易结果状态:失败. */
// public static final int STATUS_FAIL = 1;
//
// /**
// * @return 此结果的状态
// * @see Result#STATUS_FAIL
// * @see Result#STATUS_SUCCESS
// */
// int getStatus();
//
// /**
// * @return 结果状态为 {@link Result#STATUS_SUCCESS} 返回 <code>true</code>
// */
// boolean isSuccess();
//
// /**
// * @return 响应码
// */
// String getResponseCode();
//
// /**
// * @return 响应消息
// */
// String getResponseMessage();
//
// /**
// * @return 消息所承载的数据
// */
// T getPayload();
//
// /**
// * @return 消息头承载的数据
// */
// Map<String, Object> getHeaders();
//
// /**
// * 向结果中添加 header
// *
// * @param key 添加 header 的 key
// * @param value 添加 header 的值
// * @return 当前结果对象
// */
// Result<T> setHeader(String key, Object value);
//
// /**
// * 取指定 key 的头的值
// *
// * @param key 取值的 key
// * @return header 的值
// */
// Object getHeader(String key);
// }
| import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.catframework.agileworking.web.support.Result;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner; | package org.catframework.agileworking.web;
/**
* 集成测试获取 openid ,需要指定 jsCode
* @author devzzm
*/
@RunWith(SpringRunner.class)
@SpringBootTest
public class WechatControllerIntegrationTest {
private static final Log logger = LogFactory.getLog(WechatControllerIntegrationTest.class);
@Autowired
private WechatController wechatController;
@Test
public void test() {
String jsCode = "someJsCode"; | // Path: src/main/java/org/catframework/agileworking/web/support/Result.java
// public interface Result<T> {
//
// /** 交易结果状态:成功. */
// public static final int STATUS_SUCCESS = 0;
//
// /** 交易结果状态:失败. */
// public static final int STATUS_FAIL = 1;
//
// /**
// * @return 此结果的状态
// * @see Result#STATUS_FAIL
// * @see Result#STATUS_SUCCESS
// */
// int getStatus();
//
// /**
// * @return 结果状态为 {@link Result#STATUS_SUCCESS} 返回 <code>true</code>
// */
// boolean isSuccess();
//
// /**
// * @return 响应码
// */
// String getResponseCode();
//
// /**
// * @return 响应消息
// */
// String getResponseMessage();
//
// /**
// * @return 消息所承载的数据
// */
// T getPayload();
//
// /**
// * @return 消息头承载的数据
// */
// Map<String, Object> getHeaders();
//
// /**
// * 向结果中添加 header
// *
// * @param key 添加 header 的 key
// * @param value 添加 header 的值
// * @return 当前结果对象
// */
// Result<T> setHeader(String key, Object value);
//
// /**
// * 取指定 key 的头的值
// *
// * @param key 取值的 key
// * @return header 的值
// */
// Object getHeader(String key);
// }
// Path: src/test/java/org/catframework/agileworking/web/WechatControllerIntegrationTest.java
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.catframework.agileworking.web.support.Result;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
package org.catframework.agileworking.web;
/**
* 集成测试获取 openid ,需要指定 jsCode
* @author devzzm
*/
@RunWith(SpringRunner.class)
@SpringBootTest
public class WechatControllerIntegrationTest {
private static final Log logger = LogFactory.getLog(WechatControllerIntegrationTest.class);
@Autowired
private WechatController wechatController;
@Test
public void test() {
String jsCode = "someJsCode"; | Result<String> result = wechatController.getOpenId(jsCode); |
7upcat/agile-wroking-backend | src/main/java/org/catframework/agileworking/Application.java | // Path: src/main/java/org/catframework/agileworking/web/support/WebTokenHandlerInterceptor.java
// public class WebTokenHandlerInterceptor implements HandlerInterceptor {
//
// @Autowired
// private WebTokenService webTokenService;
//
// private String[] ignoreUriPatterns;
//
// private PathMatcher pathMatcher = new AntPathMatcher();
//
// private String tokenKey = "Authorization";
//
// private String subjectKey = "Subject";
//
// @Override
// public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object handler) throws Exception {
// if (isIgnoreUri(req.getRequestURI())) {
// return true;
// } else {
// String token = req.getHeader(tokenKey);
// Assert.notNull(token, "Authorization 不可为空.");
// String subject = req.getHeader(subjectKey);
// Assert.notNull(subject, "Subject 不可为空.");
// Assert.isTrue(webTokenService.verify(subject, token), "Web Token 校验失败.");
// return true;
// }
// }
//
// private boolean isIgnoreUri(String uri) {
// if (null == ignoreUriPatterns)
// return false;
// return Arrays.asList(ignoreUriPatterns).stream().anyMatch(p -> pathMatcher.match(p, uri));
// }
//
// @Override
// public void afterCompletion(HttpServletRequest req, HttpServletResponse resp, Object handler, Exception e)
// throws Exception {
// // do nothing
// }
//
// @Override
// public void postHandle(HttpServletRequest req, HttpServletResponse resp, Object handler, ModelAndView m)
// throws Exception {
// // do nothing
// }
//
// public void setWebTokenService(WebTokenService webTokenService) {
// this.webTokenService = webTokenService;
// }
//
// @Value("${web.token.ignore.uri.pattern}")
// public void setIgnoreUripattern(String ignoreUripattern) {
// if (!StringUtils.isEmpty(ignoreUripattern))
// ignoreUriPatterns = StringUtils.tokenizeToStringArray(ignoreUripattern, ",");
// }
// }
| import javax.sql.DataSource;
import org.apache.tomcat.jdbc.pool.PoolProperties;
import org.catframework.agileworking.web.support.WebTokenHandlerInterceptor;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; | package org.catframework.agileworking;
@SpringBootApplication
@EnableScheduling
public class Application extends WebMvcConfigurerAdapter {
@Bean
public DataSource dataSource() {
return new org.apache.tomcat.jdbc.pool.DataSource(poolProperties());
}
@Bean
@ConfigurationProperties(prefix = "spring.datasource")
public PoolProperties poolProperties() {
return new PoolProperties();
}
@Bean | // Path: src/main/java/org/catframework/agileworking/web/support/WebTokenHandlerInterceptor.java
// public class WebTokenHandlerInterceptor implements HandlerInterceptor {
//
// @Autowired
// private WebTokenService webTokenService;
//
// private String[] ignoreUriPatterns;
//
// private PathMatcher pathMatcher = new AntPathMatcher();
//
// private String tokenKey = "Authorization";
//
// private String subjectKey = "Subject";
//
// @Override
// public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object handler) throws Exception {
// if (isIgnoreUri(req.getRequestURI())) {
// return true;
// } else {
// String token = req.getHeader(tokenKey);
// Assert.notNull(token, "Authorization 不可为空.");
// String subject = req.getHeader(subjectKey);
// Assert.notNull(subject, "Subject 不可为空.");
// Assert.isTrue(webTokenService.verify(subject, token), "Web Token 校验失败.");
// return true;
// }
// }
//
// private boolean isIgnoreUri(String uri) {
// if (null == ignoreUriPatterns)
// return false;
// return Arrays.asList(ignoreUriPatterns).stream().anyMatch(p -> pathMatcher.match(p, uri));
// }
//
// @Override
// public void afterCompletion(HttpServletRequest req, HttpServletResponse resp, Object handler, Exception e)
// throws Exception {
// // do nothing
// }
//
// @Override
// public void postHandle(HttpServletRequest req, HttpServletResponse resp, Object handler, ModelAndView m)
// throws Exception {
// // do nothing
// }
//
// public void setWebTokenService(WebTokenService webTokenService) {
// this.webTokenService = webTokenService;
// }
//
// @Value("${web.token.ignore.uri.pattern}")
// public void setIgnoreUripattern(String ignoreUripattern) {
// if (!StringUtils.isEmpty(ignoreUripattern))
// ignoreUriPatterns = StringUtils.tokenizeToStringArray(ignoreUripattern, ",");
// }
// }
// Path: src/main/java/org/catframework/agileworking/Application.java
import javax.sql.DataSource;
import org.apache.tomcat.jdbc.pool.PoolProperties;
import org.catframework.agileworking.web.support.WebTokenHandlerInterceptor;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
package org.catframework.agileworking;
@SpringBootApplication
@EnableScheduling
public class Application extends WebMvcConfigurerAdapter {
@Bean
public DataSource dataSource() {
return new org.apache.tomcat.jdbc.pool.DataSource(poolProperties());
}
@Bean
@ConfigurationProperties(prefix = "spring.datasource")
public PoolProperties poolProperties() {
return new PoolProperties();
}
@Bean | WebTokenHandlerInterceptor webTokenHandlerInterceptor() { |
DNSBelgium/rdap-server-sample-gtld | src/main/java/be/dnsbelgium/rdap/sample/parser/WhoisKeyBlock.java | // Path: src/main/java/be/dnsbelgium/rdap/sample/dto/Contact.java
// public class Contact {
// public String id;
//
// // @Length(min = 0, max = 255)
// public String name;
//
// // @Length(min = 0, max = 255)
// public String organization;
//
//
// // @NotNull
// // @Valid
// public Address address = new Address();
//
// // @Length(min = 0, max = 255)
// public String phone;
//
// // @Length(min = 0, max = 255)
// public String phoneExt;
//
// // @Length(min = 0, max = 255)
// public String fax;
//
// // @Length(min = 0, max = 255)
// public String faxExt;
//
// // @Length(min = 0, max = 255)
// public String email;
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/dto/DnsSecKey.java
// public class DnsSecKey {
// public String dsKeyTag;
// public String algorithm;
// public String digest;
// public String digestType;
//
// public DnsSecKey() {
// }
//
// public DnsSecKey(String dsKeyTag, String algorithm, String digest, String digestType) {
// this.dsKeyTag = dsKeyTag;
// this.algorithm = algorithm;
// this.digest = digest;
// this.digestType = digestType;
// }
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/dto/SimpleContact.java
// public class SimpleContact {
// // @Length(min = 0, max = 255)
// public String name;
//
// // @Length(min = 0, max = 255)
// public String phone;
//
// // @Length(min = 0, max = 255)
// public String fax;
//
// // @Length(min = 0, max = 255)
// public String email;
// }
| import be.dnsbelgium.rdap.sample.dto.Contact;
import be.dnsbelgium.rdap.sample.dto.DnsSecKey;
import be.dnsbelgium.rdap.sample.dto.SimpleContact; | package be.dnsbelgium.rdap.sample.parser;
public enum WhoisKeyBlock {
MAIN(),
DOMAIN(),
REGISTRAR(),
REGISTRANT(), | // Path: src/main/java/be/dnsbelgium/rdap/sample/dto/Contact.java
// public class Contact {
// public String id;
//
// // @Length(min = 0, max = 255)
// public String name;
//
// // @Length(min = 0, max = 255)
// public String organization;
//
//
// // @NotNull
// // @Valid
// public Address address = new Address();
//
// // @Length(min = 0, max = 255)
// public String phone;
//
// // @Length(min = 0, max = 255)
// public String phoneExt;
//
// // @Length(min = 0, max = 255)
// public String fax;
//
// // @Length(min = 0, max = 255)
// public String faxExt;
//
// // @Length(min = 0, max = 255)
// public String email;
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/dto/DnsSecKey.java
// public class DnsSecKey {
// public String dsKeyTag;
// public String algorithm;
// public String digest;
// public String digestType;
//
// public DnsSecKey() {
// }
//
// public DnsSecKey(String dsKeyTag, String algorithm, String digest, String digestType) {
// this.dsKeyTag = dsKeyTag;
// this.algorithm = algorithm;
// this.digest = digest;
// this.digestType = digestType;
// }
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/dto/SimpleContact.java
// public class SimpleContact {
// // @Length(min = 0, max = 255)
// public String name;
//
// // @Length(min = 0, max = 255)
// public String phone;
//
// // @Length(min = 0, max = 255)
// public String fax;
//
// // @Length(min = 0, max = 255)
// public String email;
// }
// Path: src/main/java/be/dnsbelgium/rdap/sample/parser/WhoisKeyBlock.java
import be.dnsbelgium.rdap.sample.dto.Contact;
import be.dnsbelgium.rdap.sample.dto.DnsSecKey;
import be.dnsbelgium.rdap.sample.dto.SimpleContact;
package be.dnsbelgium.rdap.sample.parser;
public enum WhoisKeyBlock {
MAIN(),
DOMAIN(),
REGISTRAR(),
REGISTRANT(), | ADMIN(Contact.class), |
DNSBelgium/rdap-server-sample-gtld | src/main/java/be/dnsbelgium/rdap/sample/parser/WhoisKeyBlock.java | // Path: src/main/java/be/dnsbelgium/rdap/sample/dto/Contact.java
// public class Contact {
// public String id;
//
// // @Length(min = 0, max = 255)
// public String name;
//
// // @Length(min = 0, max = 255)
// public String organization;
//
//
// // @NotNull
// // @Valid
// public Address address = new Address();
//
// // @Length(min = 0, max = 255)
// public String phone;
//
// // @Length(min = 0, max = 255)
// public String phoneExt;
//
// // @Length(min = 0, max = 255)
// public String fax;
//
// // @Length(min = 0, max = 255)
// public String faxExt;
//
// // @Length(min = 0, max = 255)
// public String email;
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/dto/DnsSecKey.java
// public class DnsSecKey {
// public String dsKeyTag;
// public String algorithm;
// public String digest;
// public String digestType;
//
// public DnsSecKey() {
// }
//
// public DnsSecKey(String dsKeyTag, String algorithm, String digest, String digestType) {
// this.dsKeyTag = dsKeyTag;
// this.algorithm = algorithm;
// this.digest = digest;
// this.digestType = digestType;
// }
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/dto/SimpleContact.java
// public class SimpleContact {
// // @Length(min = 0, max = 255)
// public String name;
//
// // @Length(min = 0, max = 255)
// public String phone;
//
// // @Length(min = 0, max = 255)
// public String fax;
//
// // @Length(min = 0, max = 255)
// public String email;
// }
| import be.dnsbelgium.rdap.sample.dto.Contact;
import be.dnsbelgium.rdap.sample.dto.DnsSecKey;
import be.dnsbelgium.rdap.sample.dto.SimpleContact; | package be.dnsbelgium.rdap.sample.parser;
public enum WhoisKeyBlock {
MAIN(),
DOMAIN(),
REGISTRAR(),
REGISTRANT(),
ADMIN(Contact.class),
TECH(Contact.class),
DNSSEC(), | // Path: src/main/java/be/dnsbelgium/rdap/sample/dto/Contact.java
// public class Contact {
// public String id;
//
// // @Length(min = 0, max = 255)
// public String name;
//
// // @Length(min = 0, max = 255)
// public String organization;
//
//
// // @NotNull
// // @Valid
// public Address address = new Address();
//
// // @Length(min = 0, max = 255)
// public String phone;
//
// // @Length(min = 0, max = 255)
// public String phoneExt;
//
// // @Length(min = 0, max = 255)
// public String fax;
//
// // @Length(min = 0, max = 255)
// public String faxExt;
//
// // @Length(min = 0, max = 255)
// public String email;
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/dto/DnsSecKey.java
// public class DnsSecKey {
// public String dsKeyTag;
// public String algorithm;
// public String digest;
// public String digestType;
//
// public DnsSecKey() {
// }
//
// public DnsSecKey(String dsKeyTag, String algorithm, String digest, String digestType) {
// this.dsKeyTag = dsKeyTag;
// this.algorithm = algorithm;
// this.digest = digest;
// this.digestType = digestType;
// }
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/dto/SimpleContact.java
// public class SimpleContact {
// // @Length(min = 0, max = 255)
// public String name;
//
// // @Length(min = 0, max = 255)
// public String phone;
//
// // @Length(min = 0, max = 255)
// public String fax;
//
// // @Length(min = 0, max = 255)
// public String email;
// }
// Path: src/main/java/be/dnsbelgium/rdap/sample/parser/WhoisKeyBlock.java
import be.dnsbelgium.rdap.sample.dto.Contact;
import be.dnsbelgium.rdap.sample.dto.DnsSecKey;
import be.dnsbelgium.rdap.sample.dto.SimpleContact;
package be.dnsbelgium.rdap.sample.parser;
public enum WhoisKeyBlock {
MAIN(),
DOMAIN(),
REGISTRAR(),
REGISTRANT(),
ADMIN(Contact.class),
TECH(Contact.class),
DNSSEC(), | DNSSECKEY(DnsSecKey.class, true), |
DNSBelgium/rdap-server-sample-gtld | src/main/java/be/dnsbelgium/rdap/sample/parser/WhoisKeyBlock.java | // Path: src/main/java/be/dnsbelgium/rdap/sample/dto/Contact.java
// public class Contact {
// public String id;
//
// // @Length(min = 0, max = 255)
// public String name;
//
// // @Length(min = 0, max = 255)
// public String organization;
//
//
// // @NotNull
// // @Valid
// public Address address = new Address();
//
// // @Length(min = 0, max = 255)
// public String phone;
//
// // @Length(min = 0, max = 255)
// public String phoneExt;
//
// // @Length(min = 0, max = 255)
// public String fax;
//
// // @Length(min = 0, max = 255)
// public String faxExt;
//
// // @Length(min = 0, max = 255)
// public String email;
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/dto/DnsSecKey.java
// public class DnsSecKey {
// public String dsKeyTag;
// public String algorithm;
// public String digest;
// public String digestType;
//
// public DnsSecKey() {
// }
//
// public DnsSecKey(String dsKeyTag, String algorithm, String digest, String digestType) {
// this.dsKeyTag = dsKeyTag;
// this.algorithm = algorithm;
// this.digest = digest;
// this.digestType = digestType;
// }
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/dto/SimpleContact.java
// public class SimpleContact {
// // @Length(min = 0, max = 255)
// public String name;
//
// // @Length(min = 0, max = 255)
// public String phone;
//
// // @Length(min = 0, max = 255)
// public String fax;
//
// // @Length(min = 0, max = 255)
// public String email;
// }
| import be.dnsbelgium.rdap.sample.dto.Contact;
import be.dnsbelgium.rdap.sample.dto.DnsSecKey;
import be.dnsbelgium.rdap.sample.dto.SimpleContact; | package be.dnsbelgium.rdap.sample.parser;
public enum WhoisKeyBlock {
MAIN(),
DOMAIN(),
REGISTRAR(),
REGISTRANT(),
ADMIN(Contact.class),
TECH(Contact.class),
DNSSEC(),
DNSSECKEY(DnsSecKey.class, true),
HOST(), | // Path: src/main/java/be/dnsbelgium/rdap/sample/dto/Contact.java
// public class Contact {
// public String id;
//
// // @Length(min = 0, max = 255)
// public String name;
//
// // @Length(min = 0, max = 255)
// public String organization;
//
//
// // @NotNull
// // @Valid
// public Address address = new Address();
//
// // @Length(min = 0, max = 255)
// public String phone;
//
// // @Length(min = 0, max = 255)
// public String phoneExt;
//
// // @Length(min = 0, max = 255)
// public String fax;
//
// // @Length(min = 0, max = 255)
// public String faxExt;
//
// // @Length(min = 0, max = 255)
// public String email;
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/dto/DnsSecKey.java
// public class DnsSecKey {
// public String dsKeyTag;
// public String algorithm;
// public String digest;
// public String digestType;
//
// public DnsSecKey() {
// }
//
// public DnsSecKey(String dsKeyTag, String algorithm, String digest, String digestType) {
// this.dsKeyTag = dsKeyTag;
// this.algorithm = algorithm;
// this.digest = digest;
// this.digestType = digestType;
// }
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/dto/SimpleContact.java
// public class SimpleContact {
// // @Length(min = 0, max = 255)
// public String name;
//
// // @Length(min = 0, max = 255)
// public String phone;
//
// // @Length(min = 0, max = 255)
// public String fax;
//
// // @Length(min = 0, max = 255)
// public String email;
// }
// Path: src/main/java/be/dnsbelgium/rdap/sample/parser/WhoisKeyBlock.java
import be.dnsbelgium.rdap.sample.dto.Contact;
import be.dnsbelgium.rdap.sample.dto.DnsSecKey;
import be.dnsbelgium.rdap.sample.dto.SimpleContact;
package be.dnsbelgium.rdap.sample.parser;
public enum WhoisKeyBlock {
MAIN(),
DOMAIN(),
REGISTRAR(),
REGISTRANT(),
ADMIN(Contact.class),
TECH(Contact.class),
DNSSEC(),
DNSSECKEY(DnsSecKey.class, true),
HOST(), | SIMPLE_ADMIN(SimpleContact.class), |
DNSBelgium/rdap-server-sample-gtld | src/main/java/be/dnsbelgium/rdap/sample/parser/WhoisEntry.java | // Path: src/main/java/be/dnsbelgium/rdap/sample/parser/fieldparser/FieldParser.java
// public interface FieldParser<T> {
// public T parse(String value);
// }
| import be.dnsbelgium.rdap.sample.parser.fieldparser.FieldParser; | package be.dnsbelgium.rdap.sample.parser;
public class WhoisEntry {
private WhoisKeyBlock block;
private boolean firstBlockItem = false;
private String key;
private String path;
private boolean itemRepeatable; | // Path: src/main/java/be/dnsbelgium/rdap/sample/parser/fieldparser/FieldParser.java
// public interface FieldParser<T> {
// public T parse(String value);
// }
// Path: src/main/java/be/dnsbelgium/rdap/sample/parser/WhoisEntry.java
import be.dnsbelgium.rdap.sample.parser.fieldparser.FieldParser;
package be.dnsbelgium.rdap.sample.parser;
public class WhoisEntry {
private WhoisKeyBlock block;
private boolean firstBlockItem = false;
private String key;
private String path;
private boolean itemRepeatable; | private FieldParser fieldParser; |
DNSBelgium/rdap-server-sample-gtld | src/main/java/be/dnsbelgium/rdap/sample/parser/AbstractWhoisParser.java | // Path: src/main/java/be/dnsbelgium/rdap/sample/parser/fieldparser/FieldParser.java
// public interface FieldParser<T> {
// public T parse(String value);
// }
| import be.dnsbelgium.rdap.sample.parser.fieldparser.FieldParser;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.apache.commons.lang3.reflect.MethodUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List; | for (String line : lines) {
try {
Pair<String, String> keyValue = splitLine(line);
if (keyValue != null) {
WhoisEntry entry = getParseLayout().getEntry(keyValue.getKey(), previousKeyBlock);
if (entry == null) {
logger.info("Skipping line! Cannot find a parser to parse line: [{}]", line);
} else {
Pair<Object, String> ofPair = getObjectFieldPair(instance, entry.getPath(), entry);
Object value = getFieldValue(keyValue.getValue(), entry.getFieldParser());
// If the item is repeatable -> check if we can access the public field
// -> if we can't use the addXxx() method
if (entry.isItemRepeatable()) {
addItemToCollection(ofPair.getKey(), ofPair.getValue(), value);
} else {
FieldUtils.writeField(ofPair.getKey(), ofPair.getValue(), value);
}
previousKeyBlock = entry.getBlock();
}
}
} catch (Exception e) {
logger.error("Skipping line! There was a problem while trying to parse the line: [{}]", line, e);
}
}
doAfterParsing(instance, data);
return instance;
}
| // Path: src/main/java/be/dnsbelgium/rdap/sample/parser/fieldparser/FieldParser.java
// public interface FieldParser<T> {
// public T parse(String value);
// }
// Path: src/main/java/be/dnsbelgium/rdap/sample/parser/AbstractWhoisParser.java
import be.dnsbelgium.rdap.sample.parser.fieldparser.FieldParser;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.apache.commons.lang3.reflect.MethodUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
for (String line : lines) {
try {
Pair<String, String> keyValue = splitLine(line);
if (keyValue != null) {
WhoisEntry entry = getParseLayout().getEntry(keyValue.getKey(), previousKeyBlock);
if (entry == null) {
logger.info("Skipping line! Cannot find a parser to parse line: [{}]", line);
} else {
Pair<Object, String> ofPair = getObjectFieldPair(instance, entry.getPath(), entry);
Object value = getFieldValue(keyValue.getValue(), entry.getFieldParser());
// If the item is repeatable -> check if we can access the public field
// -> if we can't use the addXxx() method
if (entry.isItemRepeatable()) {
addItemToCollection(ofPair.getKey(), ofPair.getValue(), value);
} else {
FieldUtils.writeField(ofPair.getKey(), ofPair.getValue(), value);
}
previousKeyBlock = entry.getBlock();
}
}
} catch (Exception e) {
logger.error("Skipping line! There was a problem while trying to parse the line: [{}]", line, e);
}
}
doAfterParsing(instance, data);
return instance;
}
| private Object getFieldValue(String value, FieldParser fieldParser) { |
DNSBelgium/rdap-server-sample-gtld | src/main/java/be/dnsbelgium/rdap/sample/parser/ParseLayout.java | // Path: src/main/java/be/dnsbelgium/rdap/sample/parser/fieldparser/FieldParser.java
// public interface FieldParser<T> {
// public T parse(String value);
// }
| import be.dnsbelgium.rdap.sample.parser.fieldparser.FieldParser;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern; | package be.dnsbelgium.rdap.sample.parser;
public class ParseLayout {
private static final Pattern INDEXED_FIELD_PATTERN = Pattern.compile("^(.+?)(\\d+)$");
private Map<String, Map<WhoisKeyBlock, WhoisEntry>> layout = new HashMap<>();
public void addEntry(WhoisKeyBlock block, String key, String path, boolean itemRepeatable) {
addEntry(new WhoisEntry(block, key, path, itemRepeatable));
}
public void addEntry(WhoisKeyBlock block, boolean firstBlockItem, String key, String path, boolean itemRepeatable) {
addEntry(new WhoisEntry(block, firstBlockItem, key, path, itemRepeatable));
}
| // Path: src/main/java/be/dnsbelgium/rdap/sample/parser/fieldparser/FieldParser.java
// public interface FieldParser<T> {
// public T parse(String value);
// }
// Path: src/main/java/be/dnsbelgium/rdap/sample/parser/ParseLayout.java
import be.dnsbelgium.rdap.sample.parser.fieldparser.FieldParser;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
package be.dnsbelgium.rdap.sample.parser;
public class ParseLayout {
private static final Pattern INDEXED_FIELD_PATTERN = Pattern.compile("^(.+?)(\\d+)$");
private Map<String, Map<WhoisKeyBlock, WhoisEntry>> layout = new HashMap<>();
public void addEntry(WhoisKeyBlock block, String key, String path, boolean itemRepeatable) {
addEntry(new WhoisEntry(block, key, path, itemRepeatable));
}
public void addEntry(WhoisKeyBlock block, boolean firstBlockItem, String key, String path, boolean itemRepeatable) {
addEntry(new WhoisEntry(block, firstBlockItem, key, path, itemRepeatable));
}
| public void addEntry(WhoisKeyBlock block, String key, String path, boolean itemRepeatable, FieldParser fieldParser) { |
DNSBelgium/rdap-server-sample-gtld | src/main/java/be/dnsbelgium/rdap/sample/parser/WhoisHostParser.java | // Path: src/main/java/be/dnsbelgium/rdap/sample/dto/WhoisHost.java
// public class WhoisHost {
// public String name;
// public List<IpAddress> ipAddressList = new ArrayList<>();
// public SimpleRegistar registrar = new SimpleRegistar();
//
// public void addIpAddress(IpAddress ipAddress) {
// ipAddressList.add(ipAddress);
// }
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/parser/fieldparser/IpAddressParser.java
// public class IpAddressParser implements FieldParser<IpAddress> {
// @Override
// public IpAddress parse(String value) {
// return IpAddress.parse(value);
// }
// }
| import be.dnsbelgium.rdap.sample.dto.WhoisHost;
import be.dnsbelgium.rdap.sample.parser.fieldparser.IpAddressParser; | package be.dnsbelgium.rdap.sample.parser;
public class WhoisHostParser extends AbstractWhoisParser<WhoisHost> {
private static ParseLayout parseLayout = new ParseLayout();
static {
parseLayout.addEntry(WhoisKeyBlock.HOST, true, "Server Name", "name", false); | // Path: src/main/java/be/dnsbelgium/rdap/sample/dto/WhoisHost.java
// public class WhoisHost {
// public String name;
// public List<IpAddress> ipAddressList = new ArrayList<>();
// public SimpleRegistar registrar = new SimpleRegistar();
//
// public void addIpAddress(IpAddress ipAddress) {
// ipAddressList.add(ipAddress);
// }
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/parser/fieldparser/IpAddressParser.java
// public class IpAddressParser implements FieldParser<IpAddress> {
// @Override
// public IpAddress parse(String value) {
// return IpAddress.parse(value);
// }
// }
// Path: src/main/java/be/dnsbelgium/rdap/sample/parser/WhoisHostParser.java
import be.dnsbelgium.rdap.sample.dto.WhoisHost;
import be.dnsbelgium.rdap.sample.parser.fieldparser.IpAddressParser;
package be.dnsbelgium.rdap.sample.parser;
public class WhoisHostParser extends AbstractWhoisParser<WhoisHost> {
private static ParseLayout parseLayout = new ParseLayout();
static {
parseLayout.addEntry(WhoisKeyBlock.HOST, true, "Server Name", "name", false); | parseLayout.addEntry(WhoisKeyBlock.HOST, "IP Address", "ipAddress", true, new IpAddressParser()); |
DNSBelgium/rdap-server-sample-gtld | src/main/java/be/dnsbelgium/rdap/sample/parser/WhoisDomainParser.java | // Path: src/main/java/be/dnsbelgium/rdap/sample/dto/DnsSecStatus.java
// public enum DnsSecStatus {
// SIGNED,
// UNSIGNED;
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/dto/WhoisDomain.java
// public class WhoisDomain {
// public String whoisServer;
// public String referralUrl;
// public Domain domain = new Domain();
// public SimpleRegistar sponsoringRegistrar = new SimpleRegistar();
//
// public Contact registrant = new Contact();
// public List<Contact> admin = new ArrayList<>();
// public List<Contact> tech = new ArrayList<>();
//
// public List<String> nameservers = new ArrayList<>();
//
// public DnsSec dnssec = new DnsSec();
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/parser/fieldparser/DateTimeFieldParser.java
// public class DateTimeFieldParser implements FieldParser<DateTime> {
// private DateTimeFormatter formatter;
//
// public DateTimeFieldParser() {
// }
//
// public DateTimeFieldParser(DateTimeFormatter formatter) {
// this.formatter = formatter;
// }
//
// @Override
// public DateTime parse(String value) {
// return (formatter != null) ? DateTime.parse(value, formatter) : DateTime.parse(value);
// }
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/parser/fieldparser/DomainStatusFieldParser.java
// public class DomainStatusFieldParser implements FieldParser<DomainStatus> {
// @Override
// public DomainStatus parse(String value) {
// // Strip of URL's (everything after a space)
// value = StringUtils.substringBefore(value, " ");
// // Replace the camelcase with underscores
// value = value.replaceAll("(.)(\\p{Upper})", "$1_$2");
// // and then uppercase it to find the status
// return DomainStatus.valueOf(StringUtils.upperCase(value));
// }
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/parser/fieldparser/EnumFieldParser.java
// public class EnumFieldParser<T extends Enum> implements FieldParser<T> {
//
// private Class<T> clazz;
//
// public EnumFieldParser(Class<T> clazz) {
// this.clazz = clazz;
// }
//
// @Override
// public T parse(String value) {
// return (T) Enum.valueOf(clazz, value.toUpperCase());
// }
// }
| import be.dnsbelgium.rdap.sample.dto.DnsSecStatus;
import be.dnsbelgium.rdap.sample.dto.WhoisDomain;
import be.dnsbelgium.rdap.sample.parser.fieldparser.DateTimeFieldParser;
import be.dnsbelgium.rdap.sample.parser.fieldparser.DomainStatusFieldParser;
import be.dnsbelgium.rdap.sample.parser.fieldparser.EnumFieldParser; | package be.dnsbelgium.rdap.sample.parser;
public class WhoisDomainParser extends AbstractWhoisParser<WhoisDomain> {
private static ParseLayout parseLayout = new ParseLayout();
static {
parseLayout.addEntry(WhoisKeyBlock.DOMAIN, true, "Domain ID", "domain.id", false);
parseLayout.addEntry(WhoisKeyBlock.DOMAIN, "Domain Name", "domain.name", false);
parseLayout.addEntry(WhoisKeyBlock.DOMAIN, "Domain U-Label", "domain.uLabel", false); | // Path: src/main/java/be/dnsbelgium/rdap/sample/dto/DnsSecStatus.java
// public enum DnsSecStatus {
// SIGNED,
// UNSIGNED;
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/dto/WhoisDomain.java
// public class WhoisDomain {
// public String whoisServer;
// public String referralUrl;
// public Domain domain = new Domain();
// public SimpleRegistar sponsoringRegistrar = new SimpleRegistar();
//
// public Contact registrant = new Contact();
// public List<Contact> admin = new ArrayList<>();
// public List<Contact> tech = new ArrayList<>();
//
// public List<String> nameservers = new ArrayList<>();
//
// public DnsSec dnssec = new DnsSec();
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/parser/fieldparser/DateTimeFieldParser.java
// public class DateTimeFieldParser implements FieldParser<DateTime> {
// private DateTimeFormatter formatter;
//
// public DateTimeFieldParser() {
// }
//
// public DateTimeFieldParser(DateTimeFormatter formatter) {
// this.formatter = formatter;
// }
//
// @Override
// public DateTime parse(String value) {
// return (formatter != null) ? DateTime.parse(value, formatter) : DateTime.parse(value);
// }
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/parser/fieldparser/DomainStatusFieldParser.java
// public class DomainStatusFieldParser implements FieldParser<DomainStatus> {
// @Override
// public DomainStatus parse(String value) {
// // Strip of URL's (everything after a space)
// value = StringUtils.substringBefore(value, " ");
// // Replace the camelcase with underscores
// value = value.replaceAll("(.)(\\p{Upper})", "$1_$2");
// // and then uppercase it to find the status
// return DomainStatus.valueOf(StringUtils.upperCase(value));
// }
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/parser/fieldparser/EnumFieldParser.java
// public class EnumFieldParser<T extends Enum> implements FieldParser<T> {
//
// private Class<T> clazz;
//
// public EnumFieldParser(Class<T> clazz) {
// this.clazz = clazz;
// }
//
// @Override
// public T parse(String value) {
// return (T) Enum.valueOf(clazz, value.toUpperCase());
// }
// }
// Path: src/main/java/be/dnsbelgium/rdap/sample/parser/WhoisDomainParser.java
import be.dnsbelgium.rdap.sample.dto.DnsSecStatus;
import be.dnsbelgium.rdap.sample.dto.WhoisDomain;
import be.dnsbelgium.rdap.sample.parser.fieldparser.DateTimeFieldParser;
import be.dnsbelgium.rdap.sample.parser.fieldparser.DomainStatusFieldParser;
import be.dnsbelgium.rdap.sample.parser.fieldparser.EnumFieldParser;
package be.dnsbelgium.rdap.sample.parser;
public class WhoisDomainParser extends AbstractWhoisParser<WhoisDomain> {
private static ParseLayout parseLayout = new ParseLayout();
static {
parseLayout.addEntry(WhoisKeyBlock.DOMAIN, true, "Domain ID", "domain.id", false);
parseLayout.addEntry(WhoisKeyBlock.DOMAIN, "Domain Name", "domain.name", false);
parseLayout.addEntry(WhoisKeyBlock.DOMAIN, "Domain U-Label", "domain.uLabel", false); | parseLayout.addEntry(WhoisKeyBlock.DOMAIN, "Creation Date", "domain.creationDate", false, new DateTimeFieldParser()); |
DNSBelgium/rdap-server-sample-gtld | src/main/java/be/dnsbelgium/rdap/sample/parser/WhoisDomainParser.java | // Path: src/main/java/be/dnsbelgium/rdap/sample/dto/DnsSecStatus.java
// public enum DnsSecStatus {
// SIGNED,
// UNSIGNED;
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/dto/WhoisDomain.java
// public class WhoisDomain {
// public String whoisServer;
// public String referralUrl;
// public Domain domain = new Domain();
// public SimpleRegistar sponsoringRegistrar = new SimpleRegistar();
//
// public Contact registrant = new Contact();
// public List<Contact> admin = new ArrayList<>();
// public List<Contact> tech = new ArrayList<>();
//
// public List<String> nameservers = new ArrayList<>();
//
// public DnsSec dnssec = new DnsSec();
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/parser/fieldparser/DateTimeFieldParser.java
// public class DateTimeFieldParser implements FieldParser<DateTime> {
// private DateTimeFormatter formatter;
//
// public DateTimeFieldParser() {
// }
//
// public DateTimeFieldParser(DateTimeFormatter formatter) {
// this.formatter = formatter;
// }
//
// @Override
// public DateTime parse(String value) {
// return (formatter != null) ? DateTime.parse(value, formatter) : DateTime.parse(value);
// }
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/parser/fieldparser/DomainStatusFieldParser.java
// public class DomainStatusFieldParser implements FieldParser<DomainStatus> {
// @Override
// public DomainStatus parse(String value) {
// // Strip of URL's (everything after a space)
// value = StringUtils.substringBefore(value, " ");
// // Replace the camelcase with underscores
// value = value.replaceAll("(.)(\\p{Upper})", "$1_$2");
// // and then uppercase it to find the status
// return DomainStatus.valueOf(StringUtils.upperCase(value));
// }
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/parser/fieldparser/EnumFieldParser.java
// public class EnumFieldParser<T extends Enum> implements FieldParser<T> {
//
// private Class<T> clazz;
//
// public EnumFieldParser(Class<T> clazz) {
// this.clazz = clazz;
// }
//
// @Override
// public T parse(String value) {
// return (T) Enum.valueOf(clazz, value.toUpperCase());
// }
// }
| import be.dnsbelgium.rdap.sample.dto.DnsSecStatus;
import be.dnsbelgium.rdap.sample.dto.WhoisDomain;
import be.dnsbelgium.rdap.sample.parser.fieldparser.DateTimeFieldParser;
import be.dnsbelgium.rdap.sample.parser.fieldparser.DomainStatusFieldParser;
import be.dnsbelgium.rdap.sample.parser.fieldparser.EnumFieldParser; | package be.dnsbelgium.rdap.sample.parser;
public class WhoisDomainParser extends AbstractWhoisParser<WhoisDomain> {
private static ParseLayout parseLayout = new ParseLayout();
static {
parseLayout.addEntry(WhoisKeyBlock.DOMAIN, true, "Domain ID", "domain.id", false);
parseLayout.addEntry(WhoisKeyBlock.DOMAIN, "Domain Name", "domain.name", false);
parseLayout.addEntry(WhoisKeyBlock.DOMAIN, "Domain U-Label", "domain.uLabel", false);
parseLayout.addEntry(WhoisKeyBlock.DOMAIN, "Creation Date", "domain.creationDate", false, new DateTimeFieldParser());
parseLayout.addEntry(WhoisKeyBlock.DOMAIN, "Registry Expiry Date", "domain.expiryDate", false, new DateTimeFieldParser());
parseLayout.addEntry(WhoisKeyBlock.DOMAIN, "Updated Date", "domain.updatedDate", false, new DateTimeFieldParser()); | // Path: src/main/java/be/dnsbelgium/rdap/sample/dto/DnsSecStatus.java
// public enum DnsSecStatus {
// SIGNED,
// UNSIGNED;
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/dto/WhoisDomain.java
// public class WhoisDomain {
// public String whoisServer;
// public String referralUrl;
// public Domain domain = new Domain();
// public SimpleRegistar sponsoringRegistrar = new SimpleRegistar();
//
// public Contact registrant = new Contact();
// public List<Contact> admin = new ArrayList<>();
// public List<Contact> tech = new ArrayList<>();
//
// public List<String> nameservers = new ArrayList<>();
//
// public DnsSec dnssec = new DnsSec();
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/parser/fieldparser/DateTimeFieldParser.java
// public class DateTimeFieldParser implements FieldParser<DateTime> {
// private DateTimeFormatter formatter;
//
// public DateTimeFieldParser() {
// }
//
// public DateTimeFieldParser(DateTimeFormatter formatter) {
// this.formatter = formatter;
// }
//
// @Override
// public DateTime parse(String value) {
// return (formatter != null) ? DateTime.parse(value, formatter) : DateTime.parse(value);
// }
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/parser/fieldparser/DomainStatusFieldParser.java
// public class DomainStatusFieldParser implements FieldParser<DomainStatus> {
// @Override
// public DomainStatus parse(String value) {
// // Strip of URL's (everything after a space)
// value = StringUtils.substringBefore(value, " ");
// // Replace the camelcase with underscores
// value = value.replaceAll("(.)(\\p{Upper})", "$1_$2");
// // and then uppercase it to find the status
// return DomainStatus.valueOf(StringUtils.upperCase(value));
// }
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/parser/fieldparser/EnumFieldParser.java
// public class EnumFieldParser<T extends Enum> implements FieldParser<T> {
//
// private Class<T> clazz;
//
// public EnumFieldParser(Class<T> clazz) {
// this.clazz = clazz;
// }
//
// @Override
// public T parse(String value) {
// return (T) Enum.valueOf(clazz, value.toUpperCase());
// }
// }
// Path: src/main/java/be/dnsbelgium/rdap/sample/parser/WhoisDomainParser.java
import be.dnsbelgium.rdap.sample.dto.DnsSecStatus;
import be.dnsbelgium.rdap.sample.dto.WhoisDomain;
import be.dnsbelgium.rdap.sample.parser.fieldparser.DateTimeFieldParser;
import be.dnsbelgium.rdap.sample.parser.fieldparser.DomainStatusFieldParser;
import be.dnsbelgium.rdap.sample.parser.fieldparser.EnumFieldParser;
package be.dnsbelgium.rdap.sample.parser;
public class WhoisDomainParser extends AbstractWhoisParser<WhoisDomain> {
private static ParseLayout parseLayout = new ParseLayout();
static {
parseLayout.addEntry(WhoisKeyBlock.DOMAIN, true, "Domain ID", "domain.id", false);
parseLayout.addEntry(WhoisKeyBlock.DOMAIN, "Domain Name", "domain.name", false);
parseLayout.addEntry(WhoisKeyBlock.DOMAIN, "Domain U-Label", "domain.uLabel", false);
parseLayout.addEntry(WhoisKeyBlock.DOMAIN, "Creation Date", "domain.creationDate", false, new DateTimeFieldParser());
parseLayout.addEntry(WhoisKeyBlock.DOMAIN, "Registry Expiry Date", "domain.expiryDate", false, new DateTimeFieldParser());
parseLayout.addEntry(WhoisKeyBlock.DOMAIN, "Updated Date", "domain.updatedDate", false, new DateTimeFieldParser()); | parseLayout.addEntry(WhoisKeyBlock.DOMAIN, "Domain Status", "domain.statusList", true, new DomainStatusFieldParser()); |
DNSBelgium/rdap-server-sample-gtld | src/main/java/be/dnsbelgium/rdap/sample/parser/WhoisDomainParser.java | // Path: src/main/java/be/dnsbelgium/rdap/sample/dto/DnsSecStatus.java
// public enum DnsSecStatus {
// SIGNED,
// UNSIGNED;
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/dto/WhoisDomain.java
// public class WhoisDomain {
// public String whoisServer;
// public String referralUrl;
// public Domain domain = new Domain();
// public SimpleRegistar sponsoringRegistrar = new SimpleRegistar();
//
// public Contact registrant = new Contact();
// public List<Contact> admin = new ArrayList<>();
// public List<Contact> tech = new ArrayList<>();
//
// public List<String> nameservers = new ArrayList<>();
//
// public DnsSec dnssec = new DnsSec();
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/parser/fieldparser/DateTimeFieldParser.java
// public class DateTimeFieldParser implements FieldParser<DateTime> {
// private DateTimeFormatter formatter;
//
// public DateTimeFieldParser() {
// }
//
// public DateTimeFieldParser(DateTimeFormatter formatter) {
// this.formatter = formatter;
// }
//
// @Override
// public DateTime parse(String value) {
// return (formatter != null) ? DateTime.parse(value, formatter) : DateTime.parse(value);
// }
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/parser/fieldparser/DomainStatusFieldParser.java
// public class DomainStatusFieldParser implements FieldParser<DomainStatus> {
// @Override
// public DomainStatus parse(String value) {
// // Strip of URL's (everything after a space)
// value = StringUtils.substringBefore(value, " ");
// // Replace the camelcase with underscores
// value = value.replaceAll("(.)(\\p{Upper})", "$1_$2");
// // and then uppercase it to find the status
// return DomainStatus.valueOf(StringUtils.upperCase(value));
// }
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/parser/fieldparser/EnumFieldParser.java
// public class EnumFieldParser<T extends Enum> implements FieldParser<T> {
//
// private Class<T> clazz;
//
// public EnumFieldParser(Class<T> clazz) {
// this.clazz = clazz;
// }
//
// @Override
// public T parse(String value) {
// return (T) Enum.valueOf(clazz, value.toUpperCase());
// }
// }
| import be.dnsbelgium.rdap.sample.dto.DnsSecStatus;
import be.dnsbelgium.rdap.sample.dto.WhoisDomain;
import be.dnsbelgium.rdap.sample.parser.fieldparser.DateTimeFieldParser;
import be.dnsbelgium.rdap.sample.parser.fieldparser.DomainStatusFieldParser;
import be.dnsbelgium.rdap.sample.parser.fieldparser.EnumFieldParser; | parseLayout.addEntry(WhoisKeyBlock.ADMIN, true, "Admin ID", "admin[].id", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin Name", "admin[].name", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin Organization", "admin[].organization", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin Street", "admin[].address.street", true);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin City", "admin[].address.city", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin State/Province", "admin[].address.region", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin Postal Code", "admin[].address.postalCode", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin Country", "admin[].address.countryCode", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin Phone", "admin[].phone", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin Phone Ext", "admin[].phoneExt", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin Fax", "admin[].fax", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin Fax Ext", "admin[].faxExt", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin Email", "admin[].email", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, true, "Tech ID", "tech[].id", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech Name", "tech[].name", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech Organization", "tech[].organization", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech Street", "tech[].address.street", true);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech City", "tech[].address.city", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech State/Province", "tech[].address.region", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech Postal Code", "tech[].address.postalCode", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech Country", "tech[].address.countryCode", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech Phone", "tech[].phone", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech Phone Ext", "tech[].phoneExt", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech Fax", "tech[].fax", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech Fax Ext", "tech[].faxExt", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech Email", "tech[].email", false);
parseLayout.addEntry(WhoisKeyBlock.HOST, false, "Name Server", "nameservers", true);
| // Path: src/main/java/be/dnsbelgium/rdap/sample/dto/DnsSecStatus.java
// public enum DnsSecStatus {
// SIGNED,
// UNSIGNED;
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/dto/WhoisDomain.java
// public class WhoisDomain {
// public String whoisServer;
// public String referralUrl;
// public Domain domain = new Domain();
// public SimpleRegistar sponsoringRegistrar = new SimpleRegistar();
//
// public Contact registrant = new Contact();
// public List<Contact> admin = new ArrayList<>();
// public List<Contact> tech = new ArrayList<>();
//
// public List<String> nameservers = new ArrayList<>();
//
// public DnsSec dnssec = new DnsSec();
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/parser/fieldparser/DateTimeFieldParser.java
// public class DateTimeFieldParser implements FieldParser<DateTime> {
// private DateTimeFormatter formatter;
//
// public DateTimeFieldParser() {
// }
//
// public DateTimeFieldParser(DateTimeFormatter formatter) {
// this.formatter = formatter;
// }
//
// @Override
// public DateTime parse(String value) {
// return (formatter != null) ? DateTime.parse(value, formatter) : DateTime.parse(value);
// }
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/parser/fieldparser/DomainStatusFieldParser.java
// public class DomainStatusFieldParser implements FieldParser<DomainStatus> {
// @Override
// public DomainStatus parse(String value) {
// // Strip of URL's (everything after a space)
// value = StringUtils.substringBefore(value, " ");
// // Replace the camelcase with underscores
// value = value.replaceAll("(.)(\\p{Upper})", "$1_$2");
// // and then uppercase it to find the status
// return DomainStatus.valueOf(StringUtils.upperCase(value));
// }
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/parser/fieldparser/EnumFieldParser.java
// public class EnumFieldParser<T extends Enum> implements FieldParser<T> {
//
// private Class<T> clazz;
//
// public EnumFieldParser(Class<T> clazz) {
// this.clazz = clazz;
// }
//
// @Override
// public T parse(String value) {
// return (T) Enum.valueOf(clazz, value.toUpperCase());
// }
// }
// Path: src/main/java/be/dnsbelgium/rdap/sample/parser/WhoisDomainParser.java
import be.dnsbelgium.rdap.sample.dto.DnsSecStatus;
import be.dnsbelgium.rdap.sample.dto.WhoisDomain;
import be.dnsbelgium.rdap.sample.parser.fieldparser.DateTimeFieldParser;
import be.dnsbelgium.rdap.sample.parser.fieldparser.DomainStatusFieldParser;
import be.dnsbelgium.rdap.sample.parser.fieldparser.EnumFieldParser;
parseLayout.addEntry(WhoisKeyBlock.ADMIN, true, "Admin ID", "admin[].id", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin Name", "admin[].name", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin Organization", "admin[].organization", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin Street", "admin[].address.street", true);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin City", "admin[].address.city", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin State/Province", "admin[].address.region", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin Postal Code", "admin[].address.postalCode", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin Country", "admin[].address.countryCode", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin Phone", "admin[].phone", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin Phone Ext", "admin[].phoneExt", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin Fax", "admin[].fax", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin Fax Ext", "admin[].faxExt", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin Email", "admin[].email", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, true, "Tech ID", "tech[].id", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech Name", "tech[].name", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech Organization", "tech[].organization", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech Street", "tech[].address.street", true);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech City", "tech[].address.city", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech State/Province", "tech[].address.region", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech Postal Code", "tech[].address.postalCode", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech Country", "tech[].address.countryCode", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech Phone", "tech[].phone", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech Phone Ext", "tech[].phoneExt", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech Fax", "tech[].fax", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech Fax Ext", "tech[].faxExt", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech Email", "tech[].email", false);
parseLayout.addEntry(WhoisKeyBlock.HOST, false, "Name Server", "nameservers", true);
| parseLayout.addEntry(WhoisKeyBlock.DNSSEC, true, "DNSSEC", "dnssec.status", false, new EnumFieldParser<>(DnsSecStatus.class)); |
DNSBelgium/rdap-server-sample-gtld | src/main/java/be/dnsbelgium/rdap/sample/parser/WhoisDomainParser.java | // Path: src/main/java/be/dnsbelgium/rdap/sample/dto/DnsSecStatus.java
// public enum DnsSecStatus {
// SIGNED,
// UNSIGNED;
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/dto/WhoisDomain.java
// public class WhoisDomain {
// public String whoisServer;
// public String referralUrl;
// public Domain domain = new Domain();
// public SimpleRegistar sponsoringRegistrar = new SimpleRegistar();
//
// public Contact registrant = new Contact();
// public List<Contact> admin = new ArrayList<>();
// public List<Contact> tech = new ArrayList<>();
//
// public List<String> nameservers = new ArrayList<>();
//
// public DnsSec dnssec = new DnsSec();
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/parser/fieldparser/DateTimeFieldParser.java
// public class DateTimeFieldParser implements FieldParser<DateTime> {
// private DateTimeFormatter formatter;
//
// public DateTimeFieldParser() {
// }
//
// public DateTimeFieldParser(DateTimeFormatter formatter) {
// this.formatter = formatter;
// }
//
// @Override
// public DateTime parse(String value) {
// return (formatter != null) ? DateTime.parse(value, formatter) : DateTime.parse(value);
// }
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/parser/fieldparser/DomainStatusFieldParser.java
// public class DomainStatusFieldParser implements FieldParser<DomainStatus> {
// @Override
// public DomainStatus parse(String value) {
// // Strip of URL's (everything after a space)
// value = StringUtils.substringBefore(value, " ");
// // Replace the camelcase with underscores
// value = value.replaceAll("(.)(\\p{Upper})", "$1_$2");
// // and then uppercase it to find the status
// return DomainStatus.valueOf(StringUtils.upperCase(value));
// }
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/parser/fieldparser/EnumFieldParser.java
// public class EnumFieldParser<T extends Enum> implements FieldParser<T> {
//
// private Class<T> clazz;
//
// public EnumFieldParser(Class<T> clazz) {
// this.clazz = clazz;
// }
//
// @Override
// public T parse(String value) {
// return (T) Enum.valueOf(clazz, value.toUpperCase());
// }
// }
| import be.dnsbelgium.rdap.sample.dto.DnsSecStatus;
import be.dnsbelgium.rdap.sample.dto.WhoisDomain;
import be.dnsbelgium.rdap.sample.parser.fieldparser.DateTimeFieldParser;
import be.dnsbelgium.rdap.sample.parser.fieldparser.DomainStatusFieldParser;
import be.dnsbelgium.rdap.sample.parser.fieldparser.EnumFieldParser; | parseLayout.addEntry(WhoisKeyBlock.ADMIN, true, "Admin ID", "admin[].id", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin Name", "admin[].name", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin Organization", "admin[].organization", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin Street", "admin[].address.street", true);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin City", "admin[].address.city", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin State/Province", "admin[].address.region", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin Postal Code", "admin[].address.postalCode", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin Country", "admin[].address.countryCode", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin Phone", "admin[].phone", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin Phone Ext", "admin[].phoneExt", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin Fax", "admin[].fax", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin Fax Ext", "admin[].faxExt", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin Email", "admin[].email", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, true, "Tech ID", "tech[].id", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech Name", "tech[].name", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech Organization", "tech[].organization", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech Street", "tech[].address.street", true);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech City", "tech[].address.city", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech State/Province", "tech[].address.region", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech Postal Code", "tech[].address.postalCode", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech Country", "tech[].address.countryCode", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech Phone", "tech[].phone", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech Phone Ext", "tech[].phoneExt", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech Fax", "tech[].fax", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech Fax Ext", "tech[].faxExt", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech Email", "tech[].email", false);
parseLayout.addEntry(WhoisKeyBlock.HOST, false, "Name Server", "nameservers", true);
| // Path: src/main/java/be/dnsbelgium/rdap/sample/dto/DnsSecStatus.java
// public enum DnsSecStatus {
// SIGNED,
// UNSIGNED;
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/dto/WhoisDomain.java
// public class WhoisDomain {
// public String whoisServer;
// public String referralUrl;
// public Domain domain = new Domain();
// public SimpleRegistar sponsoringRegistrar = new SimpleRegistar();
//
// public Contact registrant = new Contact();
// public List<Contact> admin = new ArrayList<>();
// public List<Contact> tech = new ArrayList<>();
//
// public List<String> nameservers = new ArrayList<>();
//
// public DnsSec dnssec = new DnsSec();
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/parser/fieldparser/DateTimeFieldParser.java
// public class DateTimeFieldParser implements FieldParser<DateTime> {
// private DateTimeFormatter formatter;
//
// public DateTimeFieldParser() {
// }
//
// public DateTimeFieldParser(DateTimeFormatter formatter) {
// this.formatter = formatter;
// }
//
// @Override
// public DateTime parse(String value) {
// return (formatter != null) ? DateTime.parse(value, formatter) : DateTime.parse(value);
// }
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/parser/fieldparser/DomainStatusFieldParser.java
// public class DomainStatusFieldParser implements FieldParser<DomainStatus> {
// @Override
// public DomainStatus parse(String value) {
// // Strip of URL's (everything after a space)
// value = StringUtils.substringBefore(value, " ");
// // Replace the camelcase with underscores
// value = value.replaceAll("(.)(\\p{Upper})", "$1_$2");
// // and then uppercase it to find the status
// return DomainStatus.valueOf(StringUtils.upperCase(value));
// }
// }
//
// Path: src/main/java/be/dnsbelgium/rdap/sample/parser/fieldparser/EnumFieldParser.java
// public class EnumFieldParser<T extends Enum> implements FieldParser<T> {
//
// private Class<T> clazz;
//
// public EnumFieldParser(Class<T> clazz) {
// this.clazz = clazz;
// }
//
// @Override
// public T parse(String value) {
// return (T) Enum.valueOf(clazz, value.toUpperCase());
// }
// }
// Path: src/main/java/be/dnsbelgium/rdap/sample/parser/WhoisDomainParser.java
import be.dnsbelgium.rdap.sample.dto.DnsSecStatus;
import be.dnsbelgium.rdap.sample.dto.WhoisDomain;
import be.dnsbelgium.rdap.sample.parser.fieldparser.DateTimeFieldParser;
import be.dnsbelgium.rdap.sample.parser.fieldparser.DomainStatusFieldParser;
import be.dnsbelgium.rdap.sample.parser.fieldparser.EnumFieldParser;
parseLayout.addEntry(WhoisKeyBlock.ADMIN, true, "Admin ID", "admin[].id", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin Name", "admin[].name", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin Organization", "admin[].organization", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin Street", "admin[].address.street", true);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin City", "admin[].address.city", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin State/Province", "admin[].address.region", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin Postal Code", "admin[].address.postalCode", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin Country", "admin[].address.countryCode", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin Phone", "admin[].phone", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin Phone Ext", "admin[].phoneExt", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin Fax", "admin[].fax", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin Fax Ext", "admin[].faxExt", false);
parseLayout.addEntry(WhoisKeyBlock.ADMIN, "Admin Email", "admin[].email", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, true, "Tech ID", "tech[].id", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech Name", "tech[].name", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech Organization", "tech[].organization", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech Street", "tech[].address.street", true);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech City", "tech[].address.city", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech State/Province", "tech[].address.region", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech Postal Code", "tech[].address.postalCode", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech Country", "tech[].address.countryCode", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech Phone", "tech[].phone", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech Phone Ext", "tech[].phoneExt", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech Fax", "tech[].fax", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech Fax Ext", "tech[].faxExt", false);
parseLayout.addEntry(WhoisKeyBlock.TECH, "Tech Email", "tech[].email", false);
parseLayout.addEntry(WhoisKeyBlock.HOST, false, "Name Server", "nameservers", true);
| parseLayout.addEntry(WhoisKeyBlock.DNSSEC, true, "DNSSEC", "dnssec.status", false, new EnumFieldParser<>(DnsSecStatus.class)); |
abicelis/Remindy | app/src/main/java/ve/com/abicelis/remindy/model/attachment/LinkAttachment.java | // Path: app/src/main/java/ve/com/abicelis/remindy/enums/AttachmentType.java
// public enum AttachmentType {
// IMAGE,
// LINK,
// TEXT,
// AUDIO,
// LIST
// }
//
// Path: app/src/main/java/ve/com/abicelis/remindy/exception/MalformedLinkException.java
// public class MalformedLinkException extends Exception {
//
// private static final String DEFAULT_MESSAGE = "Link is invalid, malformed.";
//
// public MalformedLinkException() {
// super(DEFAULT_MESSAGE);
// }
// public MalformedLinkException(String message) {
// super(message);
// }
// public MalformedLinkException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
| import android.util.Patterns;
import java.util.regex.Pattern;
import ve.com.abicelis.remindy.enums.AttachmentType;
import ve.com.abicelis.remindy.exception.MalformedLinkException; | package ve.com.abicelis.remindy.model.attachment;
/**
* Created by abice on 3/3/2017.
*/
public class LinkAttachment extends Attachment {
private String link;
public LinkAttachment(String link) {
this.link = link;
}
public LinkAttachment(int id, int reminderId, String link) {
super(id, reminderId);
this.link = link;
}
@Override | // Path: app/src/main/java/ve/com/abicelis/remindy/enums/AttachmentType.java
// public enum AttachmentType {
// IMAGE,
// LINK,
// TEXT,
// AUDIO,
// LIST
// }
//
// Path: app/src/main/java/ve/com/abicelis/remindy/exception/MalformedLinkException.java
// public class MalformedLinkException extends Exception {
//
// private static final String DEFAULT_MESSAGE = "Link is invalid, malformed.";
//
// public MalformedLinkException() {
// super(DEFAULT_MESSAGE);
// }
// public MalformedLinkException(String message) {
// super(message);
// }
// public MalformedLinkException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
// Path: app/src/main/java/ve/com/abicelis/remindy/model/attachment/LinkAttachment.java
import android.util.Patterns;
import java.util.regex.Pattern;
import ve.com.abicelis.remindy.enums.AttachmentType;
import ve.com.abicelis.remindy.exception.MalformedLinkException;
package ve.com.abicelis.remindy.model.attachment;
/**
* Created by abice on 3/3/2017.
*/
public class LinkAttachment extends Attachment {
private String link;
public LinkAttachment(String link) {
this.link = link;
}
public LinkAttachment(int id, int reminderId, String link) {
super(id, reminderId);
this.link = link;
}
@Override | public AttachmentType getType() { |
abicelis/Remindy | app/src/main/java/ve/com/abicelis/remindy/model/attachment/LinkAttachment.java | // Path: app/src/main/java/ve/com/abicelis/remindy/enums/AttachmentType.java
// public enum AttachmentType {
// IMAGE,
// LINK,
// TEXT,
// AUDIO,
// LIST
// }
//
// Path: app/src/main/java/ve/com/abicelis/remindy/exception/MalformedLinkException.java
// public class MalformedLinkException extends Exception {
//
// private static final String DEFAULT_MESSAGE = "Link is invalid, malformed.";
//
// public MalformedLinkException() {
// super(DEFAULT_MESSAGE);
// }
// public MalformedLinkException(String message) {
// super(message);
// }
// public MalformedLinkException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
| import android.util.Patterns;
import java.util.regex.Pattern;
import ve.com.abicelis.remindy.enums.AttachmentType;
import ve.com.abicelis.remindy.exception.MalformedLinkException; | package ve.com.abicelis.remindy.model.attachment;
/**
* Created by abice on 3/3/2017.
*/
public class LinkAttachment extends Attachment {
private String link;
public LinkAttachment(String link) {
this.link = link;
}
public LinkAttachment(int id, int reminderId, String link) {
super(id, reminderId);
this.link = link;
}
@Override
public AttachmentType getType() {
return AttachmentType.LINK;
}
public String getLink() {
return link;
} | // Path: app/src/main/java/ve/com/abicelis/remindy/enums/AttachmentType.java
// public enum AttachmentType {
// IMAGE,
// LINK,
// TEXT,
// AUDIO,
// LIST
// }
//
// Path: app/src/main/java/ve/com/abicelis/remindy/exception/MalformedLinkException.java
// public class MalformedLinkException extends Exception {
//
// private static final String DEFAULT_MESSAGE = "Link is invalid, malformed.";
//
// public MalformedLinkException() {
// super(DEFAULT_MESSAGE);
// }
// public MalformedLinkException(String message) {
// super(message);
// }
// public MalformedLinkException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
// Path: app/src/main/java/ve/com/abicelis/remindy/model/attachment/LinkAttachment.java
import android.util.Patterns;
import java.util.regex.Pattern;
import ve.com.abicelis.remindy.enums.AttachmentType;
import ve.com.abicelis.remindy.exception.MalformedLinkException;
package ve.com.abicelis.remindy.model.attachment;
/**
* Created by abice on 3/3/2017.
*/
public class LinkAttachment extends Attachment {
private String link;
public LinkAttachment(String link) {
this.link = link;
}
public LinkAttachment(int id, int reminderId, String link) {
super(id, reminderId);
this.link = link;
}
@Override
public AttachmentType getType() {
return AttachmentType.LINK;
}
public String getLink() {
return link;
} | public void setLink(String link) throws MalformedLinkException { |
abicelis/Remindy | app/src/main/java/ve/com/abicelis/remindy/model/reminder/LocationBasedReminder.java | // Path: app/src/main/java/ve/com/abicelis/remindy/enums/ReminderType.java
// public enum ReminderType implements Serializable {
// NONE(R.string.reminder_type_none),
// ONE_TIME(R.string.reminder_type_one_time),
// REPEATING(R.string.reminder_type_repeating),
// LOCATION_BASED(R.string.reminder_type_location_based);
//
// private @StringRes
// int friendlyNameRes;
//
// ReminderType(@StringRes int friendlyNameRes) {
// this.friendlyNameRes = friendlyNameRes;
//
// }
//
// public int getFriendlyNameRes() {
// return friendlyNameRes;
// }
//
// public static List<String> getFriendlyValues(Context context) {
// List<String> friendlyValues = new ArrayList<>();
// for (ReminderType rt : values()) {
// friendlyValues.add(context.getResources().getString(rt.friendlyNameRes));
// }
// return friendlyValues;
// }
// }
//
// Path: app/src/main/java/ve/com/abicelis/remindy/model/Place.java
// public class Place implements Serializable {
//
// private static final int DEFAULT_RADIUS = 500; //Default radius 500m
//
// private int id;
// private String alias;
// private String address;
// private double latitude;
// private double longitude;
// private int radius;
// private boolean isOneOff; //Places are one-off when a reminder is created with a Place = Other,
// // The place is saved in the database but it isn't a frequent one nor will it appear in saved places
//
// public Place(String alias, String address, double latitude, double longitude, int radius, boolean isOneOff) {
// this.alias = alias;
// this.address = address;
// this.latitude = latitude;
// this.longitude = longitude;
// this.radius = radius;
// this.isOneOff = isOneOff;
// }
//
// public Place(int id, String alias, String address, double latitude, double longitude, int radius, boolean isOneOff) {
// this(alias, address, latitude, longitude, radius, isOneOff);
// this.id = id;
// }
//
// public Place(Place place) {
// this(place.getId(), place.getAlias(), place.getAddress(), place.getLatitude(), place.getLongitude(), place.getRadius(), place.isOneOff());
// }
//
// public Place() {
// radius = DEFAULT_RADIUS;
// }
//
// public int getId() {
// return id;
// }
// public void setId(int id) {
// this.id = id;
// }
//
// public String getAlias() {
// return alias;
// }
// public void setAlias(String alias) {
// this.alias = alias;
// }
//
// public String getAddress() {
// return address;
// }
// public void setAddress(String address) {
// this.address = address;
// }
//
// public double getLatitude() {
// return latitude;
// }
// public void setLatitude(double latitude) {
// this.latitude = latitude;
// }
//
// public double getLongitude() {
// return longitude;
// }
// public void setLongitude(double longitude) {
// this.longitude = longitude;
// }
//
// public int getRadius() {
// return radius;
// }
// public void setRadius(int radius) {
// this.radius = radius;
// }
//
// public boolean isOneOff() {
// return isOneOff;
// }
// public void setOneOff(boolean oneOff) {
// isOneOff = oneOff;
// }
//
// @Override
// public String toString() {
// return "ID=" + id + "\r\n" +
// " alias=" + alias + "\r\n" +
// " address=" + address + "\r\n" +
// " latitude=" + latitude + "\r\n" +
// " longitude=" + longitude + "\r\n" +
// " radius=" + radius + "\r\n" +
// " isOneOff=" + isOneOff;
// }
//
// @Override
// public boolean equals(Object obj) {
// if(obj == null)
// return false;
//
// if(obj instanceof Place) {
// Place that = (Place) obj;
// return (this.getId() == that.getId() &&
// this.getAlias().equals(that.getAlias()) &&
// this.getLatitude() == that.getLatitude() &&
// this.getLongitude() == that.getLongitude() &&
// this.getRadius() == that.getRadius());
// }
// return false;
// }
// }
| import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import java.io.Serializable;
import ve.com.abicelis.remindy.R;
import ve.com.abicelis.remindy.enums.ReminderType;
import ve.com.abicelis.remindy.model.Place; | package ve.com.abicelis.remindy.model.reminder;
/**
* Created by abice on 3/3/2017.
*/
public class LocationBasedReminder extends Reminder implements Serializable {
private int placeId; | // Path: app/src/main/java/ve/com/abicelis/remindy/enums/ReminderType.java
// public enum ReminderType implements Serializable {
// NONE(R.string.reminder_type_none),
// ONE_TIME(R.string.reminder_type_one_time),
// REPEATING(R.string.reminder_type_repeating),
// LOCATION_BASED(R.string.reminder_type_location_based);
//
// private @StringRes
// int friendlyNameRes;
//
// ReminderType(@StringRes int friendlyNameRes) {
// this.friendlyNameRes = friendlyNameRes;
//
// }
//
// public int getFriendlyNameRes() {
// return friendlyNameRes;
// }
//
// public static List<String> getFriendlyValues(Context context) {
// List<String> friendlyValues = new ArrayList<>();
// for (ReminderType rt : values()) {
// friendlyValues.add(context.getResources().getString(rt.friendlyNameRes));
// }
// return friendlyValues;
// }
// }
//
// Path: app/src/main/java/ve/com/abicelis/remindy/model/Place.java
// public class Place implements Serializable {
//
// private static final int DEFAULT_RADIUS = 500; //Default radius 500m
//
// private int id;
// private String alias;
// private String address;
// private double latitude;
// private double longitude;
// private int radius;
// private boolean isOneOff; //Places are one-off when a reminder is created with a Place = Other,
// // The place is saved in the database but it isn't a frequent one nor will it appear in saved places
//
// public Place(String alias, String address, double latitude, double longitude, int radius, boolean isOneOff) {
// this.alias = alias;
// this.address = address;
// this.latitude = latitude;
// this.longitude = longitude;
// this.radius = radius;
// this.isOneOff = isOneOff;
// }
//
// public Place(int id, String alias, String address, double latitude, double longitude, int radius, boolean isOneOff) {
// this(alias, address, latitude, longitude, radius, isOneOff);
// this.id = id;
// }
//
// public Place(Place place) {
// this(place.getId(), place.getAlias(), place.getAddress(), place.getLatitude(), place.getLongitude(), place.getRadius(), place.isOneOff());
// }
//
// public Place() {
// radius = DEFAULT_RADIUS;
// }
//
// public int getId() {
// return id;
// }
// public void setId(int id) {
// this.id = id;
// }
//
// public String getAlias() {
// return alias;
// }
// public void setAlias(String alias) {
// this.alias = alias;
// }
//
// public String getAddress() {
// return address;
// }
// public void setAddress(String address) {
// this.address = address;
// }
//
// public double getLatitude() {
// return latitude;
// }
// public void setLatitude(double latitude) {
// this.latitude = latitude;
// }
//
// public double getLongitude() {
// return longitude;
// }
// public void setLongitude(double longitude) {
// this.longitude = longitude;
// }
//
// public int getRadius() {
// return radius;
// }
// public void setRadius(int radius) {
// this.radius = radius;
// }
//
// public boolean isOneOff() {
// return isOneOff;
// }
// public void setOneOff(boolean oneOff) {
// isOneOff = oneOff;
// }
//
// @Override
// public String toString() {
// return "ID=" + id + "\r\n" +
// " alias=" + alias + "\r\n" +
// " address=" + address + "\r\n" +
// " latitude=" + latitude + "\r\n" +
// " longitude=" + longitude + "\r\n" +
// " radius=" + radius + "\r\n" +
// " isOneOff=" + isOneOff;
// }
//
// @Override
// public boolean equals(Object obj) {
// if(obj == null)
// return false;
//
// if(obj instanceof Place) {
// Place that = (Place) obj;
// return (this.getId() == that.getId() &&
// this.getAlias().equals(that.getAlias()) &&
// this.getLatitude() == that.getLatitude() &&
// this.getLongitude() == that.getLongitude() &&
// this.getRadius() == that.getRadius());
// }
// return false;
// }
// }
// Path: app/src/main/java/ve/com/abicelis/remindy/model/reminder/LocationBasedReminder.java
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import java.io.Serializable;
import ve.com.abicelis.remindy.R;
import ve.com.abicelis.remindy.enums.ReminderType;
import ve.com.abicelis.remindy.model.Place;
package ve.com.abicelis.remindy.model.reminder;
/**
* Created by abice on 3/3/2017.
*/
public class LocationBasedReminder extends Reminder implements Serializable {
private int placeId; | private Place place; |
abicelis/Remindy | app/src/main/java/ve/com/abicelis/remindy/model/reminder/LocationBasedReminder.java | // Path: app/src/main/java/ve/com/abicelis/remindy/enums/ReminderType.java
// public enum ReminderType implements Serializable {
// NONE(R.string.reminder_type_none),
// ONE_TIME(R.string.reminder_type_one_time),
// REPEATING(R.string.reminder_type_repeating),
// LOCATION_BASED(R.string.reminder_type_location_based);
//
// private @StringRes
// int friendlyNameRes;
//
// ReminderType(@StringRes int friendlyNameRes) {
// this.friendlyNameRes = friendlyNameRes;
//
// }
//
// public int getFriendlyNameRes() {
// return friendlyNameRes;
// }
//
// public static List<String> getFriendlyValues(Context context) {
// List<String> friendlyValues = new ArrayList<>();
// for (ReminderType rt : values()) {
// friendlyValues.add(context.getResources().getString(rt.friendlyNameRes));
// }
// return friendlyValues;
// }
// }
//
// Path: app/src/main/java/ve/com/abicelis/remindy/model/Place.java
// public class Place implements Serializable {
//
// private static final int DEFAULT_RADIUS = 500; //Default radius 500m
//
// private int id;
// private String alias;
// private String address;
// private double latitude;
// private double longitude;
// private int radius;
// private boolean isOneOff; //Places are one-off when a reminder is created with a Place = Other,
// // The place is saved in the database but it isn't a frequent one nor will it appear in saved places
//
// public Place(String alias, String address, double latitude, double longitude, int radius, boolean isOneOff) {
// this.alias = alias;
// this.address = address;
// this.latitude = latitude;
// this.longitude = longitude;
// this.radius = radius;
// this.isOneOff = isOneOff;
// }
//
// public Place(int id, String alias, String address, double latitude, double longitude, int radius, boolean isOneOff) {
// this(alias, address, latitude, longitude, radius, isOneOff);
// this.id = id;
// }
//
// public Place(Place place) {
// this(place.getId(), place.getAlias(), place.getAddress(), place.getLatitude(), place.getLongitude(), place.getRadius(), place.isOneOff());
// }
//
// public Place() {
// radius = DEFAULT_RADIUS;
// }
//
// public int getId() {
// return id;
// }
// public void setId(int id) {
// this.id = id;
// }
//
// public String getAlias() {
// return alias;
// }
// public void setAlias(String alias) {
// this.alias = alias;
// }
//
// public String getAddress() {
// return address;
// }
// public void setAddress(String address) {
// this.address = address;
// }
//
// public double getLatitude() {
// return latitude;
// }
// public void setLatitude(double latitude) {
// this.latitude = latitude;
// }
//
// public double getLongitude() {
// return longitude;
// }
// public void setLongitude(double longitude) {
// this.longitude = longitude;
// }
//
// public int getRadius() {
// return radius;
// }
// public void setRadius(int radius) {
// this.radius = radius;
// }
//
// public boolean isOneOff() {
// return isOneOff;
// }
// public void setOneOff(boolean oneOff) {
// isOneOff = oneOff;
// }
//
// @Override
// public String toString() {
// return "ID=" + id + "\r\n" +
// " alias=" + alias + "\r\n" +
// " address=" + address + "\r\n" +
// " latitude=" + latitude + "\r\n" +
// " longitude=" + longitude + "\r\n" +
// " radius=" + radius + "\r\n" +
// " isOneOff=" + isOneOff;
// }
//
// @Override
// public boolean equals(Object obj) {
// if(obj == null)
// return false;
//
// if(obj instanceof Place) {
// Place that = (Place) obj;
// return (this.getId() == that.getId() &&
// this.getAlias().equals(that.getAlias()) &&
// this.getLatitude() == that.getLatitude() &&
// this.getLongitude() == that.getLongitude() &&
// this.getRadius() == that.getRadius());
// }
// return false;
// }
// }
| import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import java.io.Serializable;
import ve.com.abicelis.remindy.R;
import ve.com.abicelis.remindy.enums.ReminderType;
import ve.com.abicelis.remindy.model.Place; | package ve.com.abicelis.remindy.model.reminder;
/**
* Created by abice on 3/3/2017.
*/
public class LocationBasedReminder extends Reminder implements Serializable {
private int placeId;
private Place place;
private boolean triggerEntering;
private boolean triggerExiting;
public LocationBasedReminder() {} //Parameter-less argument for Reminder creation
public LocationBasedReminder(int placeId, @NonNull Place place, boolean triggerEntering, boolean triggerExiting) {
init(placeId, place, triggerEntering, triggerExiting);
}
public LocationBasedReminder(int id, int taskId, int placeId, @Nullable Place place, boolean triggerEntering, boolean triggerExiting) {
super(id, taskId);
init(placeId, place, triggerEntering, triggerExiting);
}
private void init(int placeId, @Nullable Place place, boolean triggerEntering, boolean triggerExiting) {
this.placeId = placeId;
this.place = place;
this.triggerEntering = triggerEntering;
this.triggerExiting = triggerExiting;
}
@Override | // Path: app/src/main/java/ve/com/abicelis/remindy/enums/ReminderType.java
// public enum ReminderType implements Serializable {
// NONE(R.string.reminder_type_none),
// ONE_TIME(R.string.reminder_type_one_time),
// REPEATING(R.string.reminder_type_repeating),
// LOCATION_BASED(R.string.reminder_type_location_based);
//
// private @StringRes
// int friendlyNameRes;
//
// ReminderType(@StringRes int friendlyNameRes) {
// this.friendlyNameRes = friendlyNameRes;
//
// }
//
// public int getFriendlyNameRes() {
// return friendlyNameRes;
// }
//
// public static List<String> getFriendlyValues(Context context) {
// List<String> friendlyValues = new ArrayList<>();
// for (ReminderType rt : values()) {
// friendlyValues.add(context.getResources().getString(rt.friendlyNameRes));
// }
// return friendlyValues;
// }
// }
//
// Path: app/src/main/java/ve/com/abicelis/remindy/model/Place.java
// public class Place implements Serializable {
//
// private static final int DEFAULT_RADIUS = 500; //Default radius 500m
//
// private int id;
// private String alias;
// private String address;
// private double latitude;
// private double longitude;
// private int radius;
// private boolean isOneOff; //Places are one-off when a reminder is created with a Place = Other,
// // The place is saved in the database but it isn't a frequent one nor will it appear in saved places
//
// public Place(String alias, String address, double latitude, double longitude, int radius, boolean isOneOff) {
// this.alias = alias;
// this.address = address;
// this.latitude = latitude;
// this.longitude = longitude;
// this.radius = radius;
// this.isOneOff = isOneOff;
// }
//
// public Place(int id, String alias, String address, double latitude, double longitude, int radius, boolean isOneOff) {
// this(alias, address, latitude, longitude, radius, isOneOff);
// this.id = id;
// }
//
// public Place(Place place) {
// this(place.getId(), place.getAlias(), place.getAddress(), place.getLatitude(), place.getLongitude(), place.getRadius(), place.isOneOff());
// }
//
// public Place() {
// radius = DEFAULT_RADIUS;
// }
//
// public int getId() {
// return id;
// }
// public void setId(int id) {
// this.id = id;
// }
//
// public String getAlias() {
// return alias;
// }
// public void setAlias(String alias) {
// this.alias = alias;
// }
//
// public String getAddress() {
// return address;
// }
// public void setAddress(String address) {
// this.address = address;
// }
//
// public double getLatitude() {
// return latitude;
// }
// public void setLatitude(double latitude) {
// this.latitude = latitude;
// }
//
// public double getLongitude() {
// return longitude;
// }
// public void setLongitude(double longitude) {
// this.longitude = longitude;
// }
//
// public int getRadius() {
// return radius;
// }
// public void setRadius(int radius) {
// this.radius = radius;
// }
//
// public boolean isOneOff() {
// return isOneOff;
// }
// public void setOneOff(boolean oneOff) {
// isOneOff = oneOff;
// }
//
// @Override
// public String toString() {
// return "ID=" + id + "\r\n" +
// " alias=" + alias + "\r\n" +
// " address=" + address + "\r\n" +
// " latitude=" + latitude + "\r\n" +
// " longitude=" + longitude + "\r\n" +
// " radius=" + radius + "\r\n" +
// " isOneOff=" + isOneOff;
// }
//
// @Override
// public boolean equals(Object obj) {
// if(obj == null)
// return false;
//
// if(obj instanceof Place) {
// Place that = (Place) obj;
// return (this.getId() == that.getId() &&
// this.getAlias().equals(that.getAlias()) &&
// this.getLatitude() == that.getLatitude() &&
// this.getLongitude() == that.getLongitude() &&
// this.getRadius() == that.getRadius());
// }
// return false;
// }
// }
// Path: app/src/main/java/ve/com/abicelis/remindy/model/reminder/LocationBasedReminder.java
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import java.io.Serializable;
import ve.com.abicelis.remindy.R;
import ve.com.abicelis.remindy.enums.ReminderType;
import ve.com.abicelis.remindy.model.Place;
package ve.com.abicelis.remindy.model.reminder;
/**
* Created by abice on 3/3/2017.
*/
public class LocationBasedReminder extends Reminder implements Serializable {
private int placeId;
private Place place;
private boolean triggerEntering;
private boolean triggerExiting;
public LocationBasedReminder() {} //Parameter-less argument for Reminder creation
public LocationBasedReminder(int placeId, @NonNull Place place, boolean triggerEntering, boolean triggerExiting) {
init(placeId, place, triggerEntering, triggerExiting);
}
public LocationBasedReminder(int id, int taskId, int placeId, @Nullable Place place, boolean triggerEntering, boolean triggerExiting) {
super(id, taskId);
init(placeId, place, triggerEntering, triggerExiting);
}
private void init(int placeId, @Nullable Place place, boolean triggerEntering, boolean triggerExiting) {
this.placeId = placeId;
this.place = place;
this.triggerEntering = triggerEntering;
this.triggerExiting = triggerExiting;
}
@Override | public ReminderType getType() { |
abicelis/Remindy | app/src/main/java/ve/com/abicelis/remindy/model/reminder/Reminder.java | // Path: app/src/main/java/ve/com/abicelis/remindy/enums/ReminderType.java
// public enum ReminderType implements Serializable {
// NONE(R.string.reminder_type_none),
// ONE_TIME(R.string.reminder_type_one_time),
// REPEATING(R.string.reminder_type_repeating),
// LOCATION_BASED(R.string.reminder_type_location_based);
//
// private @StringRes
// int friendlyNameRes;
//
// ReminderType(@StringRes int friendlyNameRes) {
// this.friendlyNameRes = friendlyNameRes;
//
// }
//
// public int getFriendlyNameRes() {
// return friendlyNameRes;
// }
//
// public static List<String> getFriendlyValues(Context context) {
// List<String> friendlyValues = new ArrayList<>();
// for (ReminderType rt : values()) {
// friendlyValues.add(context.getResources().getString(rt.friendlyNameRes));
// }
// return friendlyValues;
// }
// }
| import java.io.Serializable;
import ve.com.abicelis.remindy.enums.ReminderType; | package ve.com.abicelis.remindy.model.reminder;
/**
* Created by abice on 24/3/2017.
*/
public abstract class Reminder implements Serializable {
private int id;
private int taskId;
public Reminder(){
this.id = -1;
this.taskId = -1;
}
public Reminder(int id, int taskId) {
this.id = id;
this.taskId = taskId;
}
| // Path: app/src/main/java/ve/com/abicelis/remindy/enums/ReminderType.java
// public enum ReminderType implements Serializable {
// NONE(R.string.reminder_type_none),
// ONE_TIME(R.string.reminder_type_one_time),
// REPEATING(R.string.reminder_type_repeating),
// LOCATION_BASED(R.string.reminder_type_location_based);
//
// private @StringRes
// int friendlyNameRes;
//
// ReminderType(@StringRes int friendlyNameRes) {
// this.friendlyNameRes = friendlyNameRes;
//
// }
//
// public int getFriendlyNameRes() {
// return friendlyNameRes;
// }
//
// public static List<String> getFriendlyValues(Context context) {
// List<String> friendlyValues = new ArrayList<>();
// for (ReminderType rt : values()) {
// friendlyValues.add(context.getResources().getString(rt.friendlyNameRes));
// }
// return friendlyValues;
// }
// }
// Path: app/src/main/java/ve/com/abicelis/remindy/model/reminder/Reminder.java
import java.io.Serializable;
import ve.com.abicelis.remindy.enums.ReminderType;
package ve.com.abicelis.remindy.model.reminder;
/**
* Created by abice on 24/3/2017.
*/
public abstract class Reminder implements Serializable {
private int id;
private int taskId;
public Reminder(){
this.id = -1;
this.taskId = -1;
}
public Reminder(int id, int taskId) {
this.id = id;
this.taskId = taskId;
}
| public abstract ReminderType getType(); |
abicelis/Remindy | app/src/main/java/ve/com/abicelis/remindy/viewmodel/TaskViewModel.java | // Path: app/src/main/java/ve/com/abicelis/remindy/enums/TaskViewModelType.java
// public enum TaskViewModelType implements Serializable {
// HEADER,
// UNPROGRAMMED_REMINDER,
// ONE_TIME_REMINDER,
// REPEATING_REMINDER,
// LOCATION_BASED_REMINDER
// }
//
// Path: app/src/main/java/ve/com/abicelis/remindy/model/Task.java
// public class Task implements Serializable {
//
// private int id;
// private TaskStatus status;
// private String title;
// private String description;
// private TaskCategory category;
// private ReminderType reminderType;
// private Reminder reminder;
// private Calendar doneDate;
// private ArrayList<Attachment> attachments;
//
// public Task() { //Empty constructor for creating new tasks
// this.id = -1;
// this.status = TaskStatus.UNPROGRAMMED;
// this.title = "";
// this.description = "";
// this.reminderType = ReminderType.NONE;
// this.attachments = new ArrayList<>();
// }
//
// public Task(@NonNull TaskStatus status, @NonNull String title, @NonNull String description, @NonNull TaskCategory category, @NonNull ReminderType reminderType, @Nullable Reminder reminder, @Nullable Calendar doneDate) {
// this.status = status;
// this.title = title;
// this.description = description;
// this.category = category;
// this.reminderType = reminderType;
// this.reminder = reminder;
// this.doneDate = doneDate;
// this.attachments = new ArrayList<>();
// }
//
// public Task(int id, @NonNull TaskStatus status, @NonNull String title, @NonNull String description, @NonNull TaskCategory category, @NonNull ReminderType reminderType, @Nullable Reminder reminder, @Nullable Calendar doneDate) {
// this(status, title, description, category, reminderType, reminder, doneDate);
// this.id = id;
// }
//
//
// public int getId() {
// return id;
// }
// public void setId(int id) {
// this.id = id;
// }
//
// public TaskStatus getStatus() {
// return status;
// }
// public void setStatus(TaskStatus status) {
// this.status = status;
// }
//
// public String getTitle() {
// return title;
// }
// public void setTitle(String title) {
// this.title = title;
// }
//
// public String getDescription() {
// return description;
// }
// public void setDescription(String description) {
// this.description = description;
// }
//
// public TaskCategory getCategory() {
// return category;
// }
// public void setCategory(TaskCategory category) {
// this.category = category;
// }
//
// public ReminderType getReminderType() {
// return reminderType;
// }
// public void setReminderType(ReminderType reminderType) {
// this.reminderType = reminderType;
// }
//
// public Reminder getReminder() {
// return reminder;
// }
// public void setReminder(Reminder reminder) {
// this.reminder = reminder;
// }
//
// public Calendar getDoneDate() {
// return doneDate;
// }
// public void setDoneDate(Calendar doneDate) {
// this.doneDate = doneDate;
// }
//
// public ArrayList<Attachment> getAttachments() {
// return attachments;
// }
// public void setAttachments(ArrayList<Attachment> attachments) {
// this.attachments = attachments;
// }
// public void addAttachment(Attachment attachment) {
// this.attachments.add(attachment);
// }
// public void clearAttachments() {
// attachments.clear();
// }
//
//
//
// @Override
// public String toString() {
// String res = "Task ID=" + id + "\r\n Status= " + status.name() + "\r\n Title=" + title + "\r\n Description=" + description + "\r\n Category=" + category.name() + "\r\n";
// res += " ReminderType=" + reminderType.name();
// if(reminder != null) res += " Reminder=" + reminder.toString() + "\r\n";
// if(doneDate != null) res += " DoneDate=" + doneDate.toString();
// res += " Attachments=" + attachments.size();
// return res;
// }
// }
| import android.support.annotation.NonNull;
import java.security.InvalidParameterException;
import ve.com.abicelis.remindy.enums.TaskViewModelType;
import ve.com.abicelis.remindy.model.Task; | package ve.com.abicelis.remindy.viewmodel;
/**
* Created by abice on 26/3/2017.
*/
public class TaskViewModel {
//DATA
private Task task = null;
private String headerTitle = null;
private boolean headerTitleRed; | // Path: app/src/main/java/ve/com/abicelis/remindy/enums/TaskViewModelType.java
// public enum TaskViewModelType implements Serializable {
// HEADER,
// UNPROGRAMMED_REMINDER,
// ONE_TIME_REMINDER,
// REPEATING_REMINDER,
// LOCATION_BASED_REMINDER
// }
//
// Path: app/src/main/java/ve/com/abicelis/remindy/model/Task.java
// public class Task implements Serializable {
//
// private int id;
// private TaskStatus status;
// private String title;
// private String description;
// private TaskCategory category;
// private ReminderType reminderType;
// private Reminder reminder;
// private Calendar doneDate;
// private ArrayList<Attachment> attachments;
//
// public Task() { //Empty constructor for creating new tasks
// this.id = -1;
// this.status = TaskStatus.UNPROGRAMMED;
// this.title = "";
// this.description = "";
// this.reminderType = ReminderType.NONE;
// this.attachments = new ArrayList<>();
// }
//
// public Task(@NonNull TaskStatus status, @NonNull String title, @NonNull String description, @NonNull TaskCategory category, @NonNull ReminderType reminderType, @Nullable Reminder reminder, @Nullable Calendar doneDate) {
// this.status = status;
// this.title = title;
// this.description = description;
// this.category = category;
// this.reminderType = reminderType;
// this.reminder = reminder;
// this.doneDate = doneDate;
// this.attachments = new ArrayList<>();
// }
//
// public Task(int id, @NonNull TaskStatus status, @NonNull String title, @NonNull String description, @NonNull TaskCategory category, @NonNull ReminderType reminderType, @Nullable Reminder reminder, @Nullable Calendar doneDate) {
// this(status, title, description, category, reminderType, reminder, doneDate);
// this.id = id;
// }
//
//
// public int getId() {
// return id;
// }
// public void setId(int id) {
// this.id = id;
// }
//
// public TaskStatus getStatus() {
// return status;
// }
// public void setStatus(TaskStatus status) {
// this.status = status;
// }
//
// public String getTitle() {
// return title;
// }
// public void setTitle(String title) {
// this.title = title;
// }
//
// public String getDescription() {
// return description;
// }
// public void setDescription(String description) {
// this.description = description;
// }
//
// public TaskCategory getCategory() {
// return category;
// }
// public void setCategory(TaskCategory category) {
// this.category = category;
// }
//
// public ReminderType getReminderType() {
// return reminderType;
// }
// public void setReminderType(ReminderType reminderType) {
// this.reminderType = reminderType;
// }
//
// public Reminder getReminder() {
// return reminder;
// }
// public void setReminder(Reminder reminder) {
// this.reminder = reminder;
// }
//
// public Calendar getDoneDate() {
// return doneDate;
// }
// public void setDoneDate(Calendar doneDate) {
// this.doneDate = doneDate;
// }
//
// public ArrayList<Attachment> getAttachments() {
// return attachments;
// }
// public void setAttachments(ArrayList<Attachment> attachments) {
// this.attachments = attachments;
// }
// public void addAttachment(Attachment attachment) {
// this.attachments.add(attachment);
// }
// public void clearAttachments() {
// attachments.clear();
// }
//
//
//
// @Override
// public String toString() {
// String res = "Task ID=" + id + "\r\n Status= " + status.name() + "\r\n Title=" + title + "\r\n Description=" + description + "\r\n Category=" + category.name() + "\r\n";
// res += " ReminderType=" + reminderType.name();
// if(reminder != null) res += " Reminder=" + reminder.toString() + "\r\n";
// if(doneDate != null) res += " DoneDate=" + doneDate.toString();
// res += " Attachments=" + attachments.size();
// return res;
// }
// }
// Path: app/src/main/java/ve/com/abicelis/remindy/viewmodel/TaskViewModel.java
import android.support.annotation.NonNull;
import java.security.InvalidParameterException;
import ve.com.abicelis.remindy.enums.TaskViewModelType;
import ve.com.abicelis.remindy.model.Task;
package ve.com.abicelis.remindy.viewmodel;
/**
* Created by abice on 26/3/2017.
*/
public class TaskViewModel {
//DATA
private Task task = null;
private String headerTitle = null;
private boolean headerTitleRed; | private TaskViewModelType viewModelType; |
abicelis/Remindy | app/src/main/java/ve/com/abicelis/remindy/model/attachment/TextAttachment.java | // Path: app/src/main/java/ve/com/abicelis/remindy/enums/AttachmentType.java
// public enum AttachmentType {
// IMAGE,
// LINK,
// TEXT,
// AUDIO,
// LIST
// }
| import ve.com.abicelis.remindy.enums.AttachmentType; | package ve.com.abicelis.remindy.model.attachment;
/**
* Created by abice on 3/3/2017.
*/
public class TextAttachment extends Attachment {
private String text;
public TextAttachment(String text) {
this.text = text;
}
public TextAttachment(int id, int reminderId, String text) {
super(id, reminderId);
this.text = text;
}
@Override | // Path: app/src/main/java/ve/com/abicelis/remindy/enums/AttachmentType.java
// public enum AttachmentType {
// IMAGE,
// LINK,
// TEXT,
// AUDIO,
// LIST
// }
// Path: app/src/main/java/ve/com/abicelis/remindy/model/attachment/TextAttachment.java
import ve.com.abicelis.remindy.enums.AttachmentType;
package ve.com.abicelis.remindy.model.attachment;
/**
* Created by abice on 3/3/2017.
*/
public class TextAttachment extends Attachment {
private String text;
public TextAttachment(String text) {
this.text = text;
}
public TextAttachment(int id, int reminderId, String text) {
super(id, reminderId);
this.text = text;
}
@Override | public AttachmentType getType() { |
abicelis/Remindy | app/src/main/java/ve/com/abicelis/remindy/model/attachment/AudioAttachment.java | // Path: app/src/main/java/ve/com/abicelis/remindy/enums/AttachmentType.java
// public enum AttachmentType {
// IMAGE,
// LINK,
// TEXT,
// AUDIO,
// LIST
// }
| import ve.com.abicelis.remindy.enums.AttachmentType; | package ve.com.abicelis.remindy.model.attachment;
/**
* Created by abice on 3/3/2017.
*/
public class AudioAttachment extends Attachment {
private String audioFilename;
public AudioAttachment() { /* Parameter-less constructor for audio attachment creation */ }
public AudioAttachment(String audioFilename) {
this.audioFilename = audioFilename;
}
public AudioAttachment(int id, int reminderId, String audioFilename) {
super(id, reminderId);
this.audioFilename = audioFilename;
}
@Override | // Path: app/src/main/java/ve/com/abicelis/remindy/enums/AttachmentType.java
// public enum AttachmentType {
// IMAGE,
// LINK,
// TEXT,
// AUDIO,
// LIST
// }
// Path: app/src/main/java/ve/com/abicelis/remindy/model/attachment/AudioAttachment.java
import ve.com.abicelis.remindy.enums.AttachmentType;
package ve.com.abicelis.remindy.model.attachment;
/**
* Created by abice on 3/3/2017.
*/
public class AudioAttachment extends Attachment {
private String audioFilename;
public AudioAttachment() { /* Parameter-less constructor for audio attachment creation */ }
public AudioAttachment(String audioFilename) {
this.audioFilename = audioFilename;
}
public AudioAttachment(int id, int reminderId, String audioFilename) {
super(id, reminderId);
this.audioFilename = audioFilename;
}
@Override | public AttachmentType getType() { |
abicelis/Remindy | app/src/main/java/ve/com/abicelis/remindy/model/attachment/ListAttachment.java | // Path: app/src/main/java/ve/com/abicelis/remindy/enums/AttachmentType.java
// public enum AttachmentType {
// IMAGE,
// LINK,
// TEXT,
// AUDIO,
// LIST
// }
| import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.io.Serializable;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import ve.com.abicelis.remindy.enums.AttachmentType; | package ve.com.abicelis.remindy.model.attachment;
/**
* Created by abice on 3/3/2017.
*/
public class ListAttachment extends Attachment implements Serializable {
private List<ListItemAttachment> items;
public ListAttachment() {
this.items = new ArrayList<>();
}
public ListAttachment(int id, int reminderId, String itemsJsonText) {
super(id, reminderId);
setItemsJson(itemsJsonText);
}
@Override | // Path: app/src/main/java/ve/com/abicelis/remindy/enums/AttachmentType.java
// public enum AttachmentType {
// IMAGE,
// LINK,
// TEXT,
// AUDIO,
// LIST
// }
// Path: app/src/main/java/ve/com/abicelis/remindy/model/attachment/ListAttachment.java
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.io.Serializable;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import ve.com.abicelis.remindy.enums.AttachmentType;
package ve.com.abicelis.remindy.model.attachment;
/**
* Created by abice on 3/3/2017.
*/
public class ListAttachment extends Attachment implements Serializable {
private List<ListItemAttachment> items;
public ListAttachment() {
this.items = new ArrayList<>();
}
public ListAttachment(int id, int reminderId, String itemsJsonText) {
super(id, reminderId);
setItemsJson(itemsJsonText);
}
@Override | public AttachmentType getType() { |
abicelis/Remindy | app/src/main/java/ve/com/abicelis/remindy/util/SharedPreferenceUtil.java | // Path: app/src/main/java/ve/com/abicelis/remindy/enums/DateFormat.java
// public enum DateFormat {
// PRETTY_DATE {
// @Override
// public String formatCalendar(Calendar calendar) {
// SimpleDateFormat formatter = new SimpleDateFormat("MMM d, yyyy", Locale.getDefault());
// String str = formatter.format(calendar.getTime());
//
// if(Locale.getDefault().equals(Locale.ENGLISH) || Locale.getDefault().equals(Locale.US) || Locale.getDefault().equals(Locale.UK) || Locale.getDefault().equals(Locale.CANADA))
// str = str.replaceFirst(",", DateFormat.getDayNumberSuffix(calendar.get(Calendar.DAY_OF_MONTH)) + "," );
//
// return str;
// }
// },
// MONTH_DAY_YEAR{
// @Override
// public String formatCalendar(Calendar calendar) {
// SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy", Locale.getDefault());
// return formatter.format(calendar.getTime());
// }
// },
// DAY_MONTH_YEAR{
// @Override
// public String formatCalendar(Calendar calendar) {
// SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy", Locale.getDefault());
// return formatter.format(calendar.getTime());
// }
// },
// ;
//
// public abstract String formatCalendar(Calendar calendar);
//
// private static String getDayNumberSuffix(int day) {
// if (day >= 11 && day <= 13) {
// return "th";
// }
// switch (day % 10) {
// case 1:
// return "st";
// case 2:
// return "nd";
// case 3:
// return "rd";
// default:
// return "th";
// }
// }
//
// }
//
// Path: app/src/main/java/ve/com/abicelis/remindy/enums/TimeFormat.java
// public enum TimeFormat {
// FORMAT_24H,
// FORMAT_12H
// }
//
// Path: app/src/main/java/ve/com/abicelis/remindy/enums/TriggerMinutesBeforeNotificationType.java
// public enum TriggerMinutesBeforeNotificationType {
// MINUTES_1(1),
// MINUTES_5(5),
// MINUTES_10(10),
// MINUTES_20(20);
//
// private int mMinutes;
//
// TriggerMinutesBeforeNotificationType(int minutes) {
// mMinutes = minutes;
// }
//
// public int getMinutes() {
// return mMinutes;
// }
// }
//
// Path: app/src/main/java/ve/com/abicelis/remindy/enums/TapTargetSequenceType.java
// public enum TapTargetSequenceType {
// EDIT_IMAGE_ATTACHMENT_ACTIVITY,
// PLACE_LIST_ACTIVITY,
// PLACE_ACTIVITY,
// }
| import android.content.Context;
import android.content.SharedPreferences;
import android.support.v7.preference.PreferenceManager;
import android.util.Log;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import ve.com.abicelis.remindy.R;
import ve.com.abicelis.remindy.enums.DateFormat;
import ve.com.abicelis.remindy.enums.TimeFormat;
import ve.com.abicelis.remindy.enums.TriggerMinutesBeforeNotificationType;
import ve.com.abicelis.remindy.enums.TapTargetSequenceType; | package ve.com.abicelis.remindy.util;
/**
* Created by abice on 1/4/2017.
*/
public class SharedPreferenceUtil {
public static boolean doShowTapTargetSequenceFor(Context context, TapTargetSequenceType tapTargetSequenceType) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
boolean flag = preferences.getBoolean(tapTargetSequenceType.name(), true);
//boolean flag = true;
if(flag)
preferences.edit().putBoolean(tapTargetSequenceType.name(), false).apply();
return flag;
}
| // Path: app/src/main/java/ve/com/abicelis/remindy/enums/DateFormat.java
// public enum DateFormat {
// PRETTY_DATE {
// @Override
// public String formatCalendar(Calendar calendar) {
// SimpleDateFormat formatter = new SimpleDateFormat("MMM d, yyyy", Locale.getDefault());
// String str = formatter.format(calendar.getTime());
//
// if(Locale.getDefault().equals(Locale.ENGLISH) || Locale.getDefault().equals(Locale.US) || Locale.getDefault().equals(Locale.UK) || Locale.getDefault().equals(Locale.CANADA))
// str = str.replaceFirst(",", DateFormat.getDayNumberSuffix(calendar.get(Calendar.DAY_OF_MONTH)) + "," );
//
// return str;
// }
// },
// MONTH_DAY_YEAR{
// @Override
// public String formatCalendar(Calendar calendar) {
// SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy", Locale.getDefault());
// return formatter.format(calendar.getTime());
// }
// },
// DAY_MONTH_YEAR{
// @Override
// public String formatCalendar(Calendar calendar) {
// SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy", Locale.getDefault());
// return formatter.format(calendar.getTime());
// }
// },
// ;
//
// public abstract String formatCalendar(Calendar calendar);
//
// private static String getDayNumberSuffix(int day) {
// if (day >= 11 && day <= 13) {
// return "th";
// }
// switch (day % 10) {
// case 1:
// return "st";
// case 2:
// return "nd";
// case 3:
// return "rd";
// default:
// return "th";
// }
// }
//
// }
//
// Path: app/src/main/java/ve/com/abicelis/remindy/enums/TimeFormat.java
// public enum TimeFormat {
// FORMAT_24H,
// FORMAT_12H
// }
//
// Path: app/src/main/java/ve/com/abicelis/remindy/enums/TriggerMinutesBeforeNotificationType.java
// public enum TriggerMinutesBeforeNotificationType {
// MINUTES_1(1),
// MINUTES_5(5),
// MINUTES_10(10),
// MINUTES_20(20);
//
// private int mMinutes;
//
// TriggerMinutesBeforeNotificationType(int minutes) {
// mMinutes = minutes;
// }
//
// public int getMinutes() {
// return mMinutes;
// }
// }
//
// Path: app/src/main/java/ve/com/abicelis/remindy/enums/TapTargetSequenceType.java
// public enum TapTargetSequenceType {
// EDIT_IMAGE_ATTACHMENT_ACTIVITY,
// PLACE_LIST_ACTIVITY,
// PLACE_ACTIVITY,
// }
// Path: app/src/main/java/ve/com/abicelis/remindy/util/SharedPreferenceUtil.java
import android.content.Context;
import android.content.SharedPreferences;
import android.support.v7.preference.PreferenceManager;
import android.util.Log;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import ve.com.abicelis.remindy.R;
import ve.com.abicelis.remindy.enums.DateFormat;
import ve.com.abicelis.remindy.enums.TimeFormat;
import ve.com.abicelis.remindy.enums.TriggerMinutesBeforeNotificationType;
import ve.com.abicelis.remindy.enums.TapTargetSequenceType;
package ve.com.abicelis.remindy.util;
/**
* Created by abice on 1/4/2017.
*/
public class SharedPreferenceUtil {
public static boolean doShowTapTargetSequenceFor(Context context, TapTargetSequenceType tapTargetSequenceType) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
boolean flag = preferences.getBoolean(tapTargetSequenceType.name(), true);
//boolean flag = true;
if(flag)
preferences.edit().putBoolean(tapTargetSequenceType.name(), false).apply();
return flag;
}
| public static DateFormat getDateFormat(Context context) { |
abicelis/Remindy | app/src/main/java/ve/com/abicelis/remindy/util/SharedPreferenceUtil.java | // Path: app/src/main/java/ve/com/abicelis/remindy/enums/DateFormat.java
// public enum DateFormat {
// PRETTY_DATE {
// @Override
// public String formatCalendar(Calendar calendar) {
// SimpleDateFormat formatter = new SimpleDateFormat("MMM d, yyyy", Locale.getDefault());
// String str = formatter.format(calendar.getTime());
//
// if(Locale.getDefault().equals(Locale.ENGLISH) || Locale.getDefault().equals(Locale.US) || Locale.getDefault().equals(Locale.UK) || Locale.getDefault().equals(Locale.CANADA))
// str = str.replaceFirst(",", DateFormat.getDayNumberSuffix(calendar.get(Calendar.DAY_OF_MONTH)) + "," );
//
// return str;
// }
// },
// MONTH_DAY_YEAR{
// @Override
// public String formatCalendar(Calendar calendar) {
// SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy", Locale.getDefault());
// return formatter.format(calendar.getTime());
// }
// },
// DAY_MONTH_YEAR{
// @Override
// public String formatCalendar(Calendar calendar) {
// SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy", Locale.getDefault());
// return formatter.format(calendar.getTime());
// }
// },
// ;
//
// public abstract String formatCalendar(Calendar calendar);
//
// private static String getDayNumberSuffix(int day) {
// if (day >= 11 && day <= 13) {
// return "th";
// }
// switch (day % 10) {
// case 1:
// return "st";
// case 2:
// return "nd";
// case 3:
// return "rd";
// default:
// return "th";
// }
// }
//
// }
//
// Path: app/src/main/java/ve/com/abicelis/remindy/enums/TimeFormat.java
// public enum TimeFormat {
// FORMAT_24H,
// FORMAT_12H
// }
//
// Path: app/src/main/java/ve/com/abicelis/remindy/enums/TriggerMinutesBeforeNotificationType.java
// public enum TriggerMinutesBeforeNotificationType {
// MINUTES_1(1),
// MINUTES_5(5),
// MINUTES_10(10),
// MINUTES_20(20);
//
// private int mMinutes;
//
// TriggerMinutesBeforeNotificationType(int minutes) {
// mMinutes = minutes;
// }
//
// public int getMinutes() {
// return mMinutes;
// }
// }
//
// Path: app/src/main/java/ve/com/abicelis/remindy/enums/TapTargetSequenceType.java
// public enum TapTargetSequenceType {
// EDIT_IMAGE_ATTACHMENT_ACTIVITY,
// PLACE_LIST_ACTIVITY,
// PLACE_ACTIVITY,
// }
| import android.content.Context;
import android.content.SharedPreferences;
import android.support.v7.preference.PreferenceManager;
import android.util.Log;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import ve.com.abicelis.remindy.R;
import ve.com.abicelis.remindy.enums.DateFormat;
import ve.com.abicelis.remindy.enums.TimeFormat;
import ve.com.abicelis.remindy.enums.TriggerMinutesBeforeNotificationType;
import ve.com.abicelis.remindy.enums.TapTargetSequenceType; |
public static DateFormat getDateFormat(Context context) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
String dfPref = preferences.getString(context.getResources().getString(R.string.settings_date_format_key), null);
DateFormat pref;
try {
pref = DateFormat.valueOf(dfPref);
} catch (Exception e) {
pref = null;
}
if(pref == null) {
Log.d("SharedPreferenceUtil", "getDateFormat() found null, setting PRETTY_DATE");
DateFormat df = DateFormat.PRETTY_DATE;
setDateFormat(df, context);
return df;
}
else return pref;
}
public static void setDateFormat(DateFormat df, Context context) {
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
editor.putString(context.getResources().getString(R.string.settings_date_format_key), df.name());
editor.apply();
}
| // Path: app/src/main/java/ve/com/abicelis/remindy/enums/DateFormat.java
// public enum DateFormat {
// PRETTY_DATE {
// @Override
// public String formatCalendar(Calendar calendar) {
// SimpleDateFormat formatter = new SimpleDateFormat("MMM d, yyyy", Locale.getDefault());
// String str = formatter.format(calendar.getTime());
//
// if(Locale.getDefault().equals(Locale.ENGLISH) || Locale.getDefault().equals(Locale.US) || Locale.getDefault().equals(Locale.UK) || Locale.getDefault().equals(Locale.CANADA))
// str = str.replaceFirst(",", DateFormat.getDayNumberSuffix(calendar.get(Calendar.DAY_OF_MONTH)) + "," );
//
// return str;
// }
// },
// MONTH_DAY_YEAR{
// @Override
// public String formatCalendar(Calendar calendar) {
// SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy", Locale.getDefault());
// return formatter.format(calendar.getTime());
// }
// },
// DAY_MONTH_YEAR{
// @Override
// public String formatCalendar(Calendar calendar) {
// SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy", Locale.getDefault());
// return formatter.format(calendar.getTime());
// }
// },
// ;
//
// public abstract String formatCalendar(Calendar calendar);
//
// private static String getDayNumberSuffix(int day) {
// if (day >= 11 && day <= 13) {
// return "th";
// }
// switch (day % 10) {
// case 1:
// return "st";
// case 2:
// return "nd";
// case 3:
// return "rd";
// default:
// return "th";
// }
// }
//
// }
//
// Path: app/src/main/java/ve/com/abicelis/remindy/enums/TimeFormat.java
// public enum TimeFormat {
// FORMAT_24H,
// FORMAT_12H
// }
//
// Path: app/src/main/java/ve/com/abicelis/remindy/enums/TriggerMinutesBeforeNotificationType.java
// public enum TriggerMinutesBeforeNotificationType {
// MINUTES_1(1),
// MINUTES_5(5),
// MINUTES_10(10),
// MINUTES_20(20);
//
// private int mMinutes;
//
// TriggerMinutesBeforeNotificationType(int minutes) {
// mMinutes = minutes;
// }
//
// public int getMinutes() {
// return mMinutes;
// }
// }
//
// Path: app/src/main/java/ve/com/abicelis/remindy/enums/TapTargetSequenceType.java
// public enum TapTargetSequenceType {
// EDIT_IMAGE_ATTACHMENT_ACTIVITY,
// PLACE_LIST_ACTIVITY,
// PLACE_ACTIVITY,
// }
// Path: app/src/main/java/ve/com/abicelis/remindy/util/SharedPreferenceUtil.java
import android.content.Context;
import android.content.SharedPreferences;
import android.support.v7.preference.PreferenceManager;
import android.util.Log;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import ve.com.abicelis.remindy.R;
import ve.com.abicelis.remindy.enums.DateFormat;
import ve.com.abicelis.remindy.enums.TimeFormat;
import ve.com.abicelis.remindy.enums.TriggerMinutesBeforeNotificationType;
import ve.com.abicelis.remindy.enums.TapTargetSequenceType;
public static DateFormat getDateFormat(Context context) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
String dfPref = preferences.getString(context.getResources().getString(R.string.settings_date_format_key), null);
DateFormat pref;
try {
pref = DateFormat.valueOf(dfPref);
} catch (Exception e) {
pref = null;
}
if(pref == null) {
Log.d("SharedPreferenceUtil", "getDateFormat() found null, setting PRETTY_DATE");
DateFormat df = DateFormat.PRETTY_DATE;
setDateFormat(df, context);
return df;
}
else return pref;
}
public static void setDateFormat(DateFormat df, Context context) {
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
editor.putString(context.getResources().getString(R.string.settings_date_format_key), df.name());
editor.apply();
}
| public static TimeFormat getTimeFormat(Context context) { |
abicelis/Remindy | app/src/main/java/ve/com/abicelis/remindy/util/SharedPreferenceUtil.java | // Path: app/src/main/java/ve/com/abicelis/remindy/enums/DateFormat.java
// public enum DateFormat {
// PRETTY_DATE {
// @Override
// public String formatCalendar(Calendar calendar) {
// SimpleDateFormat formatter = new SimpleDateFormat("MMM d, yyyy", Locale.getDefault());
// String str = formatter.format(calendar.getTime());
//
// if(Locale.getDefault().equals(Locale.ENGLISH) || Locale.getDefault().equals(Locale.US) || Locale.getDefault().equals(Locale.UK) || Locale.getDefault().equals(Locale.CANADA))
// str = str.replaceFirst(",", DateFormat.getDayNumberSuffix(calendar.get(Calendar.DAY_OF_MONTH)) + "," );
//
// return str;
// }
// },
// MONTH_DAY_YEAR{
// @Override
// public String formatCalendar(Calendar calendar) {
// SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy", Locale.getDefault());
// return formatter.format(calendar.getTime());
// }
// },
// DAY_MONTH_YEAR{
// @Override
// public String formatCalendar(Calendar calendar) {
// SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy", Locale.getDefault());
// return formatter.format(calendar.getTime());
// }
// },
// ;
//
// public abstract String formatCalendar(Calendar calendar);
//
// private static String getDayNumberSuffix(int day) {
// if (day >= 11 && day <= 13) {
// return "th";
// }
// switch (day % 10) {
// case 1:
// return "st";
// case 2:
// return "nd";
// case 3:
// return "rd";
// default:
// return "th";
// }
// }
//
// }
//
// Path: app/src/main/java/ve/com/abicelis/remindy/enums/TimeFormat.java
// public enum TimeFormat {
// FORMAT_24H,
// FORMAT_12H
// }
//
// Path: app/src/main/java/ve/com/abicelis/remindy/enums/TriggerMinutesBeforeNotificationType.java
// public enum TriggerMinutesBeforeNotificationType {
// MINUTES_1(1),
// MINUTES_5(5),
// MINUTES_10(10),
// MINUTES_20(20);
//
// private int mMinutes;
//
// TriggerMinutesBeforeNotificationType(int minutes) {
// mMinutes = minutes;
// }
//
// public int getMinutes() {
// return mMinutes;
// }
// }
//
// Path: app/src/main/java/ve/com/abicelis/remindy/enums/TapTargetSequenceType.java
// public enum TapTargetSequenceType {
// EDIT_IMAGE_ATTACHMENT_ACTIVITY,
// PLACE_LIST_ACTIVITY,
// PLACE_ACTIVITY,
// }
| import android.content.Context;
import android.content.SharedPreferences;
import android.support.v7.preference.PreferenceManager;
import android.util.Log;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import ve.com.abicelis.remindy.R;
import ve.com.abicelis.remindy.enums.DateFormat;
import ve.com.abicelis.remindy.enums.TimeFormat;
import ve.com.abicelis.remindy.enums.TriggerMinutesBeforeNotificationType;
import ve.com.abicelis.remindy.enums.TapTargetSequenceType; | if(json != null) {
try {
Type listType = new TypeToken<List<Integer>>() {}.getType();
Gson gson = new Gson();
tasks = gson.fromJson(json, listType);
} catch (Exception e) { /* Do nothing */}
}
return tasks;
}
public static void setTriggeredTaskList(List<Integer> tasks, Context context) {
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
editor.putString(context.getResources().getString(R.string.settings_triggered_task_list_key), new Gson().toJson(tasks));
editor.apply();
}
public static void removeIdFromTriggeredTasks(Context context, int taskId) {
List<Integer> triggeredTasks = getTriggeredTaskList(context);
Iterator<Integer> iter = triggeredTasks.iterator();
while(iter.hasNext()) {
if (iter.next().equals(taskId)) {
iter.remove();
}
}
setTriggeredTaskList(triggeredTasks, context);
}
| // Path: app/src/main/java/ve/com/abicelis/remindy/enums/DateFormat.java
// public enum DateFormat {
// PRETTY_DATE {
// @Override
// public String formatCalendar(Calendar calendar) {
// SimpleDateFormat formatter = new SimpleDateFormat("MMM d, yyyy", Locale.getDefault());
// String str = formatter.format(calendar.getTime());
//
// if(Locale.getDefault().equals(Locale.ENGLISH) || Locale.getDefault().equals(Locale.US) || Locale.getDefault().equals(Locale.UK) || Locale.getDefault().equals(Locale.CANADA))
// str = str.replaceFirst(",", DateFormat.getDayNumberSuffix(calendar.get(Calendar.DAY_OF_MONTH)) + "," );
//
// return str;
// }
// },
// MONTH_DAY_YEAR{
// @Override
// public String formatCalendar(Calendar calendar) {
// SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy", Locale.getDefault());
// return formatter.format(calendar.getTime());
// }
// },
// DAY_MONTH_YEAR{
// @Override
// public String formatCalendar(Calendar calendar) {
// SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy", Locale.getDefault());
// return formatter.format(calendar.getTime());
// }
// },
// ;
//
// public abstract String formatCalendar(Calendar calendar);
//
// private static String getDayNumberSuffix(int day) {
// if (day >= 11 && day <= 13) {
// return "th";
// }
// switch (day % 10) {
// case 1:
// return "st";
// case 2:
// return "nd";
// case 3:
// return "rd";
// default:
// return "th";
// }
// }
//
// }
//
// Path: app/src/main/java/ve/com/abicelis/remindy/enums/TimeFormat.java
// public enum TimeFormat {
// FORMAT_24H,
// FORMAT_12H
// }
//
// Path: app/src/main/java/ve/com/abicelis/remindy/enums/TriggerMinutesBeforeNotificationType.java
// public enum TriggerMinutesBeforeNotificationType {
// MINUTES_1(1),
// MINUTES_5(5),
// MINUTES_10(10),
// MINUTES_20(20);
//
// private int mMinutes;
//
// TriggerMinutesBeforeNotificationType(int minutes) {
// mMinutes = minutes;
// }
//
// public int getMinutes() {
// return mMinutes;
// }
// }
//
// Path: app/src/main/java/ve/com/abicelis/remindy/enums/TapTargetSequenceType.java
// public enum TapTargetSequenceType {
// EDIT_IMAGE_ATTACHMENT_ACTIVITY,
// PLACE_LIST_ACTIVITY,
// PLACE_ACTIVITY,
// }
// Path: app/src/main/java/ve/com/abicelis/remindy/util/SharedPreferenceUtil.java
import android.content.Context;
import android.content.SharedPreferences;
import android.support.v7.preference.PreferenceManager;
import android.util.Log;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import ve.com.abicelis.remindy.R;
import ve.com.abicelis.remindy.enums.DateFormat;
import ve.com.abicelis.remindy.enums.TimeFormat;
import ve.com.abicelis.remindy.enums.TriggerMinutesBeforeNotificationType;
import ve.com.abicelis.remindy.enums.TapTargetSequenceType;
if(json != null) {
try {
Type listType = new TypeToken<List<Integer>>() {}.getType();
Gson gson = new Gson();
tasks = gson.fromJson(json, listType);
} catch (Exception e) { /* Do nothing */}
}
return tasks;
}
public static void setTriggeredTaskList(List<Integer> tasks, Context context) {
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
editor.putString(context.getResources().getString(R.string.settings_triggered_task_list_key), new Gson().toJson(tasks));
editor.apply();
}
public static void removeIdFromTriggeredTasks(Context context, int taskId) {
List<Integer> triggeredTasks = getTriggeredTaskList(context);
Iterator<Integer> iter = triggeredTasks.iterator();
while(iter.hasNext()) {
if (iter.next().equals(taskId)) {
iter.remove();
}
}
setTriggeredTaskList(triggeredTasks, context);
}
| public static TriggerMinutesBeforeNotificationType getTriggerMinutesBeforeNotification(Context context) { |
abicelis/Remindy | app/src/main/java/ve/com/abicelis/remindy/model/attachment/Attachment.java | // Path: app/src/main/java/ve/com/abicelis/remindy/enums/AttachmentType.java
// public enum AttachmentType {
// IMAGE,
// LINK,
// TEXT,
// AUDIO,
// LIST
// }
| import java.io.Serializable;
import ve.com.abicelis.remindy.enums.AttachmentType; | package ve.com.abicelis.remindy.model.attachment;
/**
* Created by abice on 3/3/2017.
*/
public abstract class Attachment implements Serializable {
private int id;
private int taskId;
public Attachment() {} //id-less Constructor used when creating Attachments
public Attachment(int id, int taskId) {
this.id = id;
this.taskId = taskId;
}
| // Path: app/src/main/java/ve/com/abicelis/remindy/enums/AttachmentType.java
// public enum AttachmentType {
// IMAGE,
// LINK,
// TEXT,
// AUDIO,
// LIST
// }
// Path: app/src/main/java/ve/com/abicelis/remindy/model/attachment/Attachment.java
import java.io.Serializable;
import ve.com.abicelis.remindy.enums.AttachmentType;
package ve.com.abicelis.remindy.model.attachment;
/**
* Created by abice on 3/3/2017.
*/
public abstract class Attachment implements Serializable {
private int id;
private int taskId;
public Attachment() {} //id-less Constructor used when creating Attachments
public Attachment(int id, int taskId) {
this.id = id;
this.taskId = taskId;
}
| public abstract AttachmentType getType(); |
abicelis/Remindy | app/src/main/java/ve/com/abicelis/remindy/model/Time.java | // Path: app/src/main/java/ve/com/abicelis/remindy/enums/TimeFormat.java
// public enum TimeFormat {
// FORMAT_24H,
// FORMAT_12H
// }
| import java.io.Serializable;
import java.security.InvalidParameterException;
import java.util.Locale;
import ve.com.abicelis.remindy.enums.TimeFormat; | package ve.com.abicelis.remindy.model;
/**
* Created by abice on 8/3/2017.
*/
/**
* Note: Internally handles time always as 24H time.
*/
public class Time implements Comparable<Time>, Serializable {
private int hour;
private int minute; | // Path: app/src/main/java/ve/com/abicelis/remindy/enums/TimeFormat.java
// public enum TimeFormat {
// FORMAT_24H,
// FORMAT_12H
// }
// Path: app/src/main/java/ve/com/abicelis/remindy/model/Time.java
import java.io.Serializable;
import java.security.InvalidParameterException;
import java.util.Locale;
import ve.com.abicelis.remindy.enums.TimeFormat;
package ve.com.abicelis.remindy.model;
/**
* Created by abice on 8/3/2017.
*/
/**
* Note: Internally handles time always as 24H time.
*/
public class Time implements Comparable<Time>, Serializable {
private int hour;
private int minute; | private TimeFormat displayTimeFormat = TimeFormat.FORMAT_24H; |
abicelis/Remindy | app/src/main/java/ve/com/abicelis/remindy/util/CalendarUtil.java | // Path: app/src/main/java/ve/com/abicelis/remindy/model/Time.java
// public class Time implements Comparable<Time>, Serializable {
// private int hour;
// private int minute;
// private TimeFormat displayTimeFormat = TimeFormat.FORMAT_24H;
//
// public Time() {
// this.hour = 0;
// this.minute = 0;
// }
// public Time(int timeInMinutes) {
// setTimeInMinutes(timeInMinutes);
// }
//
// public Time(int hour, int minute) {
// this.hour = hour;
// this.minute = minute;
// }
//
// public Time(int hour, int minute, TimeFormat displayTimeFormat) {
// this(hour, minute);
// this.displayTimeFormat = displayTimeFormat;
// }
//
// public int getHour(){
// return hour;
// }
// public void setHour(int hour) throws InvalidParameterException {
// if(hour >= 0 && hour <= 24)
// this.hour = hour;
// else
// throw new InvalidParameterException("Value of parameter (" + hour + "), is outside 0-24");
// }
//
// public int getMinute() {
// return minute;
// }
// public void setMinute(int minute) throws InvalidParameterException {
// if(hour >= 0 && hour <= 24)
// this.minute = minute;
// else
// throw new InvalidParameterException("Value of parameter (" + minute + "), is outside 0-60");
// }
//
//
// public TimeFormat getDisplayTimeFormat() {
// return displayTimeFormat;
// }
// public void setDisplayTimeFormat(TimeFormat displayTimeFormat) {
// this.displayTimeFormat = displayTimeFormat;
// }
//
//
//
//
// public boolean before(Time when) throws IllegalArgumentException {
// if(when == null)
// throw new IllegalArgumentException("Argument is null. Cannot compare");
// return this.getTimeInMinutes() < when.getTimeInMinutes();
// }
//
// public boolean after(Time when) throws IllegalArgumentException {
// if(when == null)
// throw new IllegalArgumentException("Argument is null. Cannot compare");
// return this.getTimeInMinutes() > when.getTimeInMinutes();
// }
//
// public int getTimeInMinutes() {
// return (hour*60) + minute;
// }
// public void setTimeInMinutes(int minutes) {
// if(minutes >= 0 && minutes <= 24*60) {
// this.hour = minutes/60;
// this.minute = minutes%60;
// }
// else
// throw new InvalidParameterException("Value of parameter (" + minute + "), is outside 0-60");
// }
//
// @Override
// public int compareTo(Time o) {
// int thisTime = this.getTimeInMinutes();
// int thatTime = o.getTimeInMinutes();
// return (thisTime<thatTime ? -1 : (thisTime==thatTime ? 0 : 1));
// }
//
// @Override
// public String toString() {
// switch (displayTimeFormat) {
// case FORMAT_24H:
// return String.format(Locale.getDefault(), "%1$02d:%2$02d", hour, minute);
// case FORMAT_12H:
// String amPm = "am";
// int hour12h = hour;
// if(hour > 12) {
// amPm = "pm";
// hour12h = hour - 12;
// }
// return String.format(Locale.getDefault(), "%1$02d:%2$02d %3$s", hour12h, minute, amPm);
// default:
// throw new IllegalArgumentException("displayTimeFormat is null. Cannot toString()");
// }
// }
// }
| import java.util.Calendar;
import ve.com.abicelis.remindy.model.Time; | package ve.com.abicelis.remindy.util;
/**
* Created by abice on 26/4/2017.
*/
public class CalendarUtil {
public static Calendar getNewInstanceZeroedCalendar() {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal;
}
public static void copyCalendar(Calendar copyFrom, Calendar copyTo) {
if(copyFrom == null || copyTo == null)
throw new NullPointerException("copyCalendar(), One of both parameters are null");
copyTo.setTimeZone(copyFrom.getTimeZone());
copyTo.setTimeInMillis(copyFrom.getTimeInMillis());
}
public static long getDifferenceMinutesBetween(Calendar a, Calendar b) {
long differenceMinutes = ( a.getTimeInMillis() - b.getTimeInMillis() ) / 60000; //60 * 1000 toMinutes * toSeconds
return differenceMinutes;
}
| // Path: app/src/main/java/ve/com/abicelis/remindy/model/Time.java
// public class Time implements Comparable<Time>, Serializable {
// private int hour;
// private int minute;
// private TimeFormat displayTimeFormat = TimeFormat.FORMAT_24H;
//
// public Time() {
// this.hour = 0;
// this.minute = 0;
// }
// public Time(int timeInMinutes) {
// setTimeInMinutes(timeInMinutes);
// }
//
// public Time(int hour, int minute) {
// this.hour = hour;
// this.minute = minute;
// }
//
// public Time(int hour, int minute, TimeFormat displayTimeFormat) {
// this(hour, minute);
// this.displayTimeFormat = displayTimeFormat;
// }
//
// public int getHour(){
// return hour;
// }
// public void setHour(int hour) throws InvalidParameterException {
// if(hour >= 0 && hour <= 24)
// this.hour = hour;
// else
// throw new InvalidParameterException("Value of parameter (" + hour + "), is outside 0-24");
// }
//
// public int getMinute() {
// return minute;
// }
// public void setMinute(int minute) throws InvalidParameterException {
// if(hour >= 0 && hour <= 24)
// this.minute = minute;
// else
// throw new InvalidParameterException("Value of parameter (" + minute + "), is outside 0-60");
// }
//
//
// public TimeFormat getDisplayTimeFormat() {
// return displayTimeFormat;
// }
// public void setDisplayTimeFormat(TimeFormat displayTimeFormat) {
// this.displayTimeFormat = displayTimeFormat;
// }
//
//
//
//
// public boolean before(Time when) throws IllegalArgumentException {
// if(when == null)
// throw new IllegalArgumentException("Argument is null. Cannot compare");
// return this.getTimeInMinutes() < when.getTimeInMinutes();
// }
//
// public boolean after(Time when) throws IllegalArgumentException {
// if(when == null)
// throw new IllegalArgumentException("Argument is null. Cannot compare");
// return this.getTimeInMinutes() > when.getTimeInMinutes();
// }
//
// public int getTimeInMinutes() {
// return (hour*60) + minute;
// }
// public void setTimeInMinutes(int minutes) {
// if(minutes >= 0 && minutes <= 24*60) {
// this.hour = minutes/60;
// this.minute = minutes%60;
// }
// else
// throw new InvalidParameterException("Value of parameter (" + minute + "), is outside 0-60");
// }
//
// @Override
// public int compareTo(Time o) {
// int thisTime = this.getTimeInMinutes();
// int thatTime = o.getTimeInMinutes();
// return (thisTime<thatTime ? -1 : (thisTime==thatTime ? 0 : 1));
// }
//
// @Override
// public String toString() {
// switch (displayTimeFormat) {
// case FORMAT_24H:
// return String.format(Locale.getDefault(), "%1$02d:%2$02d", hour, minute);
// case FORMAT_12H:
// String amPm = "am";
// int hour12h = hour;
// if(hour > 12) {
// amPm = "pm";
// hour12h = hour - 12;
// }
// return String.format(Locale.getDefault(), "%1$02d:%2$02d %3$s", hour12h, minute, amPm);
// default:
// throw new IllegalArgumentException("displayTimeFormat is null. Cannot toString()");
// }
// }
// }
// Path: app/src/main/java/ve/com/abicelis/remindy/util/CalendarUtil.java
import java.util.Calendar;
import ve.com.abicelis.remindy.model.Time;
package ve.com.abicelis.remindy.util;
/**
* Created by abice on 26/4/2017.
*/
public class CalendarUtil {
public static Calendar getNewInstanceZeroedCalendar() {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal;
}
public static void copyCalendar(Calendar copyFrom, Calendar copyTo) {
if(copyFrom == null || copyTo == null)
throw new NullPointerException("copyCalendar(), One of both parameters are null");
copyTo.setTimeZone(copyFrom.getTimeZone());
copyTo.setTimeInMillis(copyFrom.getTimeInMillis());
}
public static long getDifferenceMinutesBetween(Calendar a, Calendar b) {
long differenceMinutes = ( a.getTimeInMillis() - b.getTimeInMillis() ) / 60000; //60 * 1000 toMinutes * toSeconds
return differenceMinutes;
}
| public static Calendar getCalendarFromDateAndTime(Calendar date, Time time) { |
abicelis/Remindy | app/src/main/java/ve/com/abicelis/remindy/util/FileUtil.java | // Path: app/src/main/java/ve/com/abicelis/remindy/model/attachment/Attachment.java
// public abstract class Attachment implements Serializable {
// private int id;
// private int taskId;
//
// public Attachment() {} //id-less Constructor used when creating Attachments
// public Attachment(int id, int taskId) {
// this.id = id;
// this.taskId = taskId;
// }
//
// public abstract AttachmentType getType();
//
// public int getId() {
// return id;
// }
// public void setId(int id) {
// this.id = id;
// }
//
// public int getTaskId() {
// return taskId;
// }
// public void setTaskId(int taskId) {
// this.taskId = taskId;
// }
//
// }
//
// Path: app/src/main/java/ve/com/abicelis/remindy/model/attachment/AudioAttachment.java
// public class AudioAttachment extends Attachment {
//
// private String audioFilename;
//
// public AudioAttachment() { /* Parameter-less constructor for audio attachment creation */ }
// public AudioAttachment(String audioFilename) {
// this.audioFilename = audioFilename;
// }
// public AudioAttachment(int id, int reminderId, String audioFilename) {
// super(id, reminderId);
// this.audioFilename = audioFilename;
// }
//
// @Override
// public AttachmentType getType() {
// return AttachmentType.AUDIO;
// }
//
// public String getAudioFilename() {
// return audioFilename;
// }
// public void setAudioFilename(String audioFilename) {
// this.audioFilename = audioFilename;
// }
// }
//
// Path: app/src/main/java/ve/com/abicelis/remindy/model/attachment/ImageAttachment.java
// public class ImageAttachment extends Attachment {
//
// private byte[] thumbnail;
// private String imageFilename;
//
// public ImageAttachment() { /* Parameter-less constructor for image attachment creation */ }
// public ImageAttachment(byte[] thumbnail, String imageFilename) {
// this.thumbnail = thumbnail;
// this.imageFilename = imageFilename;
// }
// public ImageAttachment(int id, int reminderId, byte[] thumbnail, String fullImagePath) {
// super(id, reminderId);
// this.thumbnail = thumbnail;
// this.imageFilename = fullImagePath;
// }
//
// @Override
// public AttachmentType getType() {
// return AttachmentType.IMAGE;
// }
//
//
// public byte[] getThumbnail() {
// return thumbnail;
// }
// public void setThumbnail(byte[] thumbnail) {
// this.thumbnail = thumbnail;
// }
//
// public String getImageFilename() {
// return imageFilename;
// }
// public void setImageFilename(String imageFilename) {
// this.imageFilename = imageFilename;
// }
// }
| import android.app.Activity;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import ve.com.abicelis.remindy.R;
import ve.com.abicelis.remindy.model.attachment.Attachment;
import ve.com.abicelis.remindy.model.attachment.AudioAttachment;
import ve.com.abicelis.remindy.model.attachment.ImageAttachment; |
public static File getAudioAttachmentDir(Activity activity) {
return new File(activity.getExternalFilesDir(null), activity.getResources().getString(R.string.subdirectory_attachments_audio));
}
public static File getImageAttachmentDir(Activity activity) {
return new File(activity.getExternalFilesDir(null), activity.getResources().getString(R.string.subdirectory_attachments_image));
}
public static void createDirIfNotExists(File directory) throws IOException, SecurityException {
if (directory.mkdirs()){
File nomedia = new File(directory, ".nomedia");
nomedia.createNewFile();
}
}
/**
* Creates an empty file at the specified directory, with the given name if it doesn't already exist
*
*/
public static File createNewFileIfNotExistsInDir(File directory, String fileName) throws IOException {
File file = new File(directory, fileName);
file.createNewFile();
return file;
}
/**
* Deletes the images and audio files from a list of attachments
*/ | // Path: app/src/main/java/ve/com/abicelis/remindy/model/attachment/Attachment.java
// public abstract class Attachment implements Serializable {
// private int id;
// private int taskId;
//
// public Attachment() {} //id-less Constructor used when creating Attachments
// public Attachment(int id, int taskId) {
// this.id = id;
// this.taskId = taskId;
// }
//
// public abstract AttachmentType getType();
//
// public int getId() {
// return id;
// }
// public void setId(int id) {
// this.id = id;
// }
//
// public int getTaskId() {
// return taskId;
// }
// public void setTaskId(int taskId) {
// this.taskId = taskId;
// }
//
// }
//
// Path: app/src/main/java/ve/com/abicelis/remindy/model/attachment/AudioAttachment.java
// public class AudioAttachment extends Attachment {
//
// private String audioFilename;
//
// public AudioAttachment() { /* Parameter-less constructor for audio attachment creation */ }
// public AudioAttachment(String audioFilename) {
// this.audioFilename = audioFilename;
// }
// public AudioAttachment(int id, int reminderId, String audioFilename) {
// super(id, reminderId);
// this.audioFilename = audioFilename;
// }
//
// @Override
// public AttachmentType getType() {
// return AttachmentType.AUDIO;
// }
//
// public String getAudioFilename() {
// return audioFilename;
// }
// public void setAudioFilename(String audioFilename) {
// this.audioFilename = audioFilename;
// }
// }
//
// Path: app/src/main/java/ve/com/abicelis/remindy/model/attachment/ImageAttachment.java
// public class ImageAttachment extends Attachment {
//
// private byte[] thumbnail;
// private String imageFilename;
//
// public ImageAttachment() { /* Parameter-less constructor for image attachment creation */ }
// public ImageAttachment(byte[] thumbnail, String imageFilename) {
// this.thumbnail = thumbnail;
// this.imageFilename = imageFilename;
// }
// public ImageAttachment(int id, int reminderId, byte[] thumbnail, String fullImagePath) {
// super(id, reminderId);
// this.thumbnail = thumbnail;
// this.imageFilename = fullImagePath;
// }
//
// @Override
// public AttachmentType getType() {
// return AttachmentType.IMAGE;
// }
//
//
// public byte[] getThumbnail() {
// return thumbnail;
// }
// public void setThumbnail(byte[] thumbnail) {
// this.thumbnail = thumbnail;
// }
//
// public String getImageFilename() {
// return imageFilename;
// }
// public void setImageFilename(String imageFilename) {
// this.imageFilename = imageFilename;
// }
// }
// Path: app/src/main/java/ve/com/abicelis/remindy/util/FileUtil.java
import android.app.Activity;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import ve.com.abicelis.remindy.R;
import ve.com.abicelis.remindy.model.attachment.Attachment;
import ve.com.abicelis.remindy.model.attachment.AudioAttachment;
import ve.com.abicelis.remindy.model.attachment.ImageAttachment;
public static File getAudioAttachmentDir(Activity activity) {
return new File(activity.getExternalFilesDir(null), activity.getResources().getString(R.string.subdirectory_attachments_audio));
}
public static File getImageAttachmentDir(Activity activity) {
return new File(activity.getExternalFilesDir(null), activity.getResources().getString(R.string.subdirectory_attachments_image));
}
public static void createDirIfNotExists(File directory) throws IOException, SecurityException {
if (directory.mkdirs()){
File nomedia = new File(directory, ".nomedia");
nomedia.createNewFile();
}
}
/**
* Creates an empty file at the specified directory, with the given name if it doesn't already exist
*
*/
public static File createNewFileIfNotExistsInDir(File directory, String fileName) throws IOException {
File file = new File(directory, fileName);
file.createNewFile();
return file;
}
/**
* Deletes the images and audio files from a list of attachments
*/ | public static void deleteAttachmentFiles(Activity activity, List<Attachment> attachments) { |
abicelis/Remindy | app/src/main/java/ve/com/abicelis/remindy/util/FileUtil.java | // Path: app/src/main/java/ve/com/abicelis/remindy/model/attachment/Attachment.java
// public abstract class Attachment implements Serializable {
// private int id;
// private int taskId;
//
// public Attachment() {} //id-less Constructor used when creating Attachments
// public Attachment(int id, int taskId) {
// this.id = id;
// this.taskId = taskId;
// }
//
// public abstract AttachmentType getType();
//
// public int getId() {
// return id;
// }
// public void setId(int id) {
// this.id = id;
// }
//
// public int getTaskId() {
// return taskId;
// }
// public void setTaskId(int taskId) {
// this.taskId = taskId;
// }
//
// }
//
// Path: app/src/main/java/ve/com/abicelis/remindy/model/attachment/AudioAttachment.java
// public class AudioAttachment extends Attachment {
//
// private String audioFilename;
//
// public AudioAttachment() { /* Parameter-less constructor for audio attachment creation */ }
// public AudioAttachment(String audioFilename) {
// this.audioFilename = audioFilename;
// }
// public AudioAttachment(int id, int reminderId, String audioFilename) {
// super(id, reminderId);
// this.audioFilename = audioFilename;
// }
//
// @Override
// public AttachmentType getType() {
// return AttachmentType.AUDIO;
// }
//
// public String getAudioFilename() {
// return audioFilename;
// }
// public void setAudioFilename(String audioFilename) {
// this.audioFilename = audioFilename;
// }
// }
//
// Path: app/src/main/java/ve/com/abicelis/remindy/model/attachment/ImageAttachment.java
// public class ImageAttachment extends Attachment {
//
// private byte[] thumbnail;
// private String imageFilename;
//
// public ImageAttachment() { /* Parameter-less constructor for image attachment creation */ }
// public ImageAttachment(byte[] thumbnail, String imageFilename) {
// this.thumbnail = thumbnail;
// this.imageFilename = imageFilename;
// }
// public ImageAttachment(int id, int reminderId, byte[] thumbnail, String fullImagePath) {
// super(id, reminderId);
// this.thumbnail = thumbnail;
// this.imageFilename = fullImagePath;
// }
//
// @Override
// public AttachmentType getType() {
// return AttachmentType.IMAGE;
// }
//
//
// public byte[] getThumbnail() {
// return thumbnail;
// }
// public void setThumbnail(byte[] thumbnail) {
// this.thumbnail = thumbnail;
// }
//
// public String getImageFilename() {
// return imageFilename;
// }
// public void setImageFilename(String imageFilename) {
// this.imageFilename = imageFilename;
// }
// }
| import android.app.Activity;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import ve.com.abicelis.remindy.R;
import ve.com.abicelis.remindy.model.attachment.Attachment;
import ve.com.abicelis.remindy.model.attachment.AudioAttachment;
import ve.com.abicelis.remindy.model.attachment.ImageAttachment; | public static File getImageAttachmentDir(Activity activity) {
return new File(activity.getExternalFilesDir(null), activity.getResources().getString(R.string.subdirectory_attachments_image));
}
public static void createDirIfNotExists(File directory) throws IOException, SecurityException {
if (directory.mkdirs()){
File nomedia = new File(directory, ".nomedia");
nomedia.createNewFile();
}
}
/**
* Creates an empty file at the specified directory, with the given name if it doesn't already exist
*
*/
public static File createNewFileIfNotExistsInDir(File directory, String fileName) throws IOException {
File file = new File(directory, fileName);
file.createNewFile();
return file;
}
/**
* Deletes the images and audio files from a list of attachments
*/
public static void deleteAttachmentFiles(Activity activity, List<Attachment> attachments) {
for (Attachment attachment : attachments) {
switch (attachment.getType()) {
case AUDIO: | // Path: app/src/main/java/ve/com/abicelis/remindy/model/attachment/Attachment.java
// public abstract class Attachment implements Serializable {
// private int id;
// private int taskId;
//
// public Attachment() {} //id-less Constructor used when creating Attachments
// public Attachment(int id, int taskId) {
// this.id = id;
// this.taskId = taskId;
// }
//
// public abstract AttachmentType getType();
//
// public int getId() {
// return id;
// }
// public void setId(int id) {
// this.id = id;
// }
//
// public int getTaskId() {
// return taskId;
// }
// public void setTaskId(int taskId) {
// this.taskId = taskId;
// }
//
// }
//
// Path: app/src/main/java/ve/com/abicelis/remindy/model/attachment/AudioAttachment.java
// public class AudioAttachment extends Attachment {
//
// private String audioFilename;
//
// public AudioAttachment() { /* Parameter-less constructor for audio attachment creation */ }
// public AudioAttachment(String audioFilename) {
// this.audioFilename = audioFilename;
// }
// public AudioAttachment(int id, int reminderId, String audioFilename) {
// super(id, reminderId);
// this.audioFilename = audioFilename;
// }
//
// @Override
// public AttachmentType getType() {
// return AttachmentType.AUDIO;
// }
//
// public String getAudioFilename() {
// return audioFilename;
// }
// public void setAudioFilename(String audioFilename) {
// this.audioFilename = audioFilename;
// }
// }
//
// Path: app/src/main/java/ve/com/abicelis/remindy/model/attachment/ImageAttachment.java
// public class ImageAttachment extends Attachment {
//
// private byte[] thumbnail;
// private String imageFilename;
//
// public ImageAttachment() { /* Parameter-less constructor for image attachment creation */ }
// public ImageAttachment(byte[] thumbnail, String imageFilename) {
// this.thumbnail = thumbnail;
// this.imageFilename = imageFilename;
// }
// public ImageAttachment(int id, int reminderId, byte[] thumbnail, String fullImagePath) {
// super(id, reminderId);
// this.thumbnail = thumbnail;
// this.imageFilename = fullImagePath;
// }
//
// @Override
// public AttachmentType getType() {
// return AttachmentType.IMAGE;
// }
//
//
// public byte[] getThumbnail() {
// return thumbnail;
// }
// public void setThumbnail(byte[] thumbnail) {
// this.thumbnail = thumbnail;
// }
//
// public String getImageFilename() {
// return imageFilename;
// }
// public void setImageFilename(String imageFilename) {
// this.imageFilename = imageFilename;
// }
// }
// Path: app/src/main/java/ve/com/abicelis/remindy/util/FileUtil.java
import android.app.Activity;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import ve.com.abicelis.remindy.R;
import ve.com.abicelis.remindy.model.attachment.Attachment;
import ve.com.abicelis.remindy.model.attachment.AudioAttachment;
import ve.com.abicelis.remindy.model.attachment.ImageAttachment;
public static File getImageAttachmentDir(Activity activity) {
return new File(activity.getExternalFilesDir(null), activity.getResources().getString(R.string.subdirectory_attachments_image));
}
public static void createDirIfNotExists(File directory) throws IOException, SecurityException {
if (directory.mkdirs()){
File nomedia = new File(directory, ".nomedia");
nomedia.createNewFile();
}
}
/**
* Creates an empty file at the specified directory, with the given name if it doesn't already exist
*
*/
public static File createNewFileIfNotExistsInDir(File directory, String fileName) throws IOException {
File file = new File(directory, fileName);
file.createNewFile();
return file;
}
/**
* Deletes the images and audio files from a list of attachments
*/
public static void deleteAttachmentFiles(Activity activity, List<Attachment> attachments) {
for (Attachment attachment : attachments) {
switch (attachment.getType()) {
case AUDIO: | String audioFilename = ((AudioAttachment)attachment).getAudioFilename(); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.