X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.basicexpression%2Fsrc%2Forg%2Fsimantics%2Fbasicexpression%2FExpressions.java;h=51dae6c3698c61ded4bed6b9b8eae6b4be85520a;hp=a3e4ff5690e6499239432f564dad4df181c1c444;hb=a43df9e895f022132f9b94dfedeae78fb4eed712;hpb=969bd23cab98a79ca9101af33334000879fb60c5 diff --git a/bundles/org.simantics.basicexpression/src/org/simantics/basicexpression/Expressions.java b/bundles/org.simantics.basicexpression/src/org/simantics/basicexpression/Expressions.java index a3e4ff569..51dae6c36 100644 --- a/bundles/org.simantics.basicexpression/src/org/simantics/basicexpression/Expressions.java +++ b/bundles/org.simantics.basicexpression/src/org/simantics/basicexpression/Expressions.java @@ -1,56 +1,61 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.basicexpression; - -import java.io.PushbackReader; -import java.io.StringReader; - -import org.simantics.basicexpression.analysis.DepthFirstAdapter; -import org.simantics.basicexpression.lexer.Lexer; -import org.simantics.basicexpression.node.Start; -import org.simantics.basicexpression.parser.Parser; - -public class Expressions { - - private static final boolean DEBUG = false; - - public static void evaluate(String expression, DepthFirstAdapter evaluator) { - - try - { - // Create a Parser instance. - Parser p = - new Parser( - new Lexer( - new PushbackReader(new StringReader(expression)))); - - // Parse the input. - Start tree = p.parse(); - - if(DEBUG) - tree.apply(new PrettyPrintExpressionVisitor()); - -// System.out.println("tree=" + tree.getClass().getName()); - - // Apply the translation. - tree.apply(evaluator); - - } - catch(Exception e) - { - e.printStackTrace(); - evaluator.except(e); - } - - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.basicexpression; + +import java.io.PushbackReader; +import java.io.StringReader; + +import org.simantics.basicexpression.analysis.DepthFirstAdapter; +import org.simantics.basicexpression.lexer.Lexer; +import org.simantics.basicexpression.node.Start; +import org.simantics.basicexpression.parser.Parser; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class Expressions { + + private static final Logger LOGGER = LoggerFactory.getLogger(Expressions.class); + + private static final boolean DEBUG = false; + + public static void evaluate(String expression, DepthFirstAdapter evaluator) { + + try + { + // Create a Parser instance. + Parser p = + new Parser( + new Lexer( + new PushbackReader(new StringReader(expression)))); + + // Parse the input. + Start tree = p.parse(); + + if(DEBUG) + tree.apply(new PrettyPrintExpressionVisitor()); + +// System.out.println("tree=" + tree.getClass().getName()); + + // Apply the translation. + tree.apply(evaluator); + + } + catch(Exception e) + { + if (LOGGER.isDebugEnabled()) + LOGGER.debug("Failed to evaluate expression {}", expression, e); + evaluator.except(e); + } + + } + +}