blob: bb9867cd26e1d657cb5548f015e700b698557221 [file] [log] [blame]
/*
* 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;
}
//
// 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;
/**
* Command line parser.
*
* @version $Rev$ $Date$
*/
public class CommandLineParser
{
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
//
<DEFAULT> SKIP :
{
" "
| "\t"
| "\n"
| "\r"
| "\f"
}
//
// COMMENTS
//
<DEFAULT> SPECIAL_TOKEN :
{
< COMMENT: "#" (~["\n", "\r"])* ("\n" | "\r" | "\r\n")? >
}
//
// STRINGS
//
<DEFAULT> TOKEN :
{
< STRING:
( (~["\"","\\"," ","\t","\n","\r","\f",";","|","\"","'"])
| ("\\"
( ["n","t","b","r","f","\\","'","\"",";"]
| ["0"-"7"] ( ["0"-"7"] )?
| ["0"-"3"] ["0"-"7"] ["0"-"7"]
)
)
| ( "="
( <QUOTED_STRING> )
)
| ( "="
( <OPAQUE_STRING> )
)
)+
>
|
< 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
//
<DEFAULT> TOKEN :
{
< SEMICOLON: ";" >
}
<DEFAULT> TOKEN :
{
< PIPE: "|" >
}
///////////////////////////////////////////////////////////////////////////////
ASTCommandLine commandLine() #CommandLine: {}
{
(
expression() ( ";" [ expression() ] )* | <EOF>
)
{
return jjtThis;
}
}
void expression() #Expression: {}
{
(
process() ( "|" [ process() ] )*
)
}
void process() #Process: {}
{
( 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=<QUOTED_STRING>
{
jjtThis.setToken(t);
}
}
void opaqueString() #OpaqueString:
{
Token t;
}
{
t=<OPAQUE_STRING>
{
jjtThis.setToken(t);
}
}
void plainString() #PlainString:
{
Token t;
}
{
t=<STRING>
{
jjtThis.setToken(t);
}
}