当前位置: 首页>>代码示例>>Java>>正文


Java StreamTokenizer.TT_WORD属性代码示例

本文整理汇总了Java中java.io.StreamTokenizer.TT_WORD属性的典型用法代码示例。如果您正苦于以下问题:Java StreamTokenizer.TT_WORD属性的具体用法?Java StreamTokenizer.TT_WORD怎么用?Java StreamTokenizer.TT_WORD使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在java.io.StreamTokenizer的用法示例。


在下文中一共展示了StreamTokenizer.TT_WORD属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseBenchArgs

String[] parseBenchArgs(StreamTokenizer tokens)
    throws IOException, ConfigFormatException
{
    Vector vec = new Vector();
    for (;;) {
        switch (tokens.ttype) {
            case StreamTokenizer.TT_EOF:
            case StreamTokenizer.TT_EOL:
                return (String[]) vec.toArray(new String[vec.size()]);

            case StreamTokenizer.TT_WORD:
            case '"':
                vec.add(tokens.sval);
                tokens.nextToken();
                break;

            default:
                throw new ConfigFormatException("unrecognized arg token " +
                        "on line " + tokens.lineno());
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:Harness.java

示例2: parseBenchName

String parseBenchName(StreamTokenizer tokens)
    throws IOException, ConfigFormatException
{
    String name;
    switch (tokens.ttype) {
        case StreamTokenizer.TT_WORD:
        case '"':
            name = tokens.sval;
            tokens.nextToken();
            return name;

        default:
            throw new ConfigFormatException("missing benchmark name on " +
                    "line " + tokens.lineno());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:Harness.java

示例3: parseBenchWeight

float parseBenchWeight(StreamTokenizer tokens)
    throws IOException, ConfigFormatException
{
    float weight;
    switch (tokens.ttype) {
        case StreamTokenizer.TT_WORD:
        case '"':
            try {
                weight = Float.parseFloat(tokens.sval);
            } catch (NumberFormatException e) {
                throw new ConfigFormatException("illegal weight value \"" +
                        tokens.sval + "\" on line " + tokens.lineno());
            }
            tokens.nextToken();
            return weight;

        default:
            throw new ConfigFormatException("missing weight value on line "
                    + tokens.lineno());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:Harness.java

示例4: toMessage

public String toMessage() {
    switch(ttype) {
    case StreamTokenizer.TT_EOL:
        return "\"EOL\"";
    case StreamTokenizer.TT_EOF:
        return "\"EOF\"";
    case StreamTokenizer.TT_NUMBER:
        return "NUMBER";
    case StreamTokenizer.TT_WORD:
        if (sval == null) {
            return "IDENTIFIER";
        } else {
            return "IDENTIFIER " + sval;
        }
    default:
        if (ttype == (int)'"') {
            String msg = "QUOTED STRING";
            if (sval != null)
                msg = msg + " \"" + sval + "\"";
            return msg;
        } else {
            return "CHARACTER \'" + (char)ttype + "\'";
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:25,代码来源:Token.java

示例5: next

Token next() throws IOException {
  int type = tok.nextToken();
  switch (type) {
    case StreamTokenizer.TT_EOF:
    case StreamTokenizer.TT_EOL:
      return null;
    case StreamTokenizer.TT_NUMBER:
      return new NumToken(tok.nval);
    case StreamTokenizer.TT_WORD:
      return new StrToken(TType.IDENT, tok.sval);
    case '"':
      return new StrToken(TType.QUOT, tok.sval);
    default:
      switch (type) {
        case ',':
          return new Token(TType.COMMA);
        case '(':
          return new Token(TType.LPAREN);
        case ')':
          return new Token(TType.RPAREN);
        default:
          throw new IOException("Unexpected: " + type);
      }
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:25,代码来源:Parser.java

示例6: atTypeSpec

/**
        * Is the current token an indicator of a type specification? E.g., see TypeSpec.isaModeSpec for the full list.
        *
        * @return Whether the current token is a type specification.
        * @throws IOException
        */
private boolean atTypeSpec() throws IOException {
	int tokenRead = tokenizer.ttype();
	if (tokenRead == '+' || tokenRead == '-') {
		if (tokenizer.prevToken() == '\\') { return false; } // Currently at the ISO standard, but semi-weirdly named, predicate '\+'.
		// If '+' or '-' need to see if the next item is a string of digits.
		int nextToken  = getNextToken();
		if (nextToken == StreamTokenizer.TT_WORD && isAllDigits(tokenizer.sval())) {  // This '+' or '-' is a sign in front of some digits.
			tokenizer.pushBack();
			return false;
		}
		if (nextToken == StreamTokenizer.TT_WORD && atInfinity()) { // Have +inf or -inf, which is not a type spec for type 'inf'.
			tokenizer.pushBack();
			return false;
		}
		tokenizer.pushBack();
		return true;
	}
	return TypeSpec.isaModeSpec((char) tokenRead);
}
 
开发者ID:boost-starai,项目名称:BoostSRL,代码行数:25,代码来源:FileParser.java

示例7: getNextNumber

/**
 * Parses the next number in the stream. Numbers with exponents are handled.
 * 
 * @param tokenizer tokenizer over a stream of text in Well-known Text
 *        format. The next token must be a number.
 * @return the next number in the stream
 * @throws ParseException if the next token is not a valid number
 * @throws IOException if an I/O error occurs
 */
private double getNextNumber() throws IOException, ParseException {
    int type = tokenizer.nextToken();
    switch (type) {
    case StreamTokenizer.TT_WORD: {
        try {
            return Double.parseDouble(tokenizer.sval);
        }
        catch (NumberFormatException ex) {
            throw new ParseException("Invalid number: " + tokenizer.sval);
        }
    }
    }
    parseError("number");
    return 0.0;
}
 
开发者ID:gvSIGAssociation,项目名称:gvnix1,代码行数:24,代码来源:EWKTReader.java

示例8: parseListSchema

private static HollowListSchema parseListSchema(String typeName, StreamTokenizer tokenizer) throws IOException {
    int tok = tokenizer.nextToken();

    if(tokenizer.ttype != '<')
        throw new IOException("Invalid Syntax: Expected '<' after 'List' for type " + typeName);

    tok = tokenizer.nextToken();
    if(tok != StreamTokenizer.TT_WORD) {
        log.warning("Invalid Syntax: Expected element type declaration: " + typeName);
    }

    String elementType = tokenizer.sval;

    tok = tokenizer.nextToken();
    if(tokenizer.ttype != '>')
        throw new IOException("Invalid Syntax: Expected '>' element type declaration: " + typeName);

    tok = tokenizer.nextToken();
    if(tokenizer.ttype != ';')
        throw new IOException("Invalid Syntax: Expected semicolon after List schema declaration: " + typeName);

    return new HollowListSchema(typeName, elementType);
}
 
开发者ID:Netflix,项目名称:hollow,代码行数:23,代码来源:HollowSchemaParser.java

示例9: getNextNumber

/**
 * Parses the next number in the stream.
 * Numbers with exponents are handled.
 * <tt>NaN</tt> values are handled correctly, and
 * the case of the "NaN" symbol is not significant.
 *
 * @param tokenizer tokenizer over a stream of text in Well-known Text
 * format. The next token must be a number.
 * @return the next number in the stream
 * @throws ParseException if the next token is not a valid number
 * @throws IOException if an I/O error occurs
 */
private double getNextNumber() throws IOException,
        ParseException {
    int type = this.tokenizer.nextToken();
    switch (type) {
        case StreamTokenizer.TT_WORD: {
            if (this.tokenizer.sval.equalsIgnoreCase(NAN_SYMBOL)) {
                return Double.NaN;
            } else {
                try {
                    return Double.parseDouble(this.tokenizer.sval);
                } catch (NumberFormatException ex) {
                    this.parseErrorWithLine("Invalid number: " + this.tokenizer.sval);
                }
            }
        }
    }
    this.parseErrorExpected("number");
    return 0.0;
}
 
开发者ID:gegy1000,项目名称:Earth,代码行数:31,代码来源:WKTReader.java

示例10: getIntOrCP

/**
 * Read an int or codepoint - codepoint is given as a string
 */
private int getIntOrCP() throws IOException
{
	int val = tkn.nextToken();
	if (val == StreamTokenizer.TT_NUMBER)
	{
		return new Double(tkn.nval).intValue();
	}
	else if (val == StreamTokenizer.TT_WORD)
	{
		return decodeCP(tkn.sval);
	}
	else
	{
		fail("Expecting number, got " + tkn.sval + " on line "
						   + tkn.lineno());
		System.exit(1);
	}
	return 0;
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:22,代码来源:TestProto.java

示例11: processCost

/**
 * Process something like:  cost: p/2, 1.5;
 * Such costs can be used when scoring clauses (default cost is 1.0).
 * @throws ParsingException
 */
private void processCost(boolean isFinal) throws ParsingException, IOException {
	// Have already read the 'cost:"
	int tokenRead = checkForPredicateNamesThatAreCharacters(getNextToken());

	if (tokenRead == StreamTokenizer.TT_WORD) {
		String currentWord = tokenizer.sval();
		PredicateName pName = stringHandler.getPredicateName(currentWord);
		tokenRead = getNextToken();
		if (tokenRead != '/') { throw new ParsingException("Expecting a '/' (slash) in an 'cost' specification, but got: '" + reportLastItemRead() + "'."); }
		int arity = readInteger();

		checkAndConsume(','); // OK if there is a commas separating the items.

		tokenRead = getNextToken();
		double cost = processNumber(tokenRead);

		if (debugLevel > 1) { Utils.println("cost: " + pName + "/" + arity + ", " + cost); }
		pName.setCost(arity, cost, isFinal);
		return;
	}
	throw new ParsingException("Expecting the name of a predicate in a 'cost' but read: '" + reportLastItemRead() + "'.");
}
 
开发者ID:boost-starai,项目名称:BoostSRL,代码行数:27,代码来源:FileParser.java

示例12: fail

/**
 * Print failure message and skip to the next test
	 *
 * @exception 	IOException 	error reading file
 */
private void fail(String msg) throws IOException
{
	System.out.println("FAILED - " + msg + " in line " + tkn.lineno());
	// skip remainder of the test look for endtest or end of file
	int val = tkn.nextToken();
	while (val != StreamTokenizer.TT_EOF)
	{
		if (val == StreamTokenizer.TT_WORD && tkn.sval.toLowerCase(Locale.ENGLISH).equals("endtest"))
			break;

		val = tkn.nextToken();
	}
	failed = true;
	// get ready for next test
	reset();
	// print out stack trace so we know where the failure occurred
	Exception e = new Exception();
	e.printStackTrace();
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:24,代码来源:TestProto.java

示例13: tokenize

private static List<String> tokenize(String sentence) {
    List<String> tokens = new ArrayList<>();
    StreamTokenizer tokenizer = new StreamTokenizer(new StringReader(sentence));

    try {
        while (tokenizer.nextToken() != StreamTokenizer.TT_EOF) {
            if (tokenizer.ttype == StreamTokenizer.TT_WORD) {
                tokens.add(tokenizer.sval);
            }
        }
        return tokens;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:Lambda-3,项目名称:Stargraph,代码行数:15,代码来源:WordNet.java

示例14: getFirstToken

/**
 * Gets next token, skipping empty lines.
 *
 * @throws IOException if reading the next token fails
 */
private void getFirstToken(StreamTokenizer tokenizer) throws IOException {
    while (tokenizer.nextToken() == StreamTokenizer.TT_EOL) {
    }

    if ((tokenizer.ttype == '\'') || (tokenizer.ttype == '"')) {
        tokenizer.ttype = StreamTokenizer.TT_WORD;
    } else if ((tokenizer.ttype == StreamTokenizer.TT_WORD) && (tokenizer.sval.equals("?"))) {
        tokenizer.ttype = '?';
    }
}
 
开发者ID:takun2s,项目名称:smile_1.5.0_java7,代码行数:15,代码来源:ArffParser.java

示例15: parse

@Override
public ParserState parse(StreamTokenizer st) throws IOException, ParseException
{
    int token = st.ttype;
    if (token != StreamTokenizer.TT_WORD || !st.sval.equals(ExpectedResultsParser.SECTION_IDENTIFIER))
    {
        throw new ParseException("expected line " + st.lineno() + " to begin with Section", st.lineno());
    }
    token = st.nextToken();
    if (token != StreamTokenizer.TT_WORD && token != '"')
    {
        throw new ParseException("expected a section name on line " + st.lineno(), st.lineno());
    }
    String testName = st.sval;

    token = st.nextToken();
    String tableName = null;
    if (token == StreamTokenizer.TT_WORD || token == '"')
    {
        tableName = st.sval;
        token = st.nextToken();
    }

    this.getParser().startNewSection(testName, tableName);

    if (token != StreamTokenizer.TT_EOL)
    {
        throw new ParseException("invalid data after the class name on line " + st.lineno(), st.lineno());
    }

    return this.getParser().getHeaderState();
}
 
开发者ID:goldmansachs,项目名称:tablasco,代码行数:32,代码来源:SectionReaderState.java


注:本文中的java.io.StreamTokenizer.TT_WORD属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。