Search in sources :

Example 6 with AStringExpression

use of de.be4.classicalb.core.parser.node.AStringExpression in project probparsers by bendisposto.

the class RulesMachineChecker method checkTagsAttribute.

private void checkTagsAttribute(POperationAttribute pOperationAttribute, LinkedList<PExpression> arguments) {
    final List<String> tags = new ArrayList<>();
    for (PExpression pExpression : arguments) {
        if (pExpression instanceof AIdentifierExpression) {
            final AIdentifierExpression ident = (AIdentifierExpression) pExpression;
            final String identifierAsString = Utils.getTIdentifierListAsString(ident.getIdentifier());
            tags.add(identifierAsString);
        } else if (pExpression instanceof AStringExpression) {
            final AStringExpression stringExpr = (AStringExpression) pExpression;
            tags.add(stringExpr.getContent().getText());
        } else {
            errorList.add(new CheckException("Expected identifier or string after the TAGS attribute.", pOperationAttribute));
        }
    }
    currentOperation.addTags(tags);
    return;
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) ArrayList(java.util.ArrayList) AStringExpression(de.be4.classicalb.core.parser.node.AStringExpression) PExpression(de.be4.classicalb.core.parser.node.PExpression)

Example 7 with AStringExpression

use of de.be4.classicalb.core.parser.node.AStringExpression in project probparsers by bendisposto.

the class SyntaxExtensionTranslator method caseAMultilineStringExpression.

@Override
public void caseAMultilineStringExpression(AMultilineStringExpression node) {
    final TMultilineStringContent content = node.getContent();
    final String text = content.getText();
    TStringLiteral tStringLiteral = new TStringLiteral(text, content.getLine(), content.getPos());
    AStringExpression stringNode = new AStringExpression(tStringLiteral);
    stringNode.setStartPos(node.getStartPos());
    stringNode.setEndPos(node.getEndPos());
    node.replaceBy(stringNode);
}
Also used : TMultilineStringContent(de.be4.classicalb.core.parser.node.TMultilineStringContent) TStringLiteral(de.be4.classicalb.core.parser.node.TStringLiteral) AStringExpression(de.be4.classicalb.core.parser.node.AStringExpression)

Example 8 with AStringExpression

use of de.be4.classicalb.core.parser.node.AStringExpression in project probparsers by bendisposto.

the class ASTBuilder method addChooseDefinition.

public static void addChooseDefinition(IDefinitions iDefinitions) {
    if (iDefinitions.containsDefinition(CHOOSE)) {
        return;
    }
    /*-
		 * TO_STRING(S) == "0";
		 * EXTERNAL_FUNCTION_TO_STRING(X) == (X --> STRING);
		 */
    AExpressionDefinitionDefinition chooseDef = new AExpressionDefinitionDefinition();
    chooseDef.setName(new TIdentifierLiteral(CHOOSE));
    chooseDef.setParameters(createIdentifierList("X"));
    chooseDef.setRhs(new AStringExpression(new TStringLiteral("a member of X")));
    iDefinitions.addDefinition(chooseDef, IDefinitions.Type.Expression);
    AExpressionDefinitionDefinition chooseDefType = new AExpressionDefinitionDefinition();
    chooseDefType.setName(new TIdentifierLiteral("EXTERNAL_FUNCTION_CHOOSE"));
    chooseDefType.setParameters(createIdentifierList("T"));
    chooseDefType.setRhs(new ATotalFunctionExpression(new APowSubsetExpression(createIdentifier("T")), createIdentifier("T")));
    iDefinitions.addDefinition(chooseDefType, IDefinitions.Type.Expression);
}
Also used : APowSubsetExpression(de.be4.classicalb.core.parser.node.APowSubsetExpression) AExpressionDefinitionDefinition(de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition) AStringExpression(de.be4.classicalb.core.parser.node.AStringExpression) TStringLiteral(de.be4.classicalb.core.parser.node.TStringLiteral) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral) ATotalFunctionExpression(de.be4.classicalb.core.parser.node.ATotalFunctionExpression)

Example 9 with AStringExpression

use of de.be4.classicalb.core.parser.node.AStringExpression in project probparsers by bendisposto.

the class RulesMachineChecker method countPlaceHoldersInExpression.

private Integer countPlaceHoldersInExpression(PExpression param) {
    if (param instanceof AConcatExpression) {
        AConcatExpression con = (AConcatExpression) param;
        Integer left = countPlaceHoldersInExpression(con.getLeft());
        Integer right = countPlaceHoldersInExpression(con.getRight());
        if (left == null || right == null) {
            return null;
        } else {
            return left + right;
        }
    } else if (param instanceof AStringExpression) {
        AStringExpression string = (AStringExpression) param;
        String content = string.getContent().getText();
        String subString = "~w";
        return countOccurrences(content, subString);
    } else {
        return null;
    }
}
Also used : AConcatExpression(de.be4.classicalb.core.parser.node.AConcatExpression) AStringExpression(de.be4.classicalb.core.parser.node.AStringExpression)

Example 10 with AStringExpression

use of de.be4.classicalb.core.parser.node.AStringExpression in project probparsers by bendisposto.

the class LTLFormulaVisitor method parseDefinition.

public void parseDefinition(AExpressionDefinitionDefinition def) {
    if (!(def.getRhs() instanceof AStringExpression)) {
        throw new LTLParseException("Error: LTL formula is not in a string representation.");
    }
    AStringExpression stringNode = (AStringExpression) def.getRhs();
    this.ltlFormula = stringNode.getContent().getText();
    try {
        this.ltlFormulaStart = parseLTLFormula(ltlFormula);
    } catch (Exception e) {
        String message = "Parsing definition " + name + " (line " + def.getStartPos().getLine() + "):\n";
        throw new LTLParseException(message + e.getMessage());
    }
}
Also used : LTLParseException(de.prob.typechecker.exceptions.LTLParseException) AStringExpression(de.be4.classicalb.core.parser.node.AStringExpression) LexerException(de.be4.ltl.core.parser.lexer.LexerException) ParserException(de.be4.ltl.core.parser.parser.ParserException) ScopeException(de.prob.typechecker.exceptions.ScopeException) LTLParseException(de.prob.typechecker.exceptions.LTLParseException) IOException(java.io.IOException) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException)

Aggregations

AStringExpression (de.be4.classicalb.core.parser.node.AStringExpression)10 TStringLiteral (de.be4.classicalb.core.parser.node.TStringLiteral)7 TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)4 AExpressionDefinitionDefinition (de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition)3 AIdentifierExpression (de.be4.classicalb.core.parser.node.AIdentifierExpression)3 ATotalFunctionExpression (de.be4.classicalb.core.parser.node.ATotalFunctionExpression)3 CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)2 AEqualPredicate (de.be4.classicalb.core.parser.node.AEqualPredicate)2 AStringSetExpression (de.be4.classicalb.core.parser.node.AStringSetExpression)2 PExpression (de.be4.classicalb.core.parser.node.PExpression)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 BCompoundException (de.be4.classicalb.core.parser.exceptions.BCompoundException)1 AConcatExpression (de.be4.classicalb.core.parser.node.AConcatExpression)1 AMultOrCartExpression (de.be4.classicalb.core.parser.node.AMultOrCartExpression)1 APowSubsetExpression (de.be4.classicalb.core.parser.node.APowSubsetExpression)1 APropertiesMachineClause (de.be4.classicalb.core.parser.node.APropertiesMachineClause)1 ASeqExpression (de.be4.classicalb.core.parser.node.ASeqExpression)1 PPredicate (de.be4.classicalb.core.parser.node.PPredicate)1 TMultilineStringContent (de.be4.classicalb.core.parser.node.TMultilineStringContent)1