You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by ju...@apache.org on 2002/02/20 22:56:23 UTC
cvs commit: jakarta-turbine-maven/src/java/org/apache/maven/jrcs/rcs ArchiveParser.jj
juanco 02/02/20 13:56:23
Added: src/java/org/apache/maven/jrcs/rcs ArchiveParser.jj
Log:
Added original source for the JavaCC grammar that generates the RCS parser.
Revision Changes Path
1.1 jakarta-turbine-maven/src/java/org/apache/maven/jrcs/rcs/ArchiveParser.jj
Index: ArchiveParser.jj
===================================================================
/** $Id: ArchiveParser.jj,v 1.1 2002/02/20 21:56:23 juanco Exp $
*
* RCS (Revision Control System) archive parsing and manipulation in Java.
* Copyright (C) 1999-2001 Juancarlo A�ez, Caracas, Venezuela.
* http://www.suigeneris.org/juanca
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
options {
COMMON_TOKEN_ACTION=false;
CHOICE_AMBIGUITY_CHECK=2;
BUILD_PARSER=true;
BUILD_TOKEN_MANAGER=true;
OPTIMIZE_TOKEN_MANAGER=true;
DEBUG_TOKEN_MANAGER=false;
CACHE_TOKENS=true;
DEBUG_LOOKAHEAD=false;
DEBUG_PARSER=false;
ERROR_REPORTING=false;
FORCE_LA_CHECK=false;
IGNORE_CASE=false;
JAVA_UNICODE_ESCAPE=true;
LOOKAHEAD=1;
OTHER_AMBIGUITY_CHECK=1;
SANITY_CHECK=true;
STATIC=false;
UNICODE_INPUT=false;
USER_CHAR_STREAM=false;
USER_TOKEN_MANAGER=false;
}
PARSER_BEGIN(ArchiveParser)
/** $Id: ArchiveParser.jj,v 1.1 2002/02/20 21:56:23 juanco Exp $
*
* RCS for Java(tm)
* Copiright (c) 1999 Juancarlo A�ez.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.suigeneris.rcs;
import java.util.*;
class ArchiveParser {
static final String ident = "RCS ArchiveParser Parser $version$:";
public static void main(String args[]) {
ArchiveParser parser;
if (args.length == 0) {
System.out.println(ident + " Reading from standard input . . .");
parser = new ArchiveParser(System.in);
} else if (args.length == 1) {
System.out.println(ident + " Reading from file " + args[0] + " . . .");
try {
parser = new ArchiveParser(new java.io.FileInputStream(args[0]));
} catch (java.io.FileNotFoundException e) {
System.out.println(ident + " File " + args[0] + " not found.");
return;
}
} else {
System.out.println(ident+" Usage is one of:");
System.out.println(" java ArchiveParser < inputfile");
System.out.println("OR");
System.out.println(" java ArchiveParser inputfile");
return;
}
parser.parse();
}
public static void load(Archive arc, java.io.InputStream input) throws ParseException {
ArchiveParser parser = new ArchiveParser(input);
parser.archive(arc);
}
public static void load(Archive arc, String fname) throws java.io.FileNotFoundException, ParseException {
load(arc, new java.io.FileInputStream(fname) );
}
public void parse() {
try {
archive(null);
System.out.println("RCS ArchiveParser Parser version 1.1: RCS ArchiveParser parsed successfully.");
} catch (ParseException e) {
System.out.println("RCS ArchiveParser Parser version 1.1: Encountered errors during parse.");
}
}
}
PARSER_END(ArchiveParser)
<DEFAULT,PRE_DELTA> SKIP : /* WHITE SPACE */
{
" "
| "\n"
| "\t"
| "\r"
| "\f"
}
TOKEN : /* keywords */
{
< ACCESS: "access" >
|
< AUTHOR: "author" >
|
< BRANCH: "branch" >
|
< BRANCHES: "branches" >
|
< COMMENT: "comment" >
|
< DATE: "date" >
|
< DESC: "desc" >
|
< EXPAND: "expand" >
|
< HEAD : "head" >
|
< LOCKS: "locks" >
|
< LOG: "log" >
|
< NEXT: "next" >
|
< STATE: "state">
|
< STRICT: "strict">
|
< SYMBOLS: "symbols" >
|
< TEXT: "text" >
}
TOKEN :
{
< ID: <SYM> >
|
< SYM: (<DIGIT>)* <IDCHAR> (<IDCHAR>|<DIGIT>)* >
|
< IDCHAR : <LETTER> >
|
< STRING: "@" ( ~["@"] | "@@" )* "@" >
|
< #LETTER:
[
"\u0024",
"\u0041"-"\u005a",
"\u005f",
"\u0061"-"\u007a",
"\u00c0"-"\u00d6",
"\u00d8"-"\u00f6",
"\u00f8"-"\u00ff",
"\u0100"-"\u1fff",
"\u3040"-"\u318f",
"\u3300"-"\u337f",
"\u3400"-"\u3d2d",
"\u4e00"-"\u9fff",
"\uf900"-"\ufaff"
]
>
|
< #DIGIT: ["0"-"9"] >
|
< NUM: ( <DIGIT> )+ >
}
/**
* PARSER STARTS HERE
*/
void archive(Archive arc) :
{}
{
admin(arc)
( delta(arc) )*
desc(arc)
( text(arc) )*
<EOF>
}
void admin(Archive arc) :
{}
{
head(arc)
[ branch(arc) ]
access(arc)
symbols(arc)
locks(arc)
optionals(arc)
}
void optionals(Archive arc) :
{}
{
( comment(arc)
| expand(arc)
| newPhrase(arc._phrases)
)*
}
void newPhrases(Map map) :
{}
{
( newPhrase(map) )*
}
void head(Archive arc) :
{
Version v;
}
{ <HEAD> [ v = version() { arc.setHead(v); } ] ";"
}
void branch(Archive arc) :
{ Version v;
}
{ <BRANCH> [ v = version() { arc.setBranch(v); } ] ";"
}
void access(Archive arc) :
{
String name;
}
{ <ACCESS> ( name = id() { arc.addUser(name);} )* ";"
}
void symbols(Archive arc) :
{
String s;
Version v;
}
{ <SYMBOLS> ( s = sym() ":" v = version() { arc.addSymbol(s, v); }
)* ";"
}
void locks(Archive arc) :
{
String name;
Version v;
}
{ <LOCKS> ( name = id() ":" v = version() { arc.addLock(name, v);} )* ";"
[<STRICT> ";" {arc.setStrictLocking(true); } ]
}
void comment(Archive arc) :
{ String s; }
{ <COMMENT> [ s = string() {arc.setComment(s);} ] ";"
}
void expand(Archive arc) :
{String s;}
{ <EXPAND> [ s = string() {arc.setExpand(s);} ] ";"
}
void newPhrase(Map map) :
{ String key;
String value;
StringBuffer values = new StringBuffer();
}
{ key = id()
( value = word() { values.append(" " + value); }
)*
";"
{ if (map != null) map.put(key, values.toString()); }
}
String word():
{ String result; }
{ (
LOOKAHEAD(2)
result = pair()
|
result = simpleWord()
)
{return result;}
}
String simpleWord() :
{
String result;
Version v;
}
{
(
result = id()
|
v = version() { result = v.toString(); }
|
result = string()
)
{ return result; }
}
String pair() :
{
String left;
String right;
}
{
left = simpleWord() ":" right = simpleWord()
{ return left + ":" + right; }
}
void desc(Archive arc) :
{ String s; }
{
<DESC> s = string() { arc.setDesc(s); }
}
void delta(Archive arc) :
{
Version v;
Node node;
int[] d;
String s;
}
{
v = version()
{ node = arc.newNode(v); }
<DATE> d = date() { node.setDate(d); } ";"
<AUTHOR> s = id() { node.setAuthor(s); } ";"
<STATE> [ s = id() { node.setState(s); } ] ";"
<BRANCHES> ( v = version() { node.addBranch(arc.newBranchNode(v)); } )* ";"
<NEXT> [ v = version() { node.setRCSNext(arc.newNode(v));} ] ";"
newPhrases(node._phrases)
}
void text(Archive arc) :
{
Version v;
Node node;
String log;
String txt;
}
{
v = version()
{
node = arc.findNode(v);
}
<LOG> log = string()
{
node.setLog(log);
}
newPhrases(node._phrases)
<TEXT> txt = string()
{
node.setText(txt);
}
}
String id() : {Token t; } { t = <ID> { return t.image; } }
String sym() :
{
Token t;
}
{
( t = <SYM>
|
t = <ID>
)
{ return t.image; }
}
Version version() :
{
Version v;
int n, r;
}
{
n = num()
{ v = new Version(n); }
( "." n = num() { v.__addBranch(n); } )*
{ return v; }
}
int[] date() :
{
int[] n = new int[6];
}
{
n[0] = num() "."
n[1] = num() "."
n[2] = num() "."
n[3] = num() "."
n[4] = num() "."
n[5] = num()
{return n; }
}
int num() : { Token t; } {t = <NUM> { return Integer.parseInt(t.image);} }
String string() :
{Token t;}
{
t = <STRING> { return Archive.unquoteString(t.image); }
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>