From 9967a6d17ab644e21d22de5153d446e3174f135a Mon Sep 17 00:00:00 2001 From: leo Date: Wed, 22 Apr 2009 08:06:46 +0000 Subject: [PATCH] handle blank line git-svn-id: http://www.xerial.org/svn/project/XerialJ/trunk/xerial-core@3245 ae02f08e-27ec-0310-ae8c-8ba02fe2eafd --- src/main/java/org/xerial/silk/SilkPullParser.java | 17 --- .../java/org/xerial/silk/SilkPullParserTest.java | 43 +++++++ .../java/org/xerial/silk/impl/SilkLexerTest.java | 110 ---------------- .../java/org/xerial/silk/impl/SilkParserTest.java | 138 --------------------- src/test/java/org/xerial/util/VisitorTest.java | 6 +- 5 files changed, 46 insertions(+), 268 deletions(-) delete mode 100644 src/test/java/org/xerial/silk/impl/SilkLexerTest.java delete mode 100644 src/test/java/org/xerial/silk/impl/SilkParserTest.java diff --git a/src/main/java/org/xerial/silk/SilkPullParser.java b/src/main/java/org/xerial/silk/SilkPullParser.java index 0ffb06d..658bf71 100644 --- a/src/main/java/org/xerial/silk/SilkPullParser.java +++ b/src/main/java/org/xerial/silk/SilkPullParser.java @@ -29,7 +29,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; -import java.util.Map; import org.antlr.runtime.ANTLRStringStream; import org.antlr.runtime.CommonTokenStream; @@ -46,7 +45,6 @@ import org.xerial.silk.impl.SilkParser; import org.xerial.silk.impl.SilkPreamble; import org.xerial.silk.impl.SilkParser.silkLine_return; import org.xerial.util.ArrayDeque; -import org.xerial.util.antlr.ANTLRUtil; import org.xerial.util.bean.impl.BeanUtilImpl; import org.xerial.util.log.Logger; @@ -64,28 +62,13 @@ public class SilkPullParser private static final SilkEvent BlankLineEvent = new SilkEvent(SilkEventType.BLANK_LINE, null); private final SilkLexer lexer; - private CommonTokenStream tokenStream; private SilkParser parser; private int lineCount = 0; private final BufferedReader buffer; private boolean foundEOF = false; - private ArrayDeque eventQueue = new ArrayDeque(); - private static Map tokenTable; - - static - { - try - { - tokenTable = ANTLRUtil.getTokenTable(SilkPullParser.class, "impl/Silk.tokens"); - } - catch (IOException e) - { - e.printStackTrace(); - } - } /** * SilkEvents diff --git a/src/test/java/org/xerial/silk/SilkPullParserTest.java b/src/test/java/org/xerial/silk/SilkPullParserTest.java index 89b6d73..544f639 100644 --- a/src/test/java/org/xerial/silk/SilkPullParserTest.java +++ b/src/test/java/org/xerial/silk/SilkPullParserTest.java @@ -103,4 +103,47 @@ public class SilkPullParserTest { pull("scaffold5001.silk"); } + + @Test + public void testSuzakuConfig() throws Exception + { + pull("suzaku-config.silk"); + } + + @Test + public void testExample() throws Exception + { + pull("example.silk"); + } + + @Test + public void testMicroformat() throws Exception + { + pull("microformat.silk"); + } + + @Test + public void testTab() throws Exception + { + pull("tab.silk"); + } + + @Test + public void testJSON() throws Exception + { + pull("json.silk"); + } + + @Test + public void testType() throws Exception + { + pull("type.silk"); + } + + @Test + public void testLoad() throws Exception + { + pull("plugin/load-binary.silk"); + } + } diff --git a/src/test/java/org/xerial/silk/impl/SilkLexerTest.java b/src/test/java/org/xerial/silk/impl/SilkLexerTest.java deleted file mode 100644 index c61456d..0000000 --- a/src/test/java/org/xerial/silk/impl/SilkLexerTest.java +++ /dev/null @@ -1,110 +0,0 @@ -/*-------------------------------------------------------------------------- - * 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 -// -// SilkLexerTest.java -// Since: Jan 28, 2009 3:40:35 PM -// -// $URL$ -// $Author$ -//-------------------------------------- -package org.xerial.silk.impl; - -import java.io.IOException; -import java.util.Map; - -import org.antlr.runtime.ANTLRReaderStream; -import org.antlr.runtime.CommonTokenStream; -import org.antlr.runtime.RecognitionException; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.xerial.util.FileResource; -import org.xerial.util.StringUtil; -import org.xerial.util.antlr.ANTLRUtil; -import org.xerial.util.log.Logger; - -public class SilkLexerTest -{ - private static Logger _logger = Logger.getLogger(SilkLexerTest.class); - - @Before - public void setUp() throws Exception - {} - - @After - public void tearDown() throws Exception - {} - - static void scan(String filePath) throws IOException, RecognitionException - { - SilkLexer lexer = new SilkLexer(new ANTLRReaderStream(FileResource.open(SilkParserTest.class, filePath))); - CommonTokenStream token = new CommonTokenStream(lexer); - Map tokenTable = ANTLRUtil.getTokenTable(SilkLexer.class, "Silk.tokens"); - _logger.debug("\n" + StringUtil.join(ANTLRUtil.prettyPrintTokenList(token.getTokens(), tokenTable), "\n")); - } - - @Test - public void tokenTest() throws Exception - { - SilkLexer lexer = new SilkLexer( - new ANTLRReaderStream(FileResource.open(SilkLexerTest.class, "../example.silk"))); - - Map tokenTable = ANTLRUtil.getTokenTable(SilkLexer.class, "Silk.tokens"); - - CommonTokenStream tokenStream = new CommonTokenStream(lexer); - _logger - .debug("\n" - + StringUtil.join(ANTLRUtil.prettyPrintTokenList(tokenStream.getTokens(), tokenTable), "\n")); - } - - @Test - public void testOutValue() throws Exception - { - scan("outvalue.silk"); - } - - @Test - public void testBarChart() throws Exception - { - scan("../barchart.silk"); - } - - @Test - public void testMicroFormat() throws Exception - { - scan("../microformat.silk"); - } - - @Test - public void testFunc() throws Exception - { - scan("../func.silk"); - } - - @Test - public void testHeredoc() throws Exception - { - scan("../heredoc.silk"); - } - - @Test - public void testScaffold() throws Exception - { - scan("../scaffold5001.silk"); - } -} diff --git a/src/test/java/org/xerial/silk/impl/SilkParserTest.java b/src/test/java/org/xerial/silk/impl/SilkParserTest.java deleted file mode 100644 index 881ed1e..0000000 --- a/src/test/java/org/xerial/silk/impl/SilkParserTest.java +++ /dev/null @@ -1,138 +0,0 @@ -/*-------------------------------------------------------------------------- - * 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 -// -// SilkParserTest.java -// Since: Jan 28, 2009 6:32:05 PM -// -// $URL$ -// $Author$ -//-------------------------------------- -package org.xerial.silk.impl; - -import java.io.IOException; -import java.util.Map; - -import org.antlr.runtime.ANTLRReaderStream; -import org.antlr.runtime.CommonTokenStream; -import org.antlr.runtime.RecognitionException; -import org.antlr.runtime.Token; -import org.antlr.runtime.tree.Tree; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.xerial.util.FileResource; -import org.xerial.util.StringUtil; -import org.xerial.util.antlr.ANTLRUtil; -import org.xerial.util.log.Logger; - -public class SilkParserTest -{ - private static Logger _logger = Logger.getLogger(SilkParserTest.class); - - @Before - public void setUp() throws Exception - {} - - @After - public void tearDown() throws Exception - {} - - static void parse(String filePath) throws IOException, RecognitionException - { - SilkLexer lexer = new SilkLexer(new ANTLRReaderStream(FileResource.open(SilkParserTest.class, filePath))); - CommonTokenStream token = new CommonTokenStream(lexer); - Map tokenTable = ANTLRUtil.getTokenTable(SilkLexer.class, "Silk.tokens"); - _logger.debug("\n" + StringUtil.join(ANTLRUtil.prettyPrintTokenList(token.getTokens(), tokenTable), "\n")); - SilkParser parser = new SilkParser(token); - SilkParser.silkFile_return ret = parser.silkFile(); - _logger.debug("\n" + ANTLRUtil.parseTree((Tree) ret.getTree(), parser.getTokenNames())); - } - - @Test - public void testExample() throws Exception - { - parse("../example.silk"); - } - - @Test - public void testMicroformat() throws Exception - { - parse("../microformat.silk"); - } - - @Test - public void testFunction() throws Exception - { - parse("../func.silk"); - } - - @Test - public void testSuzakuConfig() throws Exception - { - parse("../suzaku-config.silk"); - } - - @Test - public void testTab() throws Exception - { - parse("../tab.silk"); - } - - @Test - public void testJSON() throws Exception - { - parse("../json.silk"); - } - - @Test - public void testSmall() throws Exception - { - parse("../small.silk"); - } - - @Test - public void testType() throws Exception - { - parse("../type.silk"); - } - - @Test - public void testLoad() throws Exception - { - parse("../plugin/load-binary.silk"); - } - - @Test - public void pullTest() throws Exception - { - String filePath = "../small.silk"; - - SilkLexer lexer = new SilkLexer(new ANTLRReaderStream(FileResource.open(SilkParserTest.class, filePath))); - CommonTokenStream token = new CommonTokenStream(lexer); - Map tokenTable = ANTLRUtil.getTokenTable(SilkLexer.class, "Silk.tokens"); - //_logger.info("\n" + StringUtil.join(ANTLRUtil.prettyPrintTokenList(token.getTokens(), tokenTable), "\n")); - - SilkParser parser = new SilkParser(token); - while (token.LT(1) != Token.EOF_TOKEN) - { - SilkParser.silkLine_return ret = parser.silkLine(); - _logger.debug("\n" + ANTLRUtil.parseTree((Tree) ret.getTree(), parser.getTokenNames())); - } - - } -} diff --git a/src/test/java/org/xerial/util/VisitorTest.java b/src/test/java/org/xerial/util/VisitorTest.java index 624768a..551813c 100644 --- a/src/test/java/org/xerial/util/VisitorTest.java +++ b/src/test/java/org/xerial/util/VisitorTest.java @@ -108,15 +108,15 @@ public class VisitorTest { public void visit(File file) { - _logger.info("visit file: " + file); + _logger.debug("visit file: " + file); } public void visit(Directory dir) { - _logger.info("visit dir: " + dir); + _logger.debug("visit dir: " + dir); for (FileObject each : dir.children) each.accept(this); - _logger.info("leave dir: " + dir); + _logger.debug("leave dir: " + dir); } } -- 2.11.0