}\r
\r
\r
-// lexer rules \r
+// lexer rules\r
\r
+\r
+// Line Comment\r
+fragment LineBreakChar: '\n' | '\r'; // r: <CR> n : <LF>\r
+LineComment: '#' ~(LineBreakChar)* { $channel=HIDDEN; };\r
+\r
+\r
+LineBreak: ('\r' '\n' | '\r' | '\n' ); \r
WhiteSpace: (' ' | '\r' | '\t' | '\u000C' | '\n') { $channel=HIDDEN; };\r
\r
fragment Digit: '0' .. '9';\r
fragment Letter: 'A' .. 'F' | 'a' .. 'f';\r
fragment HexDigit: Digit | Letter;\r
+fragment NonWhiteUnicodeChar: ~('"' | '\\' | \r
fragment UnicodeChar: ~('"'| '\\');\r
fragment EscapeSequence\r
: '\\' ('\"' | '\\' | '/' | 'b' | 'f' | 'n' | 'r' | 't' | 'u' HexDigit HexDigit HexDigit HexDigit)\r
String: '"' s=StringChar_s '"' { setText($s.text); };\r
\r
\r
-Colon: ':';\r
Comma: ',';\r
Integer: '-'? ('0' | '1'..'9' Digit*);\r
fragment Frac: '.' Digit+;\r
LBracket: '[' ;\r
RBracket: ']' ;\r
\r
+Lt: '<';\r
+Eq: '=';\r
+\r
LParen: '(';\r
RParen: ')';\r
\r
+Star: '*';\r
+\r
+fragment\r
+UnsafeUnicodeChar: '(' | ')' | [' | ']' | '{' | '}' | ',' | ':' | '#' | '<' | '>' | '|' | '*' | '\'' | '"' | '@' | '%' | '\\'; \r
+\r
+fragment:\r
+NonWhiteSpaceChar: ~(UnsafeUncodeChar | WhiteSpace);\r
+\r
+\r
+Symbol: { ':' NonWhiteSpaceChar} => ':' NonWhiteSpaceChar+ ;\r
+\r
Class: 'class';\r
+Includes: 'includes';\r
+End: 'end';\r
+\r
+fragment SafeFirstLetter: 'A' .. 'Z' | 'a' .. 'z';\r
+fragment SafeLetter: SafeFirstLetter | '0' .. '9' | '-' | '_';\r
+\r
+ModuleDef: 'module' WhiteSpace* SafeFistLetter SafeLetter* ('.' SafeFirstLetter SafeLetter)*; \r
+\r
+QName: ~(UnsafeUnicodeChar | WhiteSpace);\r
+\r
\r
// parser rules \r
\r
schema\r
- : (classDefinition)*\r
+ : (classDefinition | moduleDefinition )*\r
; \r
\r
+moduleDefinition:\r
+ ModuleDef LineBreak \r
+ ; \r
+ \r
classDefinition \r
- : Class LBrace RBrace\r
- ;\r
+ : Class LineBreak\r
+ ((includeStatment | attributes) LineBreak)* \r
+ End LineBreak\r
+ ; \r
+ \r
+includeStatement: Includes QName (',' QName); \r
+ \r
+\r
+\r
+\r
+\r
\r
--- /dev/null
+/*--------------------------------------------------------------------------\r
+ * Copyright 2009 Taro L. Saito\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *--------------------------------------------------------------------------*/\r
+//--------------------------------------\r
+// XerialJ\r
+//\r
+// RelationExtractTest.java\r
+// Since: Jul 2, 2009 2:38:03 PM\r
+//\r
+// $URL$\r
+// $Author$\r
+//--------------------------------------\r
+package org.xerial.silk;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.junit.After;\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.xerial.lens.Lens;\r
+import org.xerial.lens.ObjectLens;\r
+import org.xerial.util.FileResource;\r
+import org.xerial.util.log.Logger;\r
+\r
+public class RelationExtractTest\r
+{\r
+ private static Logger _logger = Logger.getLogger(RelationExtractTest.class);\r
+\r
+ @Before\r
+ public void setUp() throws Exception\r
+ {}\r
+\r
+ @After\r
+ public void tearDown() throws Exception\r
+ {}\r
+\r
+ public static class Coordinate\r
+ {\r
+ public String name;\r
+ public String species;\r
+\r
+ }\r
+\r
+ public static class GeneList\r
+ {\r
+ private List<Gene> geneList = new ArrayList<Gene>();\r
+\r
+ public void add(Coordinate coordinate, Gene gene)\r
+ {\r
+ _logger.info(String\r
+ .format("corrdinate %s, gene %s", ObjectLens.toJSON(coordinate), ObjectLens.toJSON(gene)));\r
+ }\r
+\r
+ public void add(Gene g)\r
+ {\r
+ geneList.add(g);\r
+ }\r
+\r
+ public List<Gene> getGeneList()\r
+ {\r
+ return geneList;\r
+ }\r
+\r
+ }\r
+\r
+ public static class Gene\r
+ {\r
+ public String name;\r
+ public long start;\r
+ public String strand;\r
+ public String sequence;\r
+\r
+ }\r
+\r
+ @Test\r
+ public void test() throws Exception\r
+ {\r
+ GeneList geneList = Lens\r
+ .loadSilk(GeneList.class, FileResource.open(RelationExtractTest.class, "sequence.silk"));\r
+\r
+ _logger.info(ObjectLens.toJSON(geneList));\r
+ }\r
+\r
+}\r