/** * @param tokenType * @return true when the next token has the specified token type, otherwise * false */ private boolean nextTokenIs(int tokenType) { return tokenStream.LA(1) == tokenType; }
/** * @param tokenType * @return true when the next token has the specified token type, otherwise * false */ private boolean nextTokenIs(int tokenType) { return tokenStream.LA(1) == tokenType; }
/** * This will use the super classes methods to keep track of the * start and end of the original line, not the line buffered by * this class. */ public int findTokenInSuper(int lineStart, int desiredToken) { int lookAhead = 0; int tmpToken; // if this line is a comment, skip scanning it if(super.LA(1) == FortranLexer.LINE_COMMENT) return -1; do { // lookAhead was initialized to 0 lookAhead++; // get the token tmpToken = super.LA(lookAhead); // continue until find what looking for or reach end } while(tmpToken != FortranLexer.EOF && tmpToken != FortranLexer.T_EOS && tmpToken != desiredToken); if(tmpToken == desiredToken) // we found a what we wanted to return lookAhead; return -1; }// end findTokenInSuper()
private String parseNodeName() throws XerialException { Token t = getToken(1); switch (tokenStream.LA(1)) { case PlainOneLine: case String: consume(); return t.getText().trim(); default: throw unexpectedToken(t, PlainOneLine, String); } }
private String parseNodeName() throws XerialException { Token t = getToken(1); switch (tokenStream.LA(1)) { case PlainOneLine: case String: consume(); return t.getText().trim(); default: throw unexpectedToken(t, PlainOneLine, String); } }
private void parseFunctionArg(SilkFunction func) throws XerialException { if (nextTokenIs(String) || nextTokenIs(PlainOneLine)) { if (tokenStream.LA(2) == Colon) { Token key = getToken(1); consume(); consume(); String value = parseNodeValue(); func.addKeyAndValue(key.getText().trim(), value.trim()); return; } } String value = parseNodeValue(); func.addArgument(value); }
private void parseFunctionArg(SilkFunction func) throws XerialException { if (nextTokenIs(String) || nextTokenIs(PlainOneLine)) { if (tokenStream.LA(2) == Colon) { Token key = getToken(1); consume(); consume(); String value = parseNodeValue(); func.addKeyAndValue(key.getText().trim(), value.trim()); return; } } String value = parseNodeValue(); func.addArgument(value); }
private String parseNodeValue() throws XerialException { int nextToken = tokenStream.LA(1); switch (nextToken) { case At: // TODO throw new XerialException(XerialErrorCode.PARSE_ERROR, "nested function is not yet supported"); case PlainOneLine: case String: Token t = getToken(1); consume(); return t.getText(); default: throw unexpectedToken(tokenStream.LT(1), At, PlainOneLine, String); } }
private String parseNodeValue() throws XerialException { int nextToken = tokenStream.LA(1); switch (nextToken) { case At: // TODO throw new XerialException(XerialErrorCode.PARSE_ERROR, "nested function is not yet supported"); case PlainOneLine: case String: Token t = getToken(1); consume(); return t.getText(); default: throw unexpectedToken(tokenStream.LT(1), At, PlainOneLine, String); } }
public SilkElement parse() throws XerialException { switch (tokenStream.LA(1)) { case NodeIndent: if (tokenStream.LA(2) == At) return parseFunction(); else return parseSilkNode().build(); case BlockIndent: { SilkNodeBuilder node = parseSilkNode(); node.setOccurrence(SilkNodeOccurrence.SEQUENCE_PRESERVING_WHITESPACES); return node.build(); } case PullUpNodeIndent: { SilkNodeBuilder node = parseSilkNode(); node.setOccurrence(SilkNodeOccurrence.SEQUENCE_PRESERVING_WHITESPACES); return node.build(); } case FunctionIndent: { SilkFunction func = parseFunction(); return func; } default: throw unexpectedToken(tokenStream.LT(1), NodeIndent, FunctionIndent); } }
public SilkElement parse() throws XerialException { switch (tokenStream.LA(1)) { case NodeIndent: if (tokenStream.LA(2) == At) return parseFunction(); else return parseSilkNode().build(); case BlockIndent: { SilkNodeBuilder node = parseSilkNode(); node.setOccurrence(SilkNodeOccurrence.SEQUENCE_PRESERVING_WHITESPACES); return node.build(); } case PullUpNodeIndent: { SilkNodeBuilder node = parseSilkNode(); node.setOccurrence(SilkNodeOccurrence.SEQUENCE_PRESERVING_WHITESPACES); return node.build(); } case FunctionIndent: { SilkFunction func = parseFunction(); return func; } default: throw unexpectedToken(tokenStream.LT(1), NodeIndent, FunctionIndent); } }
private void parsePlural(SilkNodeBuilder node) { int nextTokenType = tokenStream.LA(1); switch (nextTokenType) { case Star: node.setOccurrence(SilkNodeOccurrence.ZERO_OR_MORE); consume(); break; case Plus: node.setOccurrence(SilkNodeOccurrence.ONE_OR_MORE); consume(); break; case Question: node.setOccurrence(SilkNodeOccurrence.ZERO_OR_ONE); consume(); break; case Seq: node.setOccurrence(SilkNodeOccurrence.SEQUENCE); consume(); break; case TabSeq: node.setOccurrence(SilkNodeOccurrence.TABBED_SEQUENCE); consume(); break; default: // do nothing break; } }
private void parsePlural(SilkNodeBuilder node) { int nextTokenType = tokenStream.LA(1); switch (nextTokenType) { case Star: node.setOccurrence(SilkNodeOccurrence.ZERO_OR_MORE); consume(); break; case Plus: node.setOccurrence(SilkNodeOccurrence.ONE_OR_MORE); consume(); break; case Question: node.setOccurrence(SilkNodeOccurrence.ZERO_OR_ONE); consume(); break; case Seq: node.setOccurrence(SilkNodeOccurrence.SEQUENCE); consume(); break; case TabSeq: node.setOccurrence(SilkNodeOccurrence.TABBED_SEQUENCE); consume(); break; default: // do nothing break; } }
private SilkFunction parseFunction() throws XerialException { SilkFunction func = new SilkFunction(); switch (tokenStream.LA(1)) { case NodeIndent: { Token t = getToken(1); func.setNodeIndent(t.getText()); consume(); parseFunctionInternal(func); return func; } case FunctionIndent: { Token t = getToken(1); // function indent func.setNodeIndent(t.getText()); consume(); Token funcName = testAndConsume(PlainOneLine); func.setName(funcName.getText().trim()); parseFunctionArgs(func); return func; } default: throw unexpectedToken(tokenStream.LT(1), NodeIndent, FunctionIndent); } }
private SilkFunction parseFunction() throws XerialException { SilkFunction func = new SilkFunction(); switch (tokenStream.LA(1)) { case NodeIndent: { Token t = getToken(1); func.setNodeIndent(t.getText()); consume(); parseFunctionInternal(func); return func; } case FunctionIndent: { Token t = getToken(1); // function indent func.setNodeIndent(t.getText()); consume(); Token funcName = testAndConsume(PlainOneLine); func.setName(funcName.getText().trim()); parseFunctionArgs(func); return func; } default: throw unexpectedToken(tokenStream.LT(1), NodeIndent, FunctionIndent); } }
private void parseNodeValue(SilkNodeBuilder node) throws XerialException { int nextToken = tokenStream.LA(1); switch (nextToken) { case At: SilkFunction func = parseFunctionInternal(new SilkFunction()); node.setFunction(func); break; case PlainOneLine: case String: { Token t = getToken(1); consume(); node.setValue(t.getText()); break; } case JSON: { Token t = getToken(1); consume(); node.setJSON(t.getText()); break; } default: throw unexpectedToken(tokenStream.LT(1), At, PlainOneLine, String); } }
private void parseNodeValue(SilkNodeBuilder node) throws XerialException { int nextToken = tokenStream.LA(1); switch (nextToken) { case At: SilkFunction func = parseFunctionInternal(new SilkFunction()); node.setFunction(func); break; case PlainOneLine: case String: { Token t = getToken(1); consume(); node.setValue(t.getText()); break; } case JSON: { Token t = getToken(1); consume(); node.setJSON(t.getText()); break; } default: throw unexpectedToken(tokenStream.LT(1), At, PlainOneLine, String); } }
private SilkNodeBuilder parseSilkNode(SilkNodeBuilder node) throws XerialException { if (!(nextTokenIs(NodeIndent) || nextTokenIs(BlockIndent) || nextTokenIs(PullUpNodeIndent))) throw new XerialException(XerialErrorCode.PARSE_ERROR, "expected a node indent, but " + toString(tokenStream.LT(1))); Token indent = getToken(1); node.setIndent(indent.getText()); consume(); switch (tokenStream.LA(1)) { case LParen: consume(); parseAttributeList(node); testAndConsume(RParen); break; default: { parseNodeItem(node); break; } } return node; }
private SilkNodeBuilder parseSilkNode(SilkNodeBuilder node) throws XerialException { if (!(nextTokenIs(NodeIndent) || nextTokenIs(BlockIndent) || nextTokenIs(PullUpNodeIndent))) throw new XerialException(XerialErrorCode.PARSE_ERROR, "expected a node indent, but " + toString(tokenStream.LT(1))); Token indent = getToken(1); node.setIndent(indent.getText()); consume(); switch (tokenStream.LA(1)) { case LParen: consume(); parseAttributeList(node); testAndConsume(RParen); break; default: { parseNodeItem(node); break; } } return node; }