|
ActiveMQ example source code file (SelectorParser.jj)
The ActiveMQ SelectorParser.jj source code/** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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. */ // ---------------------------------------------------------------------------- // OPTIONS // ---------------------------------------------------------------------------- options { STATIC = false; UNICODE_INPUT = true; // some performance optimizations OPTIMIZE_TOKEN_MANAGER = true; ERROR_REPORTING = false; } // ---------------------------------------------------------------------------- // PARSER // ---------------------------------------------------------------------------- PARSER_BEGIN(SelectorParser) /** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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 org.apache.activemq.selector; import java.io.*; import java.util.*; import javax.jms.InvalidSelectorException; import org.apache.activemq.filter.*; import org.apache.activemq.util.LRUCache; /** * JMS Selector Parser generated by JavaCC * * Do not edit this .java file directly - it is autogenerated from SelectorParser.jj */ public class SelectorParser { private static final Map cache = Collections.synchronizedMap(new LRUCache(100)); public static BooleanExpression parse(String sql) throws InvalidSelectorException { Object result = cache.get(sql); if (result instanceof InvalidSelectorException) { throw (InvalidSelectorException) result; } else if (result instanceof BooleanExpression) { return (BooleanExpression) result; } else { try { BooleanExpression e = new SelectorParser(sql).parse(); cache.put(sql, e); return e; } catch (InvalidSelectorException t) { cache.put(sql, t); throw t; } } } public static void clearCache() { cache.clear(); } private String sql; protected SelectorParser(String sql) { this(new StringReader(sql)); this.sql = sql; } protected BooleanExpression parse() throws InvalidSelectorException { try { return this.JmsSelector(); } catch (Throwable e) { throw (InvalidSelectorException) new InvalidSelectorException(sql).initCause(e); } } private BooleanExpression asBooleanExpression(Expression value) throws ParseException { if (value instanceof BooleanExpression) { return (BooleanExpression) value; } if (value instanceof PropertyExpression) { return UnaryExpression.createBooleanCast( value ); } throw new ParseException("Expression will not result in a boolean value: " + value); } } PARSER_END(SelectorParser) // ---------------------------------------------------------------------------- // Tokens // ---------------------------------------------------------------------------- /* White Space */ SPECIAL_TOKEN : { " " | "\t" | "\n" | "\r" | "\f" } /* Comments */ SKIP: { <LINE_COMMENT: "--" (~["\n","\r"])* ("\n"|"\r"|"\r\n") > } SKIP: { <BLOCK_COMMENT: "/*" (~["*"])* "*" ("*" | (~["*","/"] (~["*"])* "*"))* "/"> } /* Reserved Words */ TOKEN [IGNORE_CASE] : { < NOT : "NOT"> | < AND : "AND"> | < OR : "OR"> | < BETWEEN : "BETWEEN"> | < LIKE : "LIKE"> | < ESCAPE : "ESCAPE"> | < IN : "IN"> | < IS : "IS"> | < TRUE : "TRUE" > | < FALSE : "FALSE" > | < NULL : "NULL" > | < XPATH : "XPATH" > | < XQUERY : "XQUERY" > } /* Literals */ TOKEN [IGNORE_CASE] : { < DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* (["l","L"])? > | < HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ > | < OCTAL_LITERAL: "0" (["0"-"7"])* > | < FLOATING_POINT_LITERAL: (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? // matches: 5.5 or 5. or 5.5E10 or 5.E10 | "." (["0"-"9"])+ (<EXPONENT>)? // matches: .5 or .5E10 | (["0"-"9"])+ <EXPONENT> // matches: 5E10 > | < #EXPONENT: "E" (["+","-"])? (["0"-"9"])+ > | < STRING_LITERAL: "'" ( ("''") | ~["'"] )* "'" > } TOKEN [IGNORE_CASE] : { < ID : ["a"-"z", "_", "$"] (["a"-"z","0"-"9","_", "$"])* > } // ---------------------------------------------------------------------------- // Grammer // ---------------------------------------------------------------------------- BooleanExpression JmsSelector() : { Expression left=null; } { ( left = orExpression() ) { return asBooleanExpression(left); } } Expression orExpression() : { Expression left; Expression right; } { ( left = andExpression() ( <OR> right = andExpression() { left = LogicExpression.createOR(asBooleanExpression(left), asBooleanExpression(right)); } )* ) { return left; } } Expression andExpression() : { Expression left; Expression right; } { ( left = equalityExpression() ( <AND> right = equalityExpression() { left = LogicExpression.createAND(asBooleanExpression(left), asBooleanExpression(right)); } )* ) { return left; } } Expression equalityExpression() : { Expression left; Expression right; } { ( left = comparisonExpression() ( "=" right = comparisonExpression() { left = ComparisonExpression.createEqual(left, right); } | "<>" right = comparisonExpression() { left = ComparisonExpression.createNotEqual(left, right); } | LOOKAHEAD(2) <IS> Other ActiveMQ examples (source code examples)Here is a short list of links related to this ActiveMQ SelectorParser.jj source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.