/* * 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 { STATIC = false; UNICODE_INPUT = true; ERROR_REPORTING = true; MULTI = true; VISITOR = true; NODE_DEFAULT_VOID = true; NODE_EXTENDS = "NodeSupport"; } // // TODO: Look at including bits from the Jexl parser here // /////////////////////////////////////////////////////////////////////////////// PARSER_BEGIN(CommandLineParser) package org.apache.geronimo.gshell.parser; import java.io.Reader; import java.io.StringReader; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.codehaus.plexus.component.annotations.Component; /** * Command line parser. * * @version $Rev$ $Date$ */ @Component(role=CommandLineParser.class) public class CommandLineParser extends CommandLineParserSupport { private final Logger log = LoggerFactory.getLogger(getClass()); public CommandLineParser() { this(new StringReader("")); } public ASTCommandLine parse(final Reader reader) throws ParseException { assert reader != null; log.debug("Parsing from reader: {}", reader); this.ReInit(reader); return this.commandLine(); } } PARSER_END(CommandLineParser) /////////////////////////////////////////////////////////////////////////////// // // WHITE SPACE // SKIP : { " " | "\t" | "\n" | "\r" | "\f" } // // COMMENTS // SPECIAL_TOKEN : { < COMMENT: "#" (~["\n", "\r"])* ("\n" | "\r" | "\r\n")? > } // // STRINGS // TOKEN : { < STRING: ( (~["\"","\\"," ","\t","\n","\r","\f",";","\"","'"]) | ("\\" ( ["n","t","b","r","f","\\","'","\"",";"] | ["0"-"7"] ( ["0"-"7"] )? | ["0"-"3"] ["0"-"7"] ["0"-"7"] ) ) | ( "=" ( ) ) | ( "=" ( ) ) )+ > | < OPAQUE_STRING: "'" ( (~["\"","\\","\n","\r"]) | ("\\" ( ["n","t","b","r","f","\\","'","\""] | ["0"-"7"] ( ["0"-"7"] )? | ["0"-"3"] ["0"-"7"] ["0"-"7"] ) ) )* "'" > | < QUOTED_STRING: "\"" ( (~["\"","\\","\n","\r"]) | ("\\" ( ["n","t","b","r","f","\\","'","\""] | ["0"-"7"] ( ["0"-"7"] )? | ["0"-"3"] ["0"-"7"] ["0"-"7"] ) ) )* "\"" > | < SET_QUOTED_STRING > } // // SEPARATORS // TOKEN : { < SEMICOLON: ";" > } /////////////////////////////////////////////////////////////////////////////// ASTCommandLine commandLine() #CommandLine: {} { ( expression() ( ";" [ expression() ] )* | ) { return jjtThis; } } void expression() #Expression: {} { ( argument() )+ } void argument() #void: {} { string() // // TODO: Add variable() to resolve raw $xxx or ${xxx} // quoted string will have to post parse these values // into strings, but raw could potentially return object // references // } void string() #void: {} { quotedString() | opaqueString() | plainString() } void quotedString() #QuotedString: { Token t; } { t= { jjtThis.setToken(t); } } void opaqueString() #OpaqueString: { Token t; } { t= { jjtThis.setToken(t); } } void plainString() #PlainString: { Token t; } { t= { jjtThis.setToken(t); } }