From f89fe8b37d8f6ed158b8cef54998a9ad5f395072 Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 13 Oct 2009 06:58:23 +0000 Subject: [PATCH] add LogWriter interface to enable switch log format git-svn-id: http://www.xerial.org/svn/project/XerialJ/trunk/xerial-core@3634 ae02f08e-27ec-0310-ae8c-8ba02fe2eafd --- .../java/org/xerial/lens/relation/NodeBase.java | 4 +- src/main/java/org/xerial/lens/relation/Tuple.java | 10 +- .../org/xerial/lens/relation/TupleElement.java | 12 +- .../xerial/lens/relation/query/impl/LensQuery.g | 27 +- .../lens/relation/query/impl/LensQuery.tokens | 81 +++--- .../lens/relation/query/impl/LensQueryLexer.java | 323 ++++++++++----------- .../lens/relation/query/impl/LensQueryParser.java | 320 ++++++++++---------- .../lens/relation/query/lang/RelationExpr.java | 7 +- src/main/java/org/xerial/silk/SilkWriter.java | 45 ++- src/main/java/org/xerial/silk/cui/SilkMain.java | 59 ++-- src/main/java/org/xerial/util/log/LogWriter.java | 39 +++ src/main/java/org/xerial/util/log/Logger.java | 220 +++++--------- .../java/org/xerial/util/log/SilkLogWriter.java | 72 +++++ .../java/org/xerial/util/log/SimpleLogWriter.java | 92 ++++++ src/test/java/org/xerial/lens/LensTest.java | 15 +- src/test/java/org/xerial/silk/SilkWriterTest.java | 18 ++ 16 files changed, 735 insertions(+), 609 deletions(-) create mode 100644 src/main/java/org/xerial/util/log/LogWriter.java create mode 100644 src/main/java/org/xerial/util/log/SilkLogWriter.java create mode 100644 src/main/java/org/xerial/util/log/SimpleLogWriter.java diff --git a/src/main/java/org/xerial/lens/relation/NodeBase.java b/src/main/java/org/xerial/lens/relation/NodeBase.java index 90260e8..8730583 100644 --- a/src/main/java/org/xerial/lens/relation/NodeBase.java +++ b/src/main/java/org/xerial/lens/relation/NodeBase.java @@ -38,7 +38,7 @@ import org.xerial.core.XerialErrorCode; public abstract class NodeBase implements TupleElement { protected NodeBase() {} - public boolean isNode() { + public boolean isAtom() { return true; } @@ -75,7 +75,7 @@ public abstract class NodeBase implements TupleElement { } @SuppressWarnings("unchecked") - public NodeType castToNode() { + public NodeType castToElement() { return (NodeType) this; } diff --git a/src/main/java/org/xerial/lens/relation/Tuple.java b/src/main/java/org/xerial/lens/relation/Tuple.java index 58d348b..4b3d06a 100644 --- a/src/main/java/org/xerial/lens/relation/Tuple.java +++ b/src/main/java/org/xerial/lens/relation/Tuple.java @@ -145,7 +145,7 @@ public class Tuple implements TupleElement, Iterable implements TupleElement, Iterable implements TupleElement, Iterable node = get(index); - if (node.isNode()) + if (node.isAtom()) return (Element) node; else throw new XerialError(XerialErrorCode.MISSING_ELEMENT, "node is not found: " + index); @@ -184,7 +184,7 @@ public class Tuple implements TupleElement, Iterable implements TupleElement, Iterable> result, TupleElement cell) { - if (cell.isNode()) + if (cell.isAtom()) result.add(cell); else { for (TupleElement each : cell.castToTuple()) { diff --git a/src/main/java/org/xerial/lens/relation/TupleElement.java b/src/main/java/org/xerial/lens/relation/TupleElement.java index 0bbef57..bfd4ae2 100644 --- a/src/main/java/org/xerial/lens/relation/TupleElement.java +++ b/src/main/java/org/xerial/lens/relation/TupleElement.java @@ -34,11 +34,11 @@ package org.xerial.lens.relation; */ public interface TupleElement { /** - * Returns true if this cell is a singleton + * Returns true if this element is a singleton, i.e. no more nested nodes * * @return */ - public boolean isNode(); + public boolean isAtom(); /** * Returns true if this cell is a tuple @@ -48,9 +48,9 @@ public interface TupleElement { public boolean isTuple(); /** - * Get the number of elements contained in this cell. When this cell is an - * atom, the size will be 1. When a tuple, the returned size is the tuple - * size. + * Get the number of elements contained in this element. When this element + * is an atom, the size will be 1. When a tuple, the returned size is the + * tuple size. * * @return */ @@ -78,7 +78,7 @@ public interface TupleElement { * * @return */ - Element castToNode(); + Element castToElement(); /** * If this cell is tuple, then return tuple. otherwise return null diff --git a/src/main/java/org/xerial/lens/relation/query/impl/LensQuery.g b/src/main/java/org/xerial/lens/relation/query/impl/LensQuery.g index 8371c60..897d91e 100644 --- a/src/main/java/org/xerial/lens/relation/query/impl/LensQuery.g +++ b/src/main/java/org/xerial/lens/relation/query/impl/LensQuery.g @@ -39,7 +39,6 @@ tokens { NODEVALUE; NAME; VALUE; - INDEX; } @@ -99,7 +98,6 @@ package org.xerial.lens.relation.query.impl; //-------------------------------------- package org.xerial.lens.relation.query.impl; -import org.xerial.lens.relation.TupleIndex; } @lexer::members { @@ -107,7 +105,6 @@ import org.xerial.lens.relation.TupleIndex; } @members { - private TupleIndex currentIndex = null; } // lexer rules @@ -190,24 +187,7 @@ expr: ; relation -scope -{ - int nodeItemIndex; - TupleIndex relationIndex; -} -@init -{ - $relation::nodeItemIndex = 1; - if(currentIndex == null) - currentIndex = new TupleIndex(1); - else - currentIndex = new TupleIndex(currentIndex, 1); -} -@after -{ - currentIndex = currentIndex.parent(); -} - : relation_i -> ^(RELATION relation_i INDEX[currentIndex.toString()]) + : relation_i -> ^(RELATION relation_i) ; relation_i: nodeName alias? LParen! nodeItem (Comma! nodeItem)* RParen!; @@ -225,11 +205,8 @@ alias: As QName -> ALIAS[$QName.text]; fragment nodeItem -@init { - int index = $relation::nodeItemIndex++; -} : nodeName alias? nodeValue? - -> ^(NODE nodeName alias? nodeValue? INDEX[new TupleIndex(currentIndex, index).toString()]) + -> ^(NODE nodeName alias? nodeValue?) | relation ; diff --git a/src/main/java/org/xerial/lens/relation/query/impl/LensQuery.tokens b/src/main/java/org/xerial/lens/relation/query/impl/LensQuery.tokens index d20e7ca..5b4c454 100644 --- a/src/main/java/org/xerial/lens/relation/query/impl/LensQuery.tokens +++ b/src/main/java/org/xerial/lens/relation/query/impl/LensQuery.tokens @@ -1,52 +1,51 @@ -INDEX=15 PATTERNMATCH=9 -Match=40 -Regex=41 -Digit=19 -Frac=28 -HexDigit=21 +Match=39 +Regex=40 +Digit=18 +Frac=27 +HexDigit=20 QUERY=4 ALIAS=11 VALUE=14 -Letter=20 -Comma=43 -Dot=42 -EscapeSequence=23 -Integer=27 -WhiteSpace=52 +Letter=19 +Comma=42 +Dot=41 +EscapeSequence=22 +Integer=26 +WhiteSpace=51 OPERATOR=7 -False=32 -Colon=44 -LineComment=17 +False=31 +LineComment=16 +Colon=43 NODEVALUE=12 -As=45 -SafeFirstLetter=50 -Null=33 -Star=48 -Eq=38 -Exp=29 -QNameChar=53 +As=44 +SafeFirstLetter=49 +Null=32 +Star=47 +Eq=37 +Exp=28 +QNameChar=52 RELATION=5 -Gt=35 -RParen=47 -UnicodeChar=22 -StringChar=24 -True=31 +Gt=34 +RParen=46 +UnicodeChar=21 +StringChar=23 +True=30 OPERAND=8 -LineBreak=18 -LParen=46 -String=26 -SafeLetter=51 -LineBreakChar=16 +LineBreak=17 +LParen=45 +String=25 +SafeLetter=50 +LineBreakChar=15 COMPARE=6 -QName=54 -Geq=37 +QName=53 +Geq=36 NODE=10 -StringChar_s=25 -Neq=39 -UnsafeUnicodeChar=49 -Double=30 -Lt=34 +StringChar_s=24 +Neq=38 +UnsafeUnicodeChar=48 +Double=29 +Lt=33 NAME=13 -Leq=36 -WhiteSpaces=55 +Leq=35 +WhiteSpaces=54 diff --git a/src/main/java/org/xerial/lens/relation/query/impl/LensQueryLexer.java b/src/main/java/org/xerial/lens/relation/query/impl/LensQueryLexer.java index 0964d84..943b0d9 100644 --- a/src/main/java/org/xerial/lens/relation/query/impl/LensQueryLexer.java +++ b/src/main/java/org/xerial/lens/relation/query/impl/LensQueryLexer.java @@ -1,4 +1,4 @@ -// $ANTLR 3.1.3 Mar 17, 2009 19:23:44 LensQuery.g 2009-09-30 22:59:27 +// $ANTLR 3.1.3 Mar 17, 2009 19:23:44 LensQuery.g 2009-10-13 14:02:52 /*-------------------------------------------------------------------------- * Copyright 2009 Taro L. Saito @@ -33,59 +33,58 @@ import java.util.List; import java.util.ArrayList; public class LensQueryLexer extends Lexer { - public static final int INDEX=15; public static final int PATTERNMATCH=9; - public static final int Match=40; - public static final int Regex=41; - public static final int Digit=19; - public static final int Frac=28; - public static final int HexDigit=21; + public static final int Match=39; + public static final int Regex=40; + public static final int Digit=18; + public static final int Frac=27; + public static final int HexDigit=20; public static final int QUERY=4; public static final int ALIAS=11; public static final int VALUE=14; - public static final int Letter=20; - public static final int Comma=43; - public static final int Dot=42; - public static final int EscapeSequence=23; - public static final int Integer=27; - public static final int WhiteSpace=52; + public static final int Letter=19; + public static final int Comma=42; + public static final int Dot=41; + public static final int EscapeSequence=22; + public static final int Integer=26; + public static final int WhiteSpace=51; public static final int OPERATOR=7; - public static final int False=32; - public static final int Colon=44; - public static final int LineComment=17; + public static final int False=31; + public static final int LineComment=16; + public static final int Colon=43; public static final int NODEVALUE=12; - public static final int As=45; - public static final int SafeFirstLetter=50; - public static final int Null=33; - public static final int Star=48; - public static final int Eq=38; - public static final int Exp=29; - public static final int QNameChar=53; + public static final int As=44; + public static final int SafeFirstLetter=49; + public static final int Null=32; + public static final int Star=47; + public static final int Eq=37; + public static final int Exp=28; + public static final int QNameChar=52; public static final int RELATION=5; - public static final int Gt=35; - public static final int RParen=47; - public static final int UnicodeChar=22; - public static final int StringChar=24; - public static final int True=31; + public static final int Gt=34; + public static final int RParen=46; + public static final int UnicodeChar=21; + public static final int StringChar=23; + public static final int True=30; public static final int OPERAND=8; - public static final int LineBreak=18; - public static final int LParen=46; - public static final int String=26; - public static final int SafeLetter=51; - public static final int LineBreakChar=16; + public static final int LineBreak=17; + public static final int LParen=45; + public static final int String=25; + public static final int SafeLetter=50; + public static final int LineBreakChar=15; public static final int COMPARE=6; - public static final int QName=54; - public static final int Geq=37; + public static final int QName=53; + public static final int Geq=36; public static final int EOF=-1; public static final int NODE=10; - public static final int Neq=39; - public static final int StringChar_s=25; - public static final int UnsafeUnicodeChar=49; - public static final int Double=30; - public static final int Lt=34; + public static final int Neq=38; + public static final int StringChar_s=24; + public static final int UnsafeUnicodeChar=48; + public static final int Double=29; + public static final int Lt=33; public static final int NAME=13; - public static final int Leq=36; - public static final int WhiteSpaces=55; + public static final int Leq=35; + public static final int WhiteSpaces=54; @@ -106,7 +105,7 @@ public class LensQueryLexer extends Lexer { // $ANTLR start "LineBreakChar" public final void mLineBreakChar() throws RecognitionException { try { - // LensQuery.g:116:23: ( '\\n' | '\\r' ) + // LensQuery.g:113:23: ( '\\n' | '\\r' ) // LensQuery.g: { if ( input.LA(1)=='\n'||input.LA(1)=='\r' ) { @@ -132,11 +131,11 @@ public class LensQueryLexer extends Lexer { try { int _type = LineComment; int _channel = DEFAULT_TOKEN_CHANNEL; - // LensQuery.g:117:12: ( '#' (~ ( LineBreakChar ) )* ) - // LensQuery.g:117:14: '#' (~ ( LineBreakChar ) )* + // LensQuery.g:114:12: ( '#' (~ ( LineBreakChar ) )* ) + // LensQuery.g:114:14: '#' (~ ( LineBreakChar ) )* { match('#'); - // LensQuery.g:117:18: (~ ( LineBreakChar ) )* + // LensQuery.g:114:18: (~ ( LineBreakChar ) )* loop1: do { int alt1=2; @@ -149,7 +148,7 @@ public class LensQueryLexer extends Lexer { switch (alt1) { case 1 : - // LensQuery.g:117:18: ~ ( LineBreakChar ) + // LensQuery.g:114:18: ~ ( LineBreakChar ) { if ( (input.LA(1)>='\u0000' && input.LA(1)<='\t')||(input.LA(1)>='\u000B' && input.LA(1)<='\f')||(input.LA(1)>='\u000E' && input.LA(1)<='\uFFFF') ) { input.consume(); @@ -186,10 +185,10 @@ public class LensQueryLexer extends Lexer { try { int _type = LineBreak; int _channel = DEFAULT_TOKEN_CHANNEL; - // LensQuery.g:120:10: ( ( '\\r' '\\n' | '\\r' | '\\n' ) ) - // LensQuery.g:120:12: ( '\\r' '\\n' | '\\r' | '\\n' ) + // LensQuery.g:117:10: ( ( '\\r' '\\n' | '\\r' | '\\n' ) ) + // LensQuery.g:117:12: ( '\\r' '\\n' | '\\r' | '\\n' ) { - // LensQuery.g:120:12: ( '\\r' '\\n' | '\\r' | '\\n' ) + // LensQuery.g:117:12: ( '\\r' '\\n' | '\\r' | '\\n' ) int alt2=3; int LA2_0 = input.LA(1); @@ -213,7 +212,7 @@ public class LensQueryLexer extends Lexer { } switch (alt2) { case 1 : - // LensQuery.g:120:13: '\\r' '\\n' + // LensQuery.g:117:13: '\\r' '\\n' { match('\r'); match('\n'); @@ -221,14 +220,14 @@ public class LensQueryLexer extends Lexer { } break; case 2 : - // LensQuery.g:120:25: '\\r' + // LensQuery.g:117:25: '\\r' { match('\r'); } break; case 3 : - // LensQuery.g:120:32: '\\n' + // LensQuery.g:117:32: '\\n' { match('\n'); @@ -252,8 +251,8 @@ public class LensQueryLexer extends Lexer { // $ANTLR start "Digit" public final void mDigit() throws RecognitionException { try { - // LensQuery.g:123:15: ( '0' .. '9' ) - // LensQuery.g:123:17: '0' .. '9' + // LensQuery.g:120:15: ( '0' .. '9' ) + // LensQuery.g:120:17: '0' .. '9' { matchRange('0','9'); @@ -268,7 +267,7 @@ public class LensQueryLexer extends Lexer { // $ANTLR start "Letter" public final void mLetter() throws RecognitionException { try { - // LensQuery.g:124:16: ( 'A' .. 'F' | 'a' .. 'f' ) + // LensQuery.g:121:16: ( 'A' .. 'F' | 'a' .. 'f' ) // LensQuery.g: { if ( (input.LA(1)>='A' && input.LA(1)<='F')||(input.LA(1)>='a' && input.LA(1)<='f') ) { @@ -292,7 +291,7 @@ public class LensQueryLexer extends Lexer { // $ANTLR start "HexDigit" public final void mHexDigit() throws RecognitionException { try { - // LensQuery.g:125:18: ( Digit | Letter ) + // LensQuery.g:122:18: ( Digit | Letter ) // LensQuery.g: { if ( (input.LA(1)>='0' && input.LA(1)<='9')||(input.LA(1)>='A' && input.LA(1)<='F')||(input.LA(1)>='a' && input.LA(1)<='f') ) { @@ -316,8 +315,8 @@ public class LensQueryLexer extends Lexer { // $ANTLR start "UnicodeChar" public final void mUnicodeChar() throws RecognitionException { try { - // LensQuery.g:126:21: (~ ( '\"' | '\\\\' ) ) - // LensQuery.g:126:23: ~ ( '\"' | '\\\\' ) + // LensQuery.g:123:21: (~ ( '\"' | '\\\\' ) ) + // LensQuery.g:123:23: ~ ( '\"' | '\\\\' ) { if ( (input.LA(1)>='\u0000' && input.LA(1)<='!')||(input.LA(1)>='#' && input.LA(1)<='[')||(input.LA(1)>=']' && input.LA(1)<='\uFFFF') ) { input.consume(); @@ -340,11 +339,11 @@ public class LensQueryLexer extends Lexer { // $ANTLR start "EscapeSequence" public final void mEscapeSequence() throws RecognitionException { try { - // LensQuery.g:128:3: ( '\\\\' ( '\\\"' | '\\\\' | '/' | 'b' | 'f' | 'n' | 'r' | 't' | 'u' HexDigit HexDigit HexDigit HexDigit ) ) - // LensQuery.g:128:5: '\\\\' ( '\\\"' | '\\\\' | '/' | 'b' | 'f' | 'n' | 'r' | 't' | 'u' HexDigit HexDigit HexDigit HexDigit ) + // LensQuery.g:125:3: ( '\\\\' ( '\\\"' | '\\\\' | '/' | 'b' | 'f' | 'n' | 'r' | 't' | 'u' HexDigit HexDigit HexDigit HexDigit ) ) + // LensQuery.g:125:5: '\\\\' ( '\\\"' | '\\\\' | '/' | 'b' | 'f' | 'n' | 'r' | 't' | 'u' HexDigit HexDigit HexDigit HexDigit ) { match('\\'); - // LensQuery.g:128:10: ( '\\\"' | '\\\\' | '/' | 'b' | 'f' | 'n' | 'r' | 't' | 'u' HexDigit HexDigit HexDigit HexDigit ) + // LensQuery.g:125:10: ( '\\\"' | '\\\\' | '/' | 'b' | 'f' | 'n' | 'r' | 't' | 'u' HexDigit HexDigit HexDigit HexDigit ) int alt3=9; switch ( input.LA(1) ) { case '\"': @@ -401,63 +400,63 @@ public class LensQueryLexer extends Lexer { switch (alt3) { case 1 : - // LensQuery.g:128:11: '\\\"' + // LensQuery.g:125:11: '\\\"' { match('\"'); } break; case 2 : - // LensQuery.g:128:18: '\\\\' + // LensQuery.g:125:18: '\\\\' { match('\\'); } break; case 3 : - // LensQuery.g:128:25: '/' + // LensQuery.g:125:25: '/' { match('/'); } break; case 4 : - // LensQuery.g:128:31: 'b' + // LensQuery.g:125:31: 'b' { match('b'); } break; case 5 : - // LensQuery.g:128:37: 'f' + // LensQuery.g:125:37: 'f' { match('f'); } break; case 6 : - // LensQuery.g:128:43: 'n' + // LensQuery.g:125:43: 'n' { match('n'); } break; case 7 : - // LensQuery.g:128:49: 'r' + // LensQuery.g:125:49: 'r' { match('r'); } break; case 8 : - // LensQuery.g:128:55: 't' + // LensQuery.g:125:55: 't' { match('t'); } break; case 9 : - // LensQuery.g:128:61: 'u' HexDigit HexDigit HexDigit HexDigit + // LensQuery.g:125:61: 'u' HexDigit HexDigit HexDigit HexDigit { match('u'); mHexDigit(); @@ -482,7 +481,7 @@ public class LensQueryLexer extends Lexer { // $ANTLR start "StringChar" public final void mStringChar() throws RecognitionException { try { - // LensQuery.g:131:21: ( UnicodeChar | EscapeSequence ) + // LensQuery.g:128:21: ( UnicodeChar | EscapeSequence ) int alt4=2; int LA4_0 = input.LA(1); @@ -500,14 +499,14 @@ public class LensQueryLexer extends Lexer { } switch (alt4) { case 1 : - // LensQuery.g:131:24: UnicodeChar + // LensQuery.g:128:24: UnicodeChar { mUnicodeChar(); } break; case 2 : - // LensQuery.g:131:38: EscapeSequence + // LensQuery.g:128:38: EscapeSequence { mEscapeSequence(); @@ -524,10 +523,10 @@ public class LensQueryLexer extends Lexer { // $ANTLR start "StringChar_s" public final void mStringChar_s() throws RecognitionException { try { - // LensQuery.g:132:22: ( ( StringChar )* ) - // LensQuery.g:132:24: ( StringChar )* + // LensQuery.g:129:22: ( ( StringChar )* ) + // LensQuery.g:129:24: ( StringChar )* { - // LensQuery.g:132:24: ( StringChar )* + // LensQuery.g:129:24: ( StringChar )* loop5: do { int alt5=2; @@ -540,7 +539,7 @@ public class LensQueryLexer extends Lexer { switch (alt5) { case 1 : - // LensQuery.g:132:24: StringChar + // LensQuery.g:129:24: StringChar { mStringChar(); @@ -568,8 +567,8 @@ public class LensQueryLexer extends Lexer { int _channel = DEFAULT_TOKEN_CHANNEL; Token s=null; - // LensQuery.g:134:7: ( '\"' s= StringChar_s '\"' ) - // LensQuery.g:134:9: '\"' s= StringChar_s '\"' + // LensQuery.g:131:7: ( '\"' s= StringChar_s '\"' ) + // LensQuery.g:131:9: '\"' s= StringChar_s '\"' { match('\"'); int sStart244 = getCharIndex(); @@ -593,10 +592,10 @@ public class LensQueryLexer extends Lexer { try { int _type = Integer; int _channel = DEFAULT_TOKEN_CHANNEL; - // LensQuery.g:137:8: ( ( '-' )? ( '0' | '1' .. '9' ( Digit )* ) ) - // LensQuery.g:137:10: ( '-' )? ( '0' | '1' .. '9' ( Digit )* ) + // LensQuery.g:134:8: ( ( '-' )? ( '0' | '1' .. '9' ( Digit )* ) ) + // LensQuery.g:134:10: ( '-' )? ( '0' | '1' .. '9' ( Digit )* ) { - // LensQuery.g:137:10: ( '-' )? + // LensQuery.g:134:10: ( '-' )? int alt6=2; int LA6_0 = input.LA(1); @@ -605,7 +604,7 @@ public class LensQueryLexer extends Lexer { } switch (alt6) { case 1 : - // LensQuery.g:137:10: '-' + // LensQuery.g:134:10: '-' { match('-'); @@ -614,7 +613,7 @@ public class LensQueryLexer extends Lexer { } - // LensQuery.g:137:15: ( '0' | '1' .. '9' ( Digit )* ) + // LensQuery.g:134:15: ( '0' | '1' .. '9' ( Digit )* ) int alt8=2; int LA8_0 = input.LA(1); @@ -632,17 +631,17 @@ public class LensQueryLexer extends Lexer { } switch (alt8) { case 1 : - // LensQuery.g:137:16: '0' + // LensQuery.g:134:16: '0' { match('0'); } break; case 2 : - // LensQuery.g:137:22: '1' .. '9' ( Digit )* + // LensQuery.g:134:22: '1' .. '9' ( Digit )* { matchRange('1','9'); - // LensQuery.g:137:31: ( Digit )* + // LensQuery.g:134:31: ( Digit )* loop7: do { int alt7=2; @@ -655,7 +654,7 @@ public class LensQueryLexer extends Lexer { switch (alt7) { case 1 : - // LensQuery.g:137:31: Digit + // LensQuery.g:134:31: Digit { mDigit(); @@ -687,11 +686,11 @@ public class LensQueryLexer extends Lexer { // $ANTLR start "Frac" public final void mFrac() throws RecognitionException { try { - // LensQuery.g:138:14: ( '.' ( Digit )+ ) - // LensQuery.g:138:16: '.' ( Digit )+ + // LensQuery.g:135:14: ( '.' ( Digit )+ ) + // LensQuery.g:135:16: '.' ( Digit )+ { match('.'); - // LensQuery.g:138:20: ( Digit )+ + // LensQuery.g:135:20: ( Digit )+ int cnt9=0; loop9: do { @@ -705,7 +704,7 @@ public class LensQueryLexer extends Lexer { switch (alt9) { case 1 : - // LensQuery.g:138:20: Digit + // LensQuery.g:135:20: Digit { mDigit(); @@ -733,8 +732,8 @@ public class LensQueryLexer extends Lexer { // $ANTLR start "Exp" public final void mExp() throws RecognitionException { try { - // LensQuery.g:139:13: ( ( 'e' | 'E' ) ( '+' | '-' )? ( Digit )+ ) - // LensQuery.g:139:15: ( 'e' | 'E' ) ( '+' | '-' )? ( Digit )+ + // LensQuery.g:136:13: ( ( 'e' | 'E' ) ( '+' | '-' )? ( Digit )+ ) + // LensQuery.g:136:15: ( 'e' | 'E' ) ( '+' | '-' )? ( Digit )+ { if ( input.LA(1)=='E'||input.LA(1)=='e' ) { input.consume(); @@ -745,7 +744,7 @@ public class LensQueryLexer extends Lexer { recover(mse); throw mse;} - // LensQuery.g:139:27: ( '+' | '-' )? + // LensQuery.g:136:27: ( '+' | '-' )? int alt10=2; int LA10_0 = input.LA(1); @@ -771,7 +770,7 @@ public class LensQueryLexer extends Lexer { } - // LensQuery.g:139:40: ( Digit )+ + // LensQuery.g:136:40: ( Digit )+ int cnt11=0; loop11: do { @@ -785,7 +784,7 @@ public class LensQueryLexer extends Lexer { switch (alt11) { case 1 : - // LensQuery.g:139:40: Digit + // LensQuery.g:136:40: Digit { mDigit(); @@ -815,11 +814,11 @@ public class LensQueryLexer extends Lexer { try { int _type = Double; int _channel = DEFAULT_TOKEN_CHANNEL; - // LensQuery.g:140:7: ( Integer ( Frac ( Exp )? | Exp ) ) - // LensQuery.g:140:9: Integer ( Frac ( Exp )? | Exp ) + // LensQuery.g:137:7: ( Integer ( Frac ( Exp )? | Exp ) ) + // LensQuery.g:137:9: Integer ( Frac ( Exp )? | Exp ) { mInteger(); - // LensQuery.g:140:17: ( Frac ( Exp )? | Exp ) + // LensQuery.g:137:17: ( Frac ( Exp )? | Exp ) int alt13=2; int LA13_0 = input.LA(1); @@ -837,10 +836,10 @@ public class LensQueryLexer extends Lexer { } switch (alt13) { case 1 : - // LensQuery.g:140:18: Frac ( Exp )? + // LensQuery.g:137:18: Frac ( Exp )? { mFrac(); - // LensQuery.g:140:23: ( Exp )? + // LensQuery.g:137:23: ( Exp )? int alt12=2; int LA12_0 = input.LA(1); @@ -849,7 +848,7 @@ public class LensQueryLexer extends Lexer { } switch (alt12) { case 1 : - // LensQuery.g:140:23: Exp + // LensQuery.g:137:23: Exp { mExp(); @@ -862,7 +861,7 @@ public class LensQueryLexer extends Lexer { } break; case 2 : - // LensQuery.g:140:30: Exp + // LensQuery.g:137:30: Exp { mExp(); @@ -887,8 +886,8 @@ public class LensQueryLexer extends Lexer { try { int _type = True; int _channel = DEFAULT_TOKEN_CHANNEL; - // LensQuery.g:142:5: ( 'true' ) - // LensQuery.g:142:7: 'true' + // LensQuery.g:139:5: ( 'true' ) + // LensQuery.g:139:7: 'true' { match("true"); @@ -908,8 +907,8 @@ public class LensQueryLexer extends Lexer { try { int _type = False; int _channel = DEFAULT_TOKEN_CHANNEL; - // LensQuery.g:143:6: ( 'false' ) - // LensQuery.g:143:8: 'false' + // LensQuery.g:140:6: ( 'false' ) + // LensQuery.g:140:8: 'false' { match("false"); @@ -929,8 +928,8 @@ public class LensQueryLexer extends Lexer { try { int _type = Null; int _channel = DEFAULT_TOKEN_CHANNEL; - // LensQuery.g:144:5: ( 'null' ) - // LensQuery.g:144:7: 'null' + // LensQuery.g:141:5: ( 'null' ) + // LensQuery.g:141:7: 'null' { match("null"); @@ -950,8 +949,8 @@ public class LensQueryLexer extends Lexer { try { int _type = Lt; int _channel = DEFAULT_TOKEN_CHANNEL; - // LensQuery.g:148:3: ( '<' ) - // LensQuery.g:148:5: '<' + // LensQuery.g:145:3: ( '<' ) + // LensQuery.g:145:5: '<' { match('<'); @@ -970,8 +969,8 @@ public class LensQueryLexer extends Lexer { try { int _type = Gt; int _channel = DEFAULT_TOKEN_CHANNEL; - // LensQuery.g:149:3: ( '>' ) - // LensQuery.g:149:5: '>' + // LensQuery.g:146:3: ( '>' ) + // LensQuery.g:146:5: '>' { match('>'); @@ -990,8 +989,8 @@ public class LensQueryLexer extends Lexer { try { int _type = Leq; int _channel = DEFAULT_TOKEN_CHANNEL; - // LensQuery.g:150:4: ( '<=' ) - // LensQuery.g:150:6: '<=' + // LensQuery.g:147:4: ( '<=' ) + // LensQuery.g:147:6: '<=' { match("<="); @@ -1011,8 +1010,8 @@ public class LensQueryLexer extends Lexer { try { int _type = Geq; int _channel = DEFAULT_TOKEN_CHANNEL; - // LensQuery.g:151:4: ( '>=' ) - // LensQuery.g:151:6: '>=' + // LensQuery.g:148:4: ( '>=' ) + // LensQuery.g:148:6: '>=' { match(">="); @@ -1032,8 +1031,8 @@ public class LensQueryLexer extends Lexer { try { int _type = Eq; int _channel = DEFAULT_TOKEN_CHANNEL; - // LensQuery.g:152:3: ( '=' ) - // LensQuery.g:152:5: '=' + // LensQuery.g:149:3: ( '=' ) + // LensQuery.g:149:5: '=' { match('='); @@ -1052,8 +1051,8 @@ public class LensQueryLexer extends Lexer { try { int _type = Neq; int _channel = DEFAULT_TOKEN_CHANNEL; - // LensQuery.g:153:4: ( '!=' ) - // LensQuery.g:153:6: '!=' + // LensQuery.g:150:4: ( '!=' ) + // LensQuery.g:150:6: '!=' { match("!="); @@ -1073,8 +1072,8 @@ public class LensQueryLexer extends Lexer { try { int _type = Match; int _channel = DEFAULT_TOKEN_CHANNEL; - // LensQuery.g:154:6: ( '~=' ) - // LensQuery.g:154:8: '~=' + // LensQuery.g:151:6: ( '~=' ) + // LensQuery.g:151:8: '~=' { match("~="); @@ -1094,11 +1093,11 @@ public class LensQueryLexer extends Lexer { try { int _type = Regex; int _channel = DEFAULT_TOKEN_CHANNEL; - // LensQuery.g:155:6: ( '/' ( options {greedy=false; } : . )* '/' ( 'a' .. 'z' | 'A' .. 'Z' )* ) - // LensQuery.g:155:8: '/' ( options {greedy=false; } : . )* '/' ( 'a' .. 'z' | 'A' .. 'Z' )* + // LensQuery.g:152:6: ( '/' ( options {greedy=false; } : . )* '/' ( 'a' .. 'z' | 'A' .. 'Z' )* ) + // LensQuery.g:152:8: '/' ( options {greedy=false; } : . )* '/' ( 'a' .. 'z' | 'A' .. 'Z' )* { match('/'); - // LensQuery.g:155:13: ( options {greedy=false; } : . )* + // LensQuery.g:152:13: ( options {greedy=false; } : . )* loop14: do { int alt14=2; @@ -1114,7 +1113,7 @@ public class LensQueryLexer extends Lexer { switch (alt14) { case 1 : - // LensQuery.g:155:38: . + // LensQuery.g:152:38: . { matchAny(); @@ -1127,7 +1126,7 @@ public class LensQueryLexer extends Lexer { } while (true); match('/'); - // LensQuery.g:155:46: ( 'a' .. 'z' | 'A' .. 'Z' )* + // LensQuery.g:152:46: ( 'a' .. 'z' | 'A' .. 'Z' )* loop15: do { int alt15=2; @@ -1176,8 +1175,8 @@ public class LensQueryLexer extends Lexer { try { int _type = Dot; int _channel = DEFAULT_TOKEN_CHANNEL; - // LensQuery.g:158:4: ( '.' ) - // LensQuery.g:158:6: '.' + // LensQuery.g:155:4: ( '.' ) + // LensQuery.g:155:6: '.' { match('.'); @@ -1196,8 +1195,8 @@ public class LensQueryLexer extends Lexer { try { int _type = Comma; int _channel = DEFAULT_TOKEN_CHANNEL; - // LensQuery.g:159:6: ( ',' ) - // LensQuery.g:159:8: ',' + // LensQuery.g:156:6: ( ',' ) + // LensQuery.g:156:8: ',' { match(','); @@ -1216,8 +1215,8 @@ public class LensQueryLexer extends Lexer { try { int _type = Colon; int _channel = DEFAULT_TOKEN_CHANNEL; - // LensQuery.g:160:6: ( ':' ) - // LensQuery.g:160:8: ':' + // LensQuery.g:157:6: ( ':' ) + // LensQuery.g:157:8: ':' { match(':'); @@ -1236,8 +1235,8 @@ public class LensQueryLexer extends Lexer { try { int _type = As; int _channel = DEFAULT_TOKEN_CHANNEL; - // LensQuery.g:162:3: ( 'as' ) - // LensQuery.g:162:5: 'as' + // LensQuery.g:159:3: ( 'as' ) + // LensQuery.g:159:5: 'as' { match("as"); @@ -1257,8 +1256,8 @@ public class LensQueryLexer extends Lexer { try { int _type = LParen; int _channel = DEFAULT_TOKEN_CHANNEL; - // LensQuery.g:164:7: ( '(' ) - // LensQuery.g:164:9: '(' + // LensQuery.g:161:7: ( '(' ) + // LensQuery.g:161:9: '(' { match('('); @@ -1277,8 +1276,8 @@ public class LensQueryLexer extends Lexer { try { int _type = RParen; int _channel = DEFAULT_TOKEN_CHANNEL; - // LensQuery.g:165:7: ( ')' ) - // LensQuery.g:165:9: ')' + // LensQuery.g:162:7: ( ')' ) + // LensQuery.g:162:9: ')' { match(')'); @@ -1297,8 +1296,8 @@ public class LensQueryLexer extends Lexer { try { int _type = Star; int _channel = DEFAULT_TOKEN_CHANNEL; - // LensQuery.g:167:5: ( '*' ) - // LensQuery.g:167:7: '*' + // LensQuery.g:164:5: ( '*' ) + // LensQuery.g:164:7: '*' { match('*'); @@ -1315,7 +1314,7 @@ public class LensQueryLexer extends Lexer { // $ANTLR start "UnsafeUnicodeChar" public final void mUnsafeUnicodeChar() throws RecognitionException { try { - // LensQuery.g:170:18: ( '(' | ')' | '[' | ']' | '{' | '}' | ',' | ':' | '#' | '<' | '>' | '|' | '*' | '\\'' | '\"' | '@' | '%' | '\\\\' | '.' | '-' ) + // LensQuery.g:167:18: ( '(' | ')' | '[' | ']' | '{' | '}' | ',' | ':' | '#' | '<' | '>' | '|' | '*' | '\\'' | '\"' | '@' | '%' | '\\\\' | '.' | '-' ) // LensQuery.g: { if ( (input.LA(1)>='\"' && input.LA(1)<='#')||input.LA(1)=='%'||(input.LA(1)>='\'' && input.LA(1)<='*')||(input.LA(1)>=',' && input.LA(1)<='.')||input.LA(1)==':'||input.LA(1)=='<'||input.LA(1)=='>'||input.LA(1)=='@'||(input.LA(1)>='[' && input.LA(1)<=']')||(input.LA(1)>='{' && input.LA(1)<='}') ) { @@ -1339,7 +1338,7 @@ public class LensQueryLexer extends Lexer { // $ANTLR start "SafeFirstLetter" public final void mSafeFirstLetter() throws RecognitionException { try { - // LensQuery.g:172:25: ( 'A' .. 'Z' | 'a' .. 'z' ) + // LensQuery.g:169:25: ( 'A' .. 'Z' | 'a' .. 'z' ) // LensQuery.g: { if ( (input.LA(1)>='A' && input.LA(1)<='Z')||(input.LA(1)>='a' && input.LA(1)<='z') ) { @@ -1363,7 +1362,7 @@ public class LensQueryLexer extends Lexer { // $ANTLR start "SafeLetter" public final void mSafeLetter() throws RecognitionException { try { - // LensQuery.g:173:20: ( SafeFirstLetter | '0' .. '9' | '-' | '_' ) + // LensQuery.g:170:20: ( SafeFirstLetter | '0' .. '9' | '-' | '_' ) // LensQuery.g: { if ( input.LA(1)=='-'||(input.LA(1)>='0' && input.LA(1)<='9')||(input.LA(1)>='A' && input.LA(1)<='Z')||input.LA(1)=='_'||(input.LA(1)>='a' && input.LA(1)<='z') ) { @@ -1387,8 +1386,8 @@ public class LensQueryLexer extends Lexer { // $ANTLR start "QNameChar" public final void mQNameChar() throws RecognitionException { try { - // LensQuery.g:176:19: (~ ( LineBreakChar | UnsafeUnicodeChar | WhiteSpace ) ) - // LensQuery.g:176:21: ~ ( LineBreakChar | UnsafeUnicodeChar | WhiteSpace ) + // LensQuery.g:173:19: (~ ( LineBreakChar | UnsafeUnicodeChar | WhiteSpace ) ) + // LensQuery.g:173:21: ~ ( LineBreakChar | UnsafeUnicodeChar | WhiteSpace ) { if ( (input.LA(1)>='\u0000' && input.LA(1)<='\b')||(input.LA(1)>='\u000B' && input.LA(1)<='\f')||(input.LA(1)>='\u000E' && input.LA(1)<='\u001F')||input.LA(1)=='!'||input.LA(1)=='$'||input.LA(1)=='&'||input.LA(1)=='+'||(input.LA(1)>='/' && input.LA(1)<='9')||input.LA(1)==';'||input.LA(1)=='='||input.LA(1)=='?'||(input.LA(1)>='A' && input.LA(1)<='Z')||(input.LA(1)>='^' && input.LA(1)<='z')||(input.LA(1)>='~' && input.LA(1)<='\uFFFF') ) { input.consume(); @@ -1413,10 +1412,10 @@ public class LensQueryLexer extends Lexer { try { int _type = QName; int _channel = DEFAULT_TOKEN_CHANNEL; - // LensQuery.g:177:6: ( ( QNameChar )+ ( Dot ( QNameChar )+ )* ) - // LensQuery.g:177:8: ( QNameChar )+ ( Dot ( QNameChar )+ )* + // LensQuery.g:174:6: ( ( QNameChar )+ ( Dot ( QNameChar )+ )* ) + // LensQuery.g:174:8: ( QNameChar )+ ( Dot ( QNameChar )+ )* { - // LensQuery.g:177:8: ( QNameChar )+ + // LensQuery.g:174:8: ( QNameChar )+ int cnt16=0; loop16: do { @@ -1430,7 +1429,7 @@ public class LensQueryLexer extends Lexer { switch (alt16) { case 1 : - // LensQuery.g:177:8: QNameChar + // LensQuery.g:174:8: QNameChar { mQNameChar(); @@ -1446,7 +1445,7 @@ public class LensQueryLexer extends Lexer { cnt16++; } while (true); - // LensQuery.g:177:19: ( Dot ( QNameChar )+ )* + // LensQuery.g:174:19: ( Dot ( QNameChar )+ )* loop18: do { int alt18=2; @@ -1459,10 +1458,10 @@ public class LensQueryLexer extends Lexer { switch (alt18) { case 1 : - // LensQuery.g:177:20: Dot ( QNameChar )+ + // LensQuery.g:174:20: Dot ( QNameChar )+ { mDot(); - // LensQuery.g:177:24: ( QNameChar )+ + // LensQuery.g:174:24: ( QNameChar )+ int cnt17=0; loop17: do { @@ -1476,7 +1475,7 @@ public class LensQueryLexer extends Lexer { switch (alt17) { case 1 : - // LensQuery.g:177:24: QNameChar + // LensQuery.g:174:24: QNameChar { mQNameChar(); @@ -1515,7 +1514,7 @@ public class LensQueryLexer extends Lexer { // $ANTLR start "WhiteSpace" public final void mWhiteSpace() throws RecognitionException { try { - // LensQuery.g:181:11: ( ' ' | '\\t' ) + // LensQuery.g:178:11: ( ' ' | '\\t' ) // LensQuery.g: { if ( input.LA(1)=='\t'||input.LA(1)==' ' ) { @@ -1541,10 +1540,10 @@ public class LensQueryLexer extends Lexer { try { int _type = WhiteSpaces; int _channel = DEFAULT_TOKEN_CHANNEL; - // LensQuery.g:183:12: ( ( WhiteSpace )+ ) - // LensQuery.g:183:14: ( WhiteSpace )+ + // LensQuery.g:180:12: ( ( WhiteSpace )+ ) + // LensQuery.g:180:14: ( WhiteSpace )+ { - // LensQuery.g:183:14: ( WhiteSpace )+ + // LensQuery.g:180:14: ( WhiteSpace )+ int cnt19=0; loop19: do { @@ -1558,7 +1557,7 @@ public class LensQueryLexer extends Lexer { switch (alt19) { case 1 : - // LensQuery.g:183:14: WhiteSpace + // LensQuery.g:180:14: WhiteSpace { mWhiteSpace(); diff --git a/src/main/java/org/xerial/lens/relation/query/impl/LensQueryParser.java b/src/main/java/org/xerial/lens/relation/query/impl/LensQueryParser.java index 77d974d..718b9b8 100644 --- a/src/main/java/org/xerial/lens/relation/query/impl/LensQueryParser.java +++ b/src/main/java/org/xerial/lens/relation/query/impl/LensQueryParser.java @@ -1,4 +1,4 @@ -// $ANTLR 3.1.3 Mar 17, 2009 19:23:44 LensQuery.g 2009-09-30 22:59:27 +// $ANTLR 3.1.3 Mar 17, 2009 19:23:44 LensQuery.g 2009-10-13 14:02:52 /*-------------------------------------------------------------------------- * Copyright 2009 Taro L. Saito @@ -24,7 +24,6 @@ //-------------------------------------- package org.xerial.lens.relation.query.impl; -import org.xerial.lens.relation.TupleIndex; import org.antlr.runtime.*; @@ -37,61 +36,60 @@ import org.antlr.runtime.tree.*; public class LensQueryParser extends Parser { public static final String[] tokenNames = new String[] { - "", "", "", "", "QUERY", "RELATION", "COMPARE", "OPERATOR", "OPERAND", "PATTERNMATCH", "NODE", "ALIAS", "NODEVALUE", "NAME", "VALUE", "INDEX", "LineBreakChar", "LineComment", "LineBreak", "Digit", "Letter", "HexDigit", "UnicodeChar", "EscapeSequence", "StringChar", "StringChar_s", "String", "Integer", "Frac", "Exp", "Double", "True", "False", "Null", "Lt", "Gt", "Leq", "Geq", "Eq", "Neq", "Match", "Regex", "Dot", "Comma", "Colon", "As", "LParen", "RParen", "Star", "UnsafeUnicodeChar", "SafeFirstLetter", "SafeLetter", "WhiteSpace", "QNameChar", "QName", "WhiteSpaces" + "", "", "", "", "QUERY", "RELATION", "COMPARE", "OPERATOR", "OPERAND", "PATTERNMATCH", "NODE", "ALIAS", "NODEVALUE", "NAME", "VALUE", "LineBreakChar", "LineComment", "LineBreak", "Digit", "Letter", "HexDigit", "UnicodeChar", "EscapeSequence", "StringChar", "StringChar_s", "String", "Integer", "Frac", "Exp", "Double", "True", "False", "Null", "Lt", "Gt", "Leq", "Geq", "Eq", "Neq", "Match", "Regex", "Dot", "Comma", "Colon", "As", "LParen", "RParen", "Star", "UnsafeUnicodeChar", "SafeFirstLetter", "SafeLetter", "WhiteSpace", "QNameChar", "QName", "WhiteSpaces" }; - public static final int INDEX=15; public static final int PATTERNMATCH=9; - public static final int Match=40; - public static final int Regex=41; - public static final int Digit=19; - public static final int Frac=28; - public static final int HexDigit=21; + public static final int Match=39; + public static final int Regex=40; + public static final int Digit=18; + public static final int Frac=27; + public static final int HexDigit=20; public static final int QUERY=4; public static final int ALIAS=11; public static final int VALUE=14; - public static final int Letter=20; - public static final int Comma=43; - public static final int Dot=42; - public static final int EscapeSequence=23; - public static final int Integer=27; - public static final int WhiteSpace=52; + public static final int Letter=19; + public static final int Comma=42; + public static final int Dot=41; + public static final int EscapeSequence=22; + public static final int Integer=26; + public static final int WhiteSpace=51; public static final int OPERATOR=7; - public static final int False=32; - public static final int Colon=44; - public static final int LineComment=17; + public static final int False=31; + public static final int LineComment=16; + public static final int Colon=43; public static final int NODEVALUE=12; - public static final int As=45; - public static final int SafeFirstLetter=50; - public static final int Null=33; - public static final int Star=48; - public static final int Eq=38; - public static final int Exp=29; - public static final int QNameChar=53; + public static final int As=44; + public static final int SafeFirstLetter=49; + public static final int Null=32; + public static final int Star=47; + public static final int Eq=37; + public static final int Exp=28; + public static final int QNameChar=52; public static final int RELATION=5; - public static final int Gt=35; - public static final int RParen=47; - public static final int UnicodeChar=22; - public static final int StringChar=24; - public static final int True=31; + public static final int Gt=34; + public static final int RParen=46; + public static final int UnicodeChar=21; + public static final int StringChar=23; + public static final int True=30; public static final int OPERAND=8; - public static final int LineBreak=18; - public static final int LParen=46; - public static final int String=26; - public static final int SafeLetter=51; - public static final int LineBreakChar=16; + public static final int LineBreak=17; + public static final int LParen=45; + public static final int String=25; + public static final int SafeLetter=50; + public static final int LineBreakChar=15; public static final int COMPARE=6; - public static final int QName=54; + public static final int QName=53; public static final int EOF=-1; - public static final int Geq=37; + public static final int Geq=36; public static final int NODE=10; - public static final int StringChar_s=25; - public static final int Neq=39; - public static final int UnsafeUnicodeChar=49; - public static final int Double=30; - public static final int Lt=34; + public static final int StringChar_s=24; + public static final int Neq=38; + public static final int UnsafeUnicodeChar=48; + public static final int Double=29; + public static final int Lt=33; public static final int NAME=13; - public static final int Leq=36; - public static final int WhiteSpaces=55; + public static final int Leq=35; + public static final int WhiteSpaces=54; // delegates // delegators @@ -118,7 +116,6 @@ public class LensQueryParser extends Parser { public String getGrammarFileName() { return "LensQuery.g"; } - private TupleIndex currentIndex = null; public static class expr_return extends ParserRuleReturnScope { @@ -127,7 +124,7 @@ public class LensQueryParser extends Parser { }; // $ANTLR start "expr" - // LensQuery.g:188:1: expr : relation ; + // LensQuery.g:185:1: expr : relation ; public final LensQueryParser.expr_return expr() throws RecognitionException { LensQueryParser.expr_return retval = new LensQueryParser.expr_return(); retval.start = input.LT(1); @@ -139,12 +136,12 @@ public class LensQueryParser extends Parser { try { - // LensQuery.g:188:5: ( relation ) - // LensQuery.g:189:3: relation + // LensQuery.g:185:5: ( relation ) + // LensQuery.g:186:3: relation { root_0 = (Object)adaptor.nil(); - pushFollow(FOLLOW_relation_in_expr779); + pushFollow(FOLLOW_relation_in_expr774); relation1=relation(); state._fsp--; @@ -171,21 +168,14 @@ public class LensQueryParser extends Parser { } // $ANTLR end "expr" - protected static class relation_scope { - int nodeItemIndex; - TupleIndex relationIndex; - } - protected Stack relation_stack = new Stack(); - public static class relation_return extends ParserRuleReturnScope { Object tree; public Object getTree() { return tree; } }; // $ANTLR start "relation" - // LensQuery.g:192:1: relation : relation_i -> ^( RELATION relation_i INDEX[currentIndex.toString()] ) ; + // LensQuery.g:189:1: relation : relation_i -> ^( RELATION relation_i ) ; public final LensQueryParser.relation_return relation() throws RecognitionException { - relation_stack.push(new relation_scope()); LensQueryParser.relation_return retval = new LensQueryParser.relation_return(); retval.start = input.LT(1); @@ -195,18 +185,11 @@ public class LensQueryParser extends Parser { RewriteRuleSubtreeStream stream_relation_i=new RewriteRuleSubtreeStream(adaptor,"rule relation_i"); - - ((relation_scope)relation_stack.peek()).nodeItemIndex = 1; - if(currentIndex == null) - currentIndex = new TupleIndex(1); - else - currentIndex = new TupleIndex(currentIndex, 1); - try { - // LensQuery.g:210:4: ( relation_i -> ^( RELATION relation_i INDEX[currentIndex.toString()] ) ) - // LensQuery.g:210:6: relation_i + // LensQuery.g:190:4: ( relation_i -> ^( RELATION relation_i ) ) + // LensQuery.g:190:6: relation_i { - pushFollow(FOLLOW_relation_i_in_relation813); + pushFollow(FOLLOW_relation_i_in_relation792); relation_i2=relation_i(); state._fsp--; @@ -225,15 +208,14 @@ public class LensQueryParser extends Parser { RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); root_0 = (Object)adaptor.nil(); - // 210:17: -> ^( RELATION relation_i INDEX[currentIndex.toString()] ) + // 190:17: -> ^( RELATION relation_i ) { - // LensQuery.g:210:20: ^( RELATION relation_i INDEX[currentIndex.toString()] ) + // LensQuery.g:190:20: ^( RELATION relation_i ) { Object root_1 = (Object)adaptor.nil(); root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(RELATION, "RELATION"), root_1); adaptor.addChild(root_1, stream_relation_i.nextTree()); - adaptor.addChild(root_1, (Object)adaptor.create(INDEX, currentIndex.toString())); adaptor.addChild(root_0, root_1); } @@ -248,9 +230,6 @@ public class LensQueryParser extends Parser { retval.tree = (Object)adaptor.rulePostProcessing(root_0); adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); - - currentIndex = currentIndex.parent(); - } catch (RecognitionException re) { reportError(re); @@ -259,7 +238,6 @@ public class LensQueryParser extends Parser { } finally { - relation_stack.pop(); } return retval; } @@ -271,7 +249,7 @@ public class LensQueryParser extends Parser { }; // $ANTLR start "relation_i" - // LensQuery.g:213:1: relation_i : nodeName ( alias )? LParen nodeItem ( Comma nodeItem )* RParen ; + // LensQuery.g:193:1: relation_i : nodeName ( alias )? LParen nodeItem ( Comma nodeItem )* RParen ; public final LensQueryParser.relation_i_return relation_i() throws RecognitionException { LensQueryParser.relation_i_return retval = new LensQueryParser.relation_i_return(); retval.start = input.LT(1); @@ -295,18 +273,18 @@ public class LensQueryParser extends Parser { Object RParen9_tree=null; try { - // LensQuery.g:213:11: ( nodeName ( alias )? LParen nodeItem ( Comma nodeItem )* RParen ) - // LensQuery.g:213:13: nodeName ( alias )? LParen nodeItem ( Comma nodeItem )* RParen + // LensQuery.g:193:11: ( nodeName ( alias )? LParen nodeItem ( Comma nodeItem )* RParen ) + // LensQuery.g:193:13: nodeName ( alias )? LParen nodeItem ( Comma nodeItem )* RParen { root_0 = (Object)adaptor.nil(); - pushFollow(FOLLOW_nodeName_in_relation_i832); + pushFollow(FOLLOW_nodeName_in_relation_i808); nodeName3=nodeName(); state._fsp--; adaptor.addChild(root_0, nodeName3.getTree()); - // LensQuery.g:213:22: ( alias )? + // LensQuery.g:193:22: ( alias )? int alt1=2; int LA1_0 = input.LA(1); @@ -315,9 +293,9 @@ public class LensQueryParser extends Parser { } switch (alt1) { case 1 : - // LensQuery.g:213:22: alias + // LensQuery.g:193:22: alias { - pushFollow(FOLLOW_alias_in_relation_i834); + pushFollow(FOLLOW_alias_in_relation_i810); alias4=alias(); state._fsp--; @@ -329,14 +307,14 @@ public class LensQueryParser extends Parser { } - LParen5=(Token)match(input,LParen,FOLLOW_LParen_in_relation_i837); - pushFollow(FOLLOW_nodeItem_in_relation_i840); + LParen5=(Token)match(input,LParen,FOLLOW_LParen_in_relation_i813); + pushFollow(FOLLOW_nodeItem_in_relation_i816); nodeItem6=nodeItem(); state._fsp--; adaptor.addChild(root_0, nodeItem6.getTree()); - // LensQuery.g:213:46: ( Comma nodeItem )* + // LensQuery.g:193:46: ( Comma nodeItem )* loop2: do { int alt2=2; @@ -349,10 +327,10 @@ public class LensQueryParser extends Parser { switch (alt2) { case 1 : - // LensQuery.g:213:47: Comma nodeItem + // LensQuery.g:193:47: Comma nodeItem { - Comma7=(Token)match(input,Comma,FOLLOW_Comma_in_relation_i843); - pushFollow(FOLLOW_nodeItem_in_relation_i846); + Comma7=(Token)match(input,Comma,FOLLOW_Comma_in_relation_i819); + pushFollow(FOLLOW_nodeItem_in_relation_i822); nodeItem8=nodeItem(); state._fsp--; @@ -367,7 +345,7 @@ public class LensQueryParser extends Parser { } } while (true); - RParen9=(Token)match(input,RParen,FOLLOW_RParen_in_relation_i850); + RParen9=(Token)match(input,RParen,FOLLOW_RParen_in_relation_i826); } @@ -395,7 +373,7 @@ public class LensQueryParser extends Parser { }; // $ANTLR start "nodeName" - // LensQuery.g:216:1: fragment nodeName : ( QName -> NAME[$QName.text] | String -> NAME[$String.text] ); + // LensQuery.g:196:1: fragment nodeName : ( QName -> NAME[$QName.text] | String -> NAME[$String.text] ); public final LensQueryParser.nodeName_return nodeName() throws RecognitionException { LensQueryParser.nodeName_return retval = new LensQueryParser.nodeName_return(); retval.start = input.LT(1); @@ -411,7 +389,7 @@ public class LensQueryParser extends Parser { RewriteRuleTokenStream stream_QName=new RewriteRuleTokenStream(adaptor,"token QName"); try { - // LensQuery.g:218:3: ( QName -> NAME[$QName.text] | String -> NAME[$String.text] ) + // LensQuery.g:198:3: ( QName -> NAME[$QName.text] | String -> NAME[$String.text] ) int alt3=2; int LA3_0 = input.LA(1); @@ -429,9 +407,9 @@ public class LensQueryParser extends Parser { } switch (alt3) { case 1 : - // LensQuery.g:218:5: QName + // LensQuery.g:198:5: QName { - QName10=(Token)match(input,QName,FOLLOW_QName_in_nodeName864); + QName10=(Token)match(input,QName,FOLLOW_QName_in_nodeName840); stream_QName.add(QName10); @@ -447,7 +425,7 @@ public class LensQueryParser extends Parser { RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); root_0 = (Object)adaptor.nil(); - // 218:11: -> NAME[$QName.text] + // 198:11: -> NAME[$QName.text] { adaptor.addChild(root_0, (Object)adaptor.create(NAME, (QName10!=null?QName10.getText():null))); @@ -457,9 +435,9 @@ public class LensQueryParser extends Parser { } break; case 2 : - // LensQuery.g:219:5: String + // LensQuery.g:199:5: String { - String11=(Token)match(input,String,FOLLOW_String_in_nodeName875); + String11=(Token)match(input,String,FOLLOW_String_in_nodeName851); stream_String.add(String11); @@ -475,7 +453,7 @@ public class LensQueryParser extends Parser { RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); root_0 = (Object)adaptor.nil(); - // 219:12: -> NAME[$String.text] + // 199:12: -> NAME[$String.text] { adaptor.addChild(root_0, (Object)adaptor.create(NAME, (String11!=null?String11.getText():null))); @@ -510,7 +488,7 @@ public class LensQueryParser extends Parser { }; // $ANTLR start "alias" - // LensQuery.g:222:1: fragment alias : As QName -> ALIAS[$QName.text] ; + // LensQuery.g:202:1: fragment alias : As QName -> ALIAS[$QName.text] ; public final LensQueryParser.alias_return alias() throws RecognitionException { LensQueryParser.alias_return retval = new LensQueryParser.alias_return(); retval.start = input.LT(1); @@ -526,13 +504,13 @@ public class LensQueryParser extends Parser { RewriteRuleTokenStream stream_QName=new RewriteRuleTokenStream(adaptor,"token QName"); try { - // LensQuery.g:223:6: ( As QName -> ALIAS[$QName.text] ) - // LensQuery.g:223:8: As QName + // LensQuery.g:203:6: ( As QName -> ALIAS[$QName.text] ) + // LensQuery.g:203:8: As QName { - As12=(Token)match(input,As,FOLLOW_As_in_alias892); + As12=(Token)match(input,As,FOLLOW_As_in_alias868); stream_As.add(As12); - QName13=(Token)match(input,QName,FOLLOW_QName_in_alias894); + QName13=(Token)match(input,QName,FOLLOW_QName_in_alias870); stream_QName.add(QName13); @@ -548,7 +526,7 @@ public class LensQueryParser extends Parser { RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); root_0 = (Object)adaptor.nil(); - // 223:17: -> ALIAS[$QName.text] + // 203:17: -> ALIAS[$QName.text] { adaptor.addChild(root_0, (Object)adaptor.create(ALIAS, (QName13!=null?QName13.getText():null))); @@ -581,7 +559,7 @@ public class LensQueryParser extends Parser { }; // $ANTLR start "nodeItem" - // LensQuery.g:226:1: fragment nodeItem : ( nodeName ( alias )? ( nodeValue )? -> ^( NODE nodeName ( alias )? ( nodeValue )? INDEX[new TupleIndex(currentIndex, index).toString()] ) | relation ); + // LensQuery.g:206:1: fragment nodeItem : ( nodeName ( alias )? ( nodeValue )? -> ^( NODE nodeName ( alias )? ( nodeValue )? ) | relation ); public final LensQueryParser.nodeItem_return nodeItem() throws RecognitionException { LensQueryParser.nodeItem_return retval = new LensQueryParser.nodeItem_return(); retval.start = input.LT(1); @@ -600,11 +578,8 @@ public class LensQueryParser extends Parser { RewriteRuleSubtreeStream stream_nodeName=new RewriteRuleSubtreeStream(adaptor,"rule nodeName"); RewriteRuleSubtreeStream stream_nodeValue=new RewriteRuleSubtreeStream(adaptor,"rule nodeValue"); RewriteRuleSubtreeStream stream_alias=new RewriteRuleSubtreeStream(adaptor,"rule alias"); - - int index = ((relation_scope)relation_stack.peek()).nodeItemIndex++; - try { - // LensQuery.g:231:3: ( nodeName ( alias )? ( nodeValue )? -> ^( NODE nodeName ( alias )? ( nodeValue )? INDEX[new TupleIndex(currentIndex, index).toString()] ) | relation ) + // LensQuery.g:208:3: ( nodeName ( alias )? ( nodeValue )? -> ^( NODE nodeName ( alias )? ( nodeValue )? ) | relation ) int alt6=2; int LA6_0 = input.LA(1); @@ -730,15 +705,15 @@ public class LensQueryParser extends Parser { } switch (alt6) { case 1 : - // LensQuery.g:231:5: nodeName ( alias )? ( nodeValue )? + // LensQuery.g:208:5: nodeName ( alias )? ( nodeValue )? { - pushFollow(FOLLOW_nodeName_in_nodeItem919); + pushFollow(FOLLOW_nodeName_in_nodeItem890); nodeName14=nodeName(); state._fsp--; stream_nodeName.add(nodeName14.getTree()); - // LensQuery.g:231:14: ( alias )? + // LensQuery.g:208:14: ( alias )? int alt4=2; int LA4_0 = input.LA(1); @@ -747,9 +722,9 @@ public class LensQueryParser extends Parser { } switch (alt4) { case 1 : - // LensQuery.g:231:14: alias + // LensQuery.g:208:14: alias { - pushFollow(FOLLOW_alias_in_nodeItem921); + pushFollow(FOLLOW_alias_in_nodeItem892); alias15=alias(); state._fsp--; @@ -761,7 +736,7 @@ public class LensQueryParser extends Parser { } - // LensQuery.g:231:21: ( nodeValue )? + // LensQuery.g:208:21: ( nodeValue )? int alt5=2; int LA5_0 = input.LA(1); @@ -770,9 +745,9 @@ public class LensQueryParser extends Parser { } switch (alt5) { case 1 : - // LensQuery.g:231:21: nodeValue + // LensQuery.g:208:21: nodeValue { - pushFollow(FOLLOW_nodeValue_in_nodeItem924); + pushFollow(FOLLOW_nodeValue_in_nodeItem895); nodeValue16=nodeValue(); state._fsp--; @@ -787,7 +762,7 @@ public class LensQueryParser extends Parser { // AST REWRITE - // elements: alias, nodeName, nodeValue + // elements: nodeName, alias, nodeValue // token labels: // rule labels: retval // token list labels: @@ -797,27 +772,26 @@ public class LensQueryParser extends Parser { RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); root_0 = (Object)adaptor.nil(); - // 232:5: -> ^( NODE nodeName ( alias )? ( nodeValue )? INDEX[new TupleIndex(currentIndex, index).toString()] ) + // 209:5: -> ^( NODE nodeName ( alias )? ( nodeValue )? ) { - // LensQuery.g:232:8: ^( NODE nodeName ( alias )? ( nodeValue )? INDEX[new TupleIndex(currentIndex, index).toString()] ) + // LensQuery.g:209:8: ^( NODE nodeName ( alias )? ( nodeValue )? ) { Object root_1 = (Object)adaptor.nil(); root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(NODE, "NODE"), root_1); adaptor.addChild(root_1, stream_nodeName.nextTree()); - // LensQuery.g:232:24: ( alias )? + // LensQuery.g:209:24: ( alias )? if ( stream_alias.hasNext() ) { adaptor.addChild(root_1, stream_alias.nextTree()); } stream_alias.reset(); - // LensQuery.g:232:31: ( nodeValue )? + // LensQuery.g:209:31: ( nodeValue )? if ( stream_nodeValue.hasNext() ) { adaptor.addChild(root_1, stream_nodeValue.nextTree()); } stream_nodeValue.reset(); - adaptor.addChild(root_1, (Object)adaptor.create(INDEX, new TupleIndex(currentIndex, index).toString())); adaptor.addChild(root_0, root_1); } @@ -828,11 +802,11 @@ public class LensQueryParser extends Parser { } break; case 2 : - // LensQuery.g:233:5: relation + // LensQuery.g:210:5: relation { root_0 = (Object)adaptor.nil(); - pushFollow(FOLLOW_relation_in_nodeItem953); + pushFollow(FOLLOW_relation_in_nodeItem921); relation17=relation(); state._fsp--; @@ -867,7 +841,7 @@ public class LensQueryParser extends Parser { }; // $ANTLR start "value" - // LensQuery.g:236:1: fragment value : ( String | Integer | Double | QName ); + // LensQuery.g:213:1: fragment value : ( String | Integer | Double | QName ); public final LensQueryParser.value_return value() throws RecognitionException { LensQueryParser.value_return retval = new LensQueryParser.value_return(); retval.start = input.LT(1); @@ -879,7 +853,7 @@ public class LensQueryParser extends Parser { Object set18_tree=null; try { - // LensQuery.g:238:3: ( String | Integer | Double | QName ) + // LensQuery.g:215:3: ( String | Integer | Double | QName ) // LensQuery.g: { root_0 = (Object)adaptor.nil(); @@ -922,7 +896,7 @@ public class LensQueryParser extends Parser { }; // $ANTLR start "nodeValue" - // LensQuery.g:241:1: fragment nodeValue : ( Colon value -> NODEVALUE[$value.text] | nodeCmp ); + // LensQuery.g:218:1: fragment nodeValue : ( Colon value -> NODEVALUE[$value.text] | nodeCmp ); public final LensQueryParser.nodeValue_return nodeValue() throws RecognitionException { LensQueryParser.nodeValue_return retval = new LensQueryParser.nodeValue_return(); retval.start = input.LT(1); @@ -939,7 +913,7 @@ public class LensQueryParser extends Parser { RewriteRuleTokenStream stream_Colon=new RewriteRuleTokenStream(adaptor,"token Colon"); RewriteRuleSubtreeStream stream_value=new RewriteRuleSubtreeStream(adaptor,"rule value"); try { - // LensQuery.g:243:3: ( Colon value -> NODEVALUE[$value.text] | nodeCmp ) + // LensQuery.g:220:3: ( Colon value -> NODEVALUE[$value.text] | nodeCmp ) int alt7=2; int LA7_0 = input.LA(1); @@ -957,12 +931,12 @@ public class LensQueryParser extends Parser { } switch (alt7) { case 1 : - // LensQuery.g:243:5: Colon value + // LensQuery.g:220:5: Colon value { - Colon19=(Token)match(input,Colon,FOLLOW_Colon_in_nodeValue1002); + Colon19=(Token)match(input,Colon,FOLLOW_Colon_in_nodeValue970); stream_Colon.add(Colon19); - pushFollow(FOLLOW_value_in_nodeValue1004); + pushFollow(FOLLOW_value_in_nodeValue972); value20=value(); state._fsp--; @@ -981,7 +955,7 @@ public class LensQueryParser extends Parser { RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); root_0 = (Object)adaptor.nil(); - // 243:17: -> NODEVALUE[$value.text] + // 220:17: -> NODEVALUE[$value.text] { adaptor.addChild(root_0, (Object)adaptor.create(NODEVALUE, (value20!=null?input.toString(value20.start,value20.stop):null))); @@ -991,11 +965,11 @@ public class LensQueryParser extends Parser { } break; case 2 : - // LensQuery.g:244:5: nodeCmp + // LensQuery.g:221:5: nodeCmp { root_0 = (Object)adaptor.nil(); - pushFollow(FOLLOW_nodeCmp_in_nodeValue1015); + pushFollow(FOLLOW_nodeCmp_in_nodeValue983); nodeCmp21=nodeCmp(); state._fsp--; @@ -1030,7 +1004,7 @@ public class LensQueryParser extends Parser { }; // $ANTLR start "nodeCmp" - // LensQuery.g:247:1: fragment nodeCmp : ( cmpOp value -> ^( COMPARE OPERATOR[$cmpOp.text] OPERAND[$value.text] ) | Match Regex -> ^( PATTERNMATCH OPERAND[$Regex.text] ) ); + // LensQuery.g:224:1: fragment nodeCmp : ( cmpOp value -> ^( COMPARE OPERATOR[$cmpOp.text] OPERAND[$value.text] ) | Match Regex -> ^( PATTERNMATCH OPERAND[$Regex.text] ) ); public final LensQueryParser.nodeCmp_return nodeCmp() throws RecognitionException { LensQueryParser.nodeCmp_return retval = new LensQueryParser.nodeCmp_return(); retval.start = input.LT(1); @@ -1051,7 +1025,7 @@ public class LensQueryParser extends Parser { RewriteRuleSubtreeStream stream_value=new RewriteRuleSubtreeStream(adaptor,"rule value"); RewriteRuleSubtreeStream stream_cmpOp=new RewriteRuleSubtreeStream(adaptor,"rule cmpOp"); try { - // LensQuery.g:249:3: ( cmpOp value -> ^( COMPARE OPERATOR[$cmpOp.text] OPERAND[$value.text] ) | Match Regex -> ^( PATTERNMATCH OPERAND[$Regex.text] ) ) + // LensQuery.g:226:3: ( cmpOp value -> ^( COMPARE OPERATOR[$cmpOp.text] OPERAND[$value.text] ) | Match Regex -> ^( PATTERNMATCH OPERAND[$Regex.text] ) ) int alt8=2; int LA8_0 = input.LA(1); @@ -1069,15 +1043,15 @@ public class LensQueryParser extends Parser { } switch (alt8) { case 1 : - // LensQuery.g:249:5: cmpOp value + // LensQuery.g:226:5: cmpOp value { - pushFollow(FOLLOW_cmpOp_in_nodeCmp1035); + pushFollow(FOLLOW_cmpOp_in_nodeCmp1003); cmpOp22=cmpOp(); state._fsp--; stream_cmpOp.add(cmpOp22.getTree()); - pushFollow(FOLLOW_value_in_nodeCmp1037); + pushFollow(FOLLOW_value_in_nodeCmp1005); value23=value(); state._fsp--; @@ -1096,9 +1070,9 @@ public class LensQueryParser extends Parser { RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); root_0 = (Object)adaptor.nil(); - // 249:17: -> ^( COMPARE OPERATOR[$cmpOp.text] OPERAND[$value.text] ) + // 226:17: -> ^( COMPARE OPERATOR[$cmpOp.text] OPERAND[$value.text] ) { - // LensQuery.g:249:20: ^( COMPARE OPERATOR[$cmpOp.text] OPERAND[$value.text] ) + // LensQuery.g:226:20: ^( COMPARE OPERATOR[$cmpOp.text] OPERAND[$value.text] ) { Object root_1 = (Object)adaptor.nil(); root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(COMPARE, "COMPARE"), root_1); @@ -1115,12 +1089,12 @@ public class LensQueryParser extends Parser { } break; case 2 : - // LensQuery.g:250:5: Match Regex + // LensQuery.g:227:5: Match Regex { - Match24=(Token)match(input,Match,FOLLOW_Match_in_nodeCmp1055); + Match24=(Token)match(input,Match,FOLLOW_Match_in_nodeCmp1023); stream_Match.add(Match24); - Regex25=(Token)match(input,Regex,FOLLOW_Regex_in_nodeCmp1057); + Regex25=(Token)match(input,Regex,FOLLOW_Regex_in_nodeCmp1025); stream_Regex.add(Regex25); @@ -1136,9 +1110,9 @@ public class LensQueryParser extends Parser { RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); root_0 = (Object)adaptor.nil(); - // 250:17: -> ^( PATTERNMATCH OPERAND[$Regex.text] ) + // 227:17: -> ^( PATTERNMATCH OPERAND[$Regex.text] ) { - // LensQuery.g:250:20: ^( PATTERNMATCH OPERAND[$Regex.text] ) + // LensQuery.g:227:20: ^( PATTERNMATCH OPERAND[$Regex.text] ) { Object root_1 = (Object)adaptor.nil(); root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(PATTERNMATCH, "PATTERNMATCH"), root_1); @@ -1179,7 +1153,7 @@ public class LensQueryParser extends Parser { }; // $ANTLR start "cmpOp" - // LensQuery.g:253:1: fragment cmpOp : ( Lt | Gt | Eq | Leq | Geq | Neq ) ; + // LensQuery.g:230:1: fragment cmpOp : ( Lt | Gt | Eq | Leq | Geq | Neq ) ; public final LensQueryParser.cmpOp_return cmpOp() throws RecognitionException { LensQueryParser.cmpOp_return retval = new LensQueryParser.cmpOp_return(); retval.start = input.LT(1); @@ -1191,8 +1165,8 @@ public class LensQueryParser extends Parser { Object set26_tree=null; try { - // LensQuery.g:254:6: ( ( Lt | Gt | Eq | Leq | Geq | Neq ) ) - // LensQuery.g:254:8: ( Lt | Gt | Eq | Leq | Geq | Neq ) + // LensQuery.g:231:6: ( ( Lt | Gt | Eq | Leq | Geq | Neq ) ) + // LensQuery.g:231:8: ( Lt | Gt | Eq | Leq | Geq | Neq ) { root_0 = (Object)adaptor.nil(); @@ -1233,31 +1207,31 @@ public class LensQueryParser extends Parser { - public static final BitSet FOLLOW_relation_in_expr779 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_relation_i_in_relation813 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_nodeName_in_relation_i832 = new BitSet(new long[]{0x0000600000000000L}); - public static final BitSet FOLLOW_alias_in_relation_i834 = new BitSet(new long[]{0x0000400000000000L}); - public static final BitSet FOLLOW_LParen_in_relation_i837 = new BitSet(new long[]{0x0040000004000000L}); - public static final BitSet FOLLOW_nodeItem_in_relation_i840 = new BitSet(new long[]{0x0000880000000000L}); - public static final BitSet FOLLOW_Comma_in_relation_i843 = new BitSet(new long[]{0x0040000004000000L}); - public static final BitSet FOLLOW_nodeItem_in_relation_i846 = new BitSet(new long[]{0x0000880000000000L}); - public static final BitSet FOLLOW_RParen_in_relation_i850 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_QName_in_nodeName864 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_String_in_nodeName875 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_As_in_alias892 = new BitSet(new long[]{0x0040000000000000L}); - public static final BitSet FOLLOW_QName_in_alias894 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_nodeName_in_nodeItem919 = new BitSet(new long[]{0x000031FC00000002L}); - public static final BitSet FOLLOW_alias_in_nodeItem921 = new BitSet(new long[]{0x000011FC00000002L}); - public static final BitSet FOLLOW_nodeValue_in_nodeItem924 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_relation_in_nodeItem953 = new BitSet(new long[]{0x0000000000000002L}); + public static final BitSet FOLLOW_relation_in_expr774 = new BitSet(new long[]{0x0000000000000002L}); + public static final BitSet FOLLOW_relation_i_in_relation792 = new BitSet(new long[]{0x0000000000000002L}); + public static final BitSet FOLLOW_nodeName_in_relation_i808 = new BitSet(new long[]{0x0000300000000000L}); + public static final BitSet FOLLOW_alias_in_relation_i810 = new BitSet(new long[]{0x0000200000000000L}); + public static final BitSet FOLLOW_LParen_in_relation_i813 = new BitSet(new long[]{0x0020000002000000L}); + public static final BitSet FOLLOW_nodeItem_in_relation_i816 = new BitSet(new long[]{0x0000440000000000L}); + public static final BitSet FOLLOW_Comma_in_relation_i819 = new BitSet(new long[]{0x0020000002000000L}); + public static final BitSet FOLLOW_nodeItem_in_relation_i822 = new BitSet(new long[]{0x0000440000000000L}); + public static final BitSet FOLLOW_RParen_in_relation_i826 = new BitSet(new long[]{0x0000000000000002L}); + public static final BitSet FOLLOW_QName_in_nodeName840 = new BitSet(new long[]{0x0000000000000002L}); + public static final BitSet FOLLOW_String_in_nodeName851 = new BitSet(new long[]{0x0000000000000002L}); + public static final BitSet FOLLOW_As_in_alias868 = new BitSet(new long[]{0x0020000000000000L}); + public static final BitSet FOLLOW_QName_in_alias870 = new BitSet(new long[]{0x0000000000000002L}); + public static final BitSet FOLLOW_nodeName_in_nodeItem890 = new BitSet(new long[]{0x000018FE00000002L}); + public static final BitSet FOLLOW_alias_in_nodeItem892 = new BitSet(new long[]{0x000008FE00000002L}); + public static final BitSet FOLLOW_nodeValue_in_nodeItem895 = new BitSet(new long[]{0x0000000000000002L}); + public static final BitSet FOLLOW_relation_in_nodeItem921 = new BitSet(new long[]{0x0000000000000002L}); public static final BitSet FOLLOW_set_in_value0 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_Colon_in_nodeValue1002 = new BitSet(new long[]{0x004000004C000000L}); - public static final BitSet FOLLOW_value_in_nodeValue1004 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_nodeCmp_in_nodeValue1015 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_cmpOp_in_nodeCmp1035 = new BitSet(new long[]{0x004000004C000000L}); - public static final BitSet FOLLOW_value_in_nodeCmp1037 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_Match_in_nodeCmp1055 = new BitSet(new long[]{0x0000020000000000L}); - public static final BitSet FOLLOW_Regex_in_nodeCmp1057 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_set_in_cmpOp1082 = new BitSet(new long[]{0x0000000000000002L}); + public static final BitSet FOLLOW_Colon_in_nodeValue970 = new BitSet(new long[]{0x0020000026000000L}); + public static final BitSet FOLLOW_value_in_nodeValue972 = new BitSet(new long[]{0x0000000000000002L}); + public static final BitSet FOLLOW_nodeCmp_in_nodeValue983 = new BitSet(new long[]{0x0000000000000002L}); + public static final BitSet FOLLOW_cmpOp_in_nodeCmp1003 = new BitSet(new long[]{0x0020000026000000L}); + public static final BitSet FOLLOW_value_in_nodeCmp1005 = new BitSet(new long[]{0x0000000000000002L}); + public static final BitSet FOLLOW_Match_in_nodeCmp1023 = new BitSet(new long[]{0x0000010000000000L}); + public static final BitSet FOLLOW_Regex_in_nodeCmp1025 = new BitSet(new long[]{0x0000000000000002L}); + public static final BitSet FOLLOW_set_in_cmpOp1050 = new BitSet(new long[]{0x0000000000000002L}); } \ No newline at end of file diff --git a/src/main/java/org/xerial/lens/relation/query/lang/RelationExpr.java b/src/main/java/org/xerial/lens/relation/query/lang/RelationExpr.java index fafac17..6ef2a52 100644 --- a/src/main/java/org/xerial/lens/relation/query/lang/RelationExpr.java +++ b/src/main/java/org/xerial/lens/relation/query/lang/RelationExpr.java @@ -31,8 +31,8 @@ import org.antlr.runtime.tree.Tree; import org.xerial.core.XerialErrorCode; import org.xerial.core.XerialException; import org.xerial.lens.Lens; -import org.xerial.lens.relation.TupleElement; import org.xerial.lens.relation.Tuple; +import org.xerial.lens.relation.TupleElement; import org.xerial.lens.relation.query.QuerySet; import org.xerial.lens.relation.query.QuerySet.QuerySetBuilder; import org.xerial.lens.relation.query.impl.LensQueryLexer; @@ -68,8 +68,9 @@ public class RelationExpr extends Tuple { try { LensQueryParser.relation_return ret = p.relation(); if (_logger.isDebugEnabled()) - _logger.debug("\n" - + ANTLRUtil.parseTree((Tree) ret.getTree(), LensQueryParser.tokenNames)); + _logger + .debug(ANTLRUtil + .parseTree((Tree) ret.getTree(), LensQueryParser.tokenNames)); RelationQuery r = Lens.loadANTLRParseTree(RelationQuery.class, (Tree) ret.getTree(), LensQueryParser.tokenNames); diff --git a/src/main/java/org/xerial/silk/SilkWriter.java b/src/main/java/org/xerial/silk/SilkWriter.java index 20b44c1..3eb2e1c 100644 --- a/src/main/java/org/xerial/silk/SilkWriter.java +++ b/src/main/java/org/xerial/silk/SilkWriter.java @@ -447,12 +447,51 @@ public class SilkWriter { return this; } - private String escapeDataLine(String dataLine) { + public SilkWriter text(String text) { + usabilityCheck(); + + attributeParenCloseCheck(true); + + if (formatConfig.indentBeforeDataLine) + printIndent(); + + String line[] = text.split("\r?\n"); + if (line == null) + return this; + + for (String each : line) { + out.print(escapeDataLine(each)); + } + + return this; + } + + public static String escapeText(String text) { + String[] line = text.split("\r?\n"); + if (line == null) + return escapeDataLine(text); + + List buf = new ArrayList(); + for (String each : line) { + buf.add(escapeDataLine(each)); + } + return StringUtil.join(buf, StringUtil.NEW_LINE); + } + + private static Pattern leadingHyphen = Pattern.compile("\\s*-"); + + private static String escapeDataLine(String dataLine) { + + if (dataLine == null) + return dataLine; - if (dataLine.startsWith("-")) { + Matcher m = leadingHyphen.matcher(dataLine); + if (m.lookingAt()) { + int hyphenPos = m.end(); StringBuilder buf = new StringBuilder(); + buf.append(dataLine.substring(0, hyphenPos - 1)); buf.append("\\"); - buf.append(dataLine); + buf.append(dataLine.substring(hyphenPos - 1)); return buf.toString(); } diff --git a/src/main/java/org/xerial/silk/cui/SilkMain.java b/src/main/java/org/xerial/silk/cui/SilkMain.java index 7ca3196..1c83f5a 100644 --- a/src/main/java/org/xerial/silk/cui/SilkMain.java +++ b/src/main/java/org/xerial/silk/cui/SilkMain.java @@ -26,7 +26,6 @@ package org.xerial.silk.cui; import java.io.BufferedReader; import java.io.InputStreamReader; -import java.io.OutputStreamWriter; import java.net.URL; import java.util.HashSet; import java.util.Set; @@ -37,6 +36,7 @@ import org.xerial.core.XerialException; import org.xerial.util.FileResource; import org.xerial.util.log.LogLevel; import org.xerial.util.log.Logger; +import org.xerial.util.log.SimpleLogWriter; import org.xerial.util.opt.Argument; import org.xerial.util.opt.Option; import org.xerial.util.opt.OptionParser; @@ -47,12 +47,10 @@ import org.xerial.util.opt.OptionParser; * @author leo * */ -public class SilkMain -{ +public class SilkMain { private static Logger _logger = Logger.getLogger(SilkMain.class); - public static class SilkGlobalOption - { + public static class SilkGlobalOption { @Option(symbol = "h", longName = "help", description = "display help message") boolean displayHelp = false; @@ -65,48 +63,41 @@ public class SilkMain static Set> availableCommands = new HashSet>(); - static - { - availableCommands.addAll(FileResource.findClasses(SilkMain.class.getPackage(), SilkCommand.class, - SilkMain.class.getClassLoader())); + static { + availableCommands.addAll(FileResource.findClasses(SilkMain.class.getPackage(), + SilkCommand.class, SilkMain.class.getClassLoader())); } - public static void main(String[] args) - { - Logger.getRootLogger().setOutputWriter(new OutputStreamWriter(System.err)); + public static void main(String[] args) { + Logger.getRootLogger().setLogWriter(new SimpleLogWriter(System.err)); SilkGlobalOption globalOption = new SilkGlobalOption(); OptionParser parser = new OptionParser(globalOption); Logger.getRootLogger().setLogLevel(globalOption.logLevel); - try - { + try { parser.parse(args, true); if (globalOption.subCommand == null) throw new XerialException(XerialErrorCode.INVALID_INPUT, "no command"); SilkCommand command = null; - for (Class each : availableCommands) - { - try - { + for (Class each : availableCommands) { + try { command = each.newInstance(); - if (command.getName() != null && command.getName().equals(globalOption.subCommand)) + if (command.getName() != null + && command.getName().equals(globalOption.subCommand)) break; } - catch (InstantiationException e) - { + catch (InstantiationException e) { _logger.warn(e); } - catch (IllegalAccessException e) - { + catch (IllegalAccessException e) { _logger.warn(e); } } - if (command == null) - { + if (command == null) { _logger.error("command is not specified"); return; } @@ -114,18 +105,18 @@ public class SilkMain // OptionParser subCommandOptionParser = new OptionParser(command); // run the sub command - if (globalOption.displayHelp) - { + if (globalOption.displayHelp) { // display help messsage of the command String helpFileName = String.format("help-%s.txt", command.getName()); URL helpFileAddr = FileResource.find(SilkMain.class, helpFileName); if (helpFileAddr == null) - throw new XerialError(XerialErrorCode.RESOURCE_NOT_FOUND, "help file not found: " + helpFileName); + throw new XerialError(XerialErrorCode.RESOURCE_NOT_FOUND, + "help file not found: " + helpFileName); - BufferedReader helpReader = new BufferedReader(new InputStreamReader(helpFileAddr.openStream())); + BufferedReader helpReader = new BufferedReader(new InputStreamReader(helpFileAddr + .openStream())); String line; - while ((line = helpReader.readLine()) != null) - { + while ((line = helpReader.readLine()) != null) { System.out.println(line); } subCommandOptionParser.printUsage(); @@ -137,12 +128,10 @@ public class SilkMain command.execute(); } - catch (Exception e) - { + catch (Exception e) { _logger.error(e); } - catch (Error e) - { + catch (Error e) { e.printStackTrace(); } diff --git a/src/main/java/org/xerial/util/log/LogWriter.java b/src/main/java/org/xerial/util/log/LogWriter.java new file mode 100644 index 0000000..72df36d --- /dev/null +++ b/src/main/java/org/xerial/util/log/LogWriter.java @@ -0,0 +1,39 @@ +/*-------------------------------------------------------------------------- + * Copyright 2009 Taro L. Saito + * + * Licensed 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. + *--------------------------------------------------------------------------*/ +//-------------------------------------- +// XerialJ +// +// LogWriter.java +// Since: Oct 13, 2009 3:24:15 PM +// +// $URL$ +// $Author$ +//-------------------------------------- +package org.xerial.util.log; + +import java.io.IOException; + +/** + * LogWriter interface + * + * @author leo + * + */ +public interface LogWriter { + + public void log(Logger logger, LogLevel logLevel, Object message) throws IOException; + +} diff --git a/src/main/java/org/xerial/util/log/Logger.java b/src/main/java/org/xerial/util/log/Logger.java index 12178bb..38648d0 100644 --- a/src/main/java/org/xerial/util/log/Logger.java +++ b/src/main/java/org/xerial/util/log/Logger.java @@ -28,33 +28,19 @@ import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.FileReader; import java.io.IOException; -import java.io.OutputStreamWriter; import java.io.Reader; -import java.io.Writer; import java.util.Properties; import java.util.TreeMap; -import org.xerial.util.StringUtil; - /** * Logger * * @author leo * */ -public class Logger -{ - private static String[] logPrefix = { "", // ALL - "\033[0;32m", // TRACE - "", // DEBUG - "\033[1;36m", // INFO - "\033[1;33m", // WARN - "\033[1;35m", // ERROR - "\033[1;31m", // FATAL - "", // OFF - "", }; - - private Writer _out = null; +public class Logger { + + private LogWriter writer = null; private LogLevel _threshold = LogLevel.UNSPECIFIED; private String _loggerFullName = ""; private String _loggerShortName = ""; @@ -64,23 +50,20 @@ public class Logger private static TreeMap _loggerHolder = new TreeMap(); private static Logger _rootLogger = new Logger(); - static - { + static { _rootLogger.setLogLevel(LogLevel.INFO); - _rootLogger.setOutputWriter(new OutputStreamWriter(System.err)); + _rootLogger.setLogWriter(new SimpleLogWriter()); + _rootLogger._loggerFullName = "root"; _rootLogger._loggerShortName = "root"; String logLevel = System.getProperty("xerial.loglevel"); - if (logLevel != null) - { + if (logLevel != null) { _rootLogger.setLogLevel(logLevel); } - else - { + else { logLevel = System.getProperty("loglevel"); - if (logLevel != null) - { + if (logLevel != null) { _rootLogger.setLogLevel(logLevel); } } @@ -90,14 +73,11 @@ public class Logger _rootLogger._emitEscapeSequence = Boolean.parseBoolean(useColor); String loggerConfigFile = System.getProperty("log.config"); - if (loggerConfigFile != null) - { - try - { + if (loggerConfigFile != null) { + try { Logger.configure(loggerConfigFile); } - catch (IOException e) - { + catch (IOException e) { e.printStackTrace(); } } @@ -107,30 +87,25 @@ public class Logger /** * hide constructor */ - private Logger() - { + private Logger() { } - private Logger(String fullTypeName) - { + private Logger(String fullTypeName) { _loggerFullName = fullTypeName; String[] packageList = _loggerFullName.split("\\."); _loggerShortName = packageList[packageList.length - 1]; if (packageList.length == 1) _parentLogger = _rootLogger; - else - { + else { String parentPackageName = concatinate(packageList, packageList.length - 1); _parentLogger = getLogger(parentPackageName); } } - private String concatinate(String[] packageList, int upTo) - { + private String concatinate(String[] packageList, int upTo) { StringBuilder builder = new StringBuilder(); - for (int i = 0; i < upTo - 1; i++) - { + for (int i = 0; i < upTo - 1; i++) { builder.append(packageList[i]); builder.append("."); } @@ -138,33 +113,28 @@ public class Logger return builder.toString(); } - public static Logger getLogger(Class< ? > c) - { + public static Logger getLogger(Class< ? > c) { return getLogger(c.getName()); } - public static Logger getLogger(Class< ? > c, String suffix) - { + public static Logger getLogger(Class< ? > c, String suffix) { if (suffix == null || suffix.length() <= 0) return getLogger(c); else return getLogger(String.format("%s-%s", c.getName(), suffix)); } - public static Logger getLogger(Package p) - { + public static Logger getLogger(Package p) { return getLogger(p.getName()); } - public static synchronized Logger getLogger(String fullTypeName) - { + public static synchronized Logger getLogger(String fullTypeName) { if (fullTypeName == null) return _rootLogger; if (_loggerHolder.containsKey(fullTypeName)) return _loggerHolder.get(fullTypeName); - else - { + else { Logger newLogger = new Logger(fullTypeName); _loggerHolder.put(fullTypeName, newLogger); newLogger._emitEscapeSequence = _rootLogger._emitEscapeSequence; @@ -172,75 +142,64 @@ public class Logger } } - public static Logger getRootLogger() - { + public static Logger getRootLogger() { return _rootLogger; } - public static void configure(String configFile) throws IOException - { + public static void configure(String configFile) throws IOException { configure(new BufferedReader(new FileReader(configFile))); } - public static void configure(Reader configurationFileReader) throws IOException - { + public static void configure(Reader configurationFileReader) throws IOException { Properties configProperties = new Properties(); StringBuilder sb = new StringBuilder(); int ch; - while ((ch = configurationFileReader.read()) > 0) - { + while ((ch = configurationFileReader.read()) > 0) { sb.append((char) ch); } ByteArrayInputStream bs = new ByteArrayInputStream(sb.toString().getBytes()); configProperties.load(bs); - for (Object key : configProperties.keySet()) - { + for (Object key : configProperties.keySet()) { String[] lhs = ((String) key).split("#"); String loggerName = lhs[0]; String value = configProperties.getProperty(key.toString()); Logger logger = getLogger(loggerName); - if (lhs.length <= 1) - { + if (lhs.length <= 1) { logger.setLogLevel(value); } - else if (lhs.length > 1) - { + else if (lhs.length > 1) { // packageName:parameter = value configuration String parameter = lhs[1]; - if (parameter.equals("color")) - { - logger.setColor(Boolean.parseBoolean(value)); + if (parameter.equals("color")) { + logger.enableColor(Boolean.parseBoolean(value)); } - else - { + else { System.err.println("unknown configuration parameter: " + parameter); } } - else - { + else { System.err.println("Error in the logger configuration file: " + key); } } } - public String getLoggerName() - { + public String getLoggerName() { return _loggerFullName; } - public void setLogLevel(LogLevel logLevel) - { + public String getLoggerShortName() { + return _loggerShortName; + } + + public void setLogLevel(LogLevel logLevel) { this._threshold = logLevel; } - public void setLogLevel(String logLevel) - { - for (LogLevel l : LogLevel.values()) - { - if (l.name().equalsIgnoreCase(logLevel)) - { + public void setLogLevel(String logLevel) { + for (LogLevel l : LogLevel.values()) { + if (l.name().equalsIgnoreCase(logLevel)) { setLogLevel(l); return; } @@ -249,48 +208,43 @@ public class Logger warn("unknown log level: " + logLevel); } - public LogLevel getLogLevel() - { + public LogLevel getLogLevel() { return _threshold; } - public void setOutputWriter(Writer writer) - { - this._out = writer; + public void setLogWriter(LogWriter writer) { + if (writer == null) + throw new NullPointerException(); + + this.writer = writer; } - public boolean trace(Object message) - { + public boolean trace(Object message) { log(LogLevel.TRACE, message); return true; } - public boolean debug(Object message) - { + public boolean debug(Object message) { log(LogLevel.DEBUG, message); return true; } - public boolean info(Object message) - { + public boolean info(Object message) { log(LogLevel.INFO, message); return true; } - public boolean warn(Object message) - { + public boolean warn(Object message) { log(LogLevel.WARN, message); return true; } - public boolean error(Object message) - { + public boolean error(Object message) { log(LogLevel.ERROR, message); return true; } - public boolean fatal(Object message) - { + public boolean fatal(Object message) { log(LogLevel.FATAL, message); return true; } @@ -301,56 +255,45 @@ public class Logger * @param enable * @return */ - public void setColor(boolean enable) - { + public void enableColor(boolean enable) { _emitEscapeSequence = enable; } /** * @return true when escape sequence is used to output the log */ - public boolean isColorEnabled() - { + public boolean isColorEnabled() { return _emitEscapeSequence; } - public boolean isDebugEnabled() - { + public boolean isDebugEnabled() { return isEnabled(LogLevel.DEBUG); } - public boolean isTraceEnabled() - { + public boolean isTraceEnabled() { return isEnabled(LogLevel.TRACE); } - public boolean isInfoEnabled() - { + public boolean isInfoEnabled() { return isEnabled(LogLevel.INFO); } - public boolean isWarnEnabled() - { + public boolean isWarnEnabled() { return isEnabled(LogLevel.WARN); } - public boolean isErrorEnabled() - { + public boolean isErrorEnabled() { return isEnabled(LogLevel.ERROR); } - public boolean isFatalEnalbed() - { + public boolean isFatalEnalbed() { return isEnabled(LogLevel.FATAL); } - public boolean isEnabled(LogLevel logLevel) - { - if (_threshold == LogLevel.UNSPECIFIED) - { + public boolean isEnabled(LogLevel logLevel) { + if (_threshold == LogLevel.UNSPECIFIED) { Logger parent = this; - while ((parent = parent._parentLogger) != null) - { + while ((parent = parent._parentLogger) != null) { if (parent.getLogLevel() == LogLevel.UNSPECIFIED) continue; @@ -363,42 +306,29 @@ public class Logger return _threshold.ordinal() <= logLevel.ordinal(); } - private Writer getWriter() - { - if (_out != null) - return _out; - else - { + private LogWriter getLogWriter() { + if (writer != null) + return writer; + else { if (_parentLogger != null) - return _parentLogger.getWriter(); + return _parentLogger.getLogWriter(); else return null; } } - private void log(LogLevel logLevel, Object message) - { + private void log(LogLevel logLevel, Object message) { if (!isEnabled(logLevel)) return; - Writer logOut = getWriter(); + LogWriter logOut = getLogWriter(); if (logOut == null) return; // no output is specified - try - { - if (_emitEscapeSequence) - logOut.write(logPrefix[logLevel.ordinal()]); - logOut.write("[" + _loggerShortName + "]\t"); - if (message != null) - logOut.write(message.toString()); - if (_emitEscapeSequence) - logOut.write("\033[0m"); - logOut.write(StringUtil.newline()); - logOut.flush(); + try { + logOut.log(this, logLevel, message); } - catch (IOException e) - { + catch (IOException e) { e.printStackTrace(); } } diff --git a/src/main/java/org/xerial/util/log/SilkLogWriter.java b/src/main/java/org/xerial/util/log/SilkLogWriter.java new file mode 100644 index 0000000..fadc24f --- /dev/null +++ b/src/main/java/org/xerial/util/log/SilkLogWriter.java @@ -0,0 +1,72 @@ +/*-------------------------------------------------------------------------- + * Copyright 2009 Taro L. Saito + * + * Licensed 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. + *--------------------------------------------------------------------------*/ +//-------------------------------------- +// XerialJ +// +// SilkLogWriter.java +// Since: Oct 13, 2009 3:35:01 PM +// +// $URL$ +// $Author$ +//-------------------------------------- +package org.xerial.util.log; + +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.Writer; + +import org.xerial.silk.SilkWriter; +import org.xerial.util.StringUtil; + +/** + * Generating log in Silk format + * + * @author leo + * + */ +public class SilkLogWriter implements LogWriter { + + private Writer logOut = new OutputStreamWriter(System.err); + + public SilkLogWriter() { + + } + + public SilkLogWriter(Writer out) { + this.logOut = out; + } + + public void log(Logger logger, LogLevel logLevel, Object message) throws IOException { + + if (logOut == null) + return; // no output is specified + + synchronized (this) { + logOut.write(String.format("-%s(name:%s)", logLevel, logger.getLoggerShortName())); + + if (message != null) { + logOut.write(StringUtil.NEW_LINE); + String m = SilkWriter.escapeText(message.toString()); + logOut.write(m); + } + + logOut.write(StringUtil.newline()); + logOut.flush(); + } + + } + +} diff --git a/src/main/java/org/xerial/util/log/SimpleLogWriter.java b/src/main/java/org/xerial/util/log/SimpleLogWriter.java new file mode 100644 index 0000000..37c9c1c --- /dev/null +++ b/src/main/java/org/xerial/util/log/SimpleLogWriter.java @@ -0,0 +1,92 @@ +/*-------------------------------------------------------------------------- + * Copyright 2009 Taro L. Saito + * + * Licensed 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. + *--------------------------------------------------------------------------*/ +//-------------------------------------- +// XerialJ +// +// ConsoleLogWriter.java +// Since: Oct 13, 2009 3:25:28 PM +// +// $URL$ +// $Author$ +//-------------------------------------- +package org.xerial.util.log; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.Writer; + +import org.xerial.util.StringUtil; + +/** + * Generating log for console output + * + * @author leo + * + */ +public class SimpleLogWriter implements LogWriter { + + private Writer logOut; + + public SimpleLogWriter() { + logOut = new OutputStreamWriter(System.err); + } + + public SimpleLogWriter(OutputStream out) { + logOut = new OutputStreamWriter(out); + } + + public SimpleLogWriter(Writer out) { + logOut = out; + } + + private static String[] logPrefix = { "", // ALL + "\033[0;32m", // TRACE + "", // DEBUG + "\033[1;36m", // INFO + "\033[1;33m", // WARN + "\033[1;35m", // ERROR + "\033[1;31m", // FATAL + "", // OFF + "", }; + + public void log(Logger logger, LogLevel logLevel, Object message) { + + if (logOut == null) + return; // no output is specified + + try { + synchronized (this) { + if (logger.isColorEnabled()) + logOut.write(logPrefix[logLevel.ordinal()]); + + logOut.write(String.format("[%s] %s", logger.getLoggerShortName(), + message != null ? message.toString() : "")); + if (logger.isColorEnabled()) + logOut.write("\033[0m"); + + logOut.write(StringUtil.newline()); + + logOut.flush(); + } + } + catch (IOException e) { + e.printStackTrace(); + } + + } + +} diff --git a/src/test/java/org/xerial/lens/LensTest.java b/src/test/java/org/xerial/lens/LensTest.java index 8f86846..a6150f5 100644 --- a/src/test/java/org/xerial/lens/LensTest.java +++ b/src/test/java/org/xerial/lens/LensTest.java @@ -371,26 +371,23 @@ public class LensTest { } public static class TupleNode extends NodeBase { + public final int id; public final String name; - public TupleNode(String name) { + public TupleNode(int id, String name) { + this.id = id; this.name = name; } - - @Override - public String toString() { - return name; - } } @Test public void testToSilkTuple() throws Exception { Tuple t = new Tuple(); - t.add(new TupleNode("A")); - t.add(new TupleNode("B")); + t.add(new TupleNode(1, "A")); + t.add(new TupleNode(2, "B")); String s = Lens.toSilk(t); - _logger.info(s); + _logger.debug(s); } } diff --git a/src/test/java/org/xerial/silk/SilkWriterTest.java b/src/test/java/org/xerial/silk/SilkWriterTest.java index 7a3a81b..902c041 100644 --- a/src/test/java/org/xerial/silk/SilkWriterTest.java +++ b/src/test/java/org/xerial/silk/SilkWriterTest.java @@ -202,4 +202,22 @@ public class SilkWriterTest { } + @Test + public void escapeText() throws Exception { + String s = SilkWriter.escapeText("-A(id:1)\n -B"); + + String[] l = s.split("\r?\n"); + + assertEquals("\\-A(id:1)", l[0]); + assertEquals(" \\-B", l[1]); + + } + + @Test + public void escapeBackSlash() throws Exception { + String e = SilkWriter.escapeText("\\-already escaped"); + assertEquals("\\-already escaped", e); + + } + } -- 2.11.0