Java Code Examples for java.io.StreamTokenizer#slashSlashComments()

The following examples show how to use java.io.StreamTokenizer#slashSlashComments() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExpectedResultsParser.java    From tablasco with Apache License 2.0 6 votes vote down vote up
private void parse(Reader reader) throws ParseException, IOException
{
    StreamTokenizer st = new StreamTokenizer(reader);
    st.eolIsSignificant(true);
    st.wordChars((int) '_', (int) '_');
    st.parseNumbers();
    st.quoteChar((int) '"');
    // These calls caused comments to be discarded
    st.slashSlashComments(true);
    st.slashStarComments(true);

    // Parse the file
    ParserState currentState = this.getBeginningOfLineState();
    while (currentState != null)
    {
        currentState = currentState.parse(st);
    }
}
 
Example 2
Source File: JaasConfiguration.java    From registry with Apache License 2.0 6 votes vote down vote up
public JaasConfiguration(String loginContextName, String jaasConfigParams) {
    StreamTokenizer tokenizer = new StreamTokenizer(new StringReader(jaasConfigParams));
    tokenizer.slashSlashComments(true);
    tokenizer.slashStarComments(true);
    tokenizer.wordChars('-', '-');
    tokenizer.wordChars('_', '_');
    tokenizer.wordChars('$', '$');

    try {
        configEntries = new ArrayList<>();
        while (tokenizer.nextToken() != StreamTokenizer.TT_EOF) {
            configEntries.add(parseAppConfigurationEntry(tokenizer));
        }
        if (configEntries.isEmpty())
            throw new IllegalArgumentException("Login module not specified in JAAS config");

        this.loginContextName = loginContextName;

    } catch (IOException e) {
        throw new IllegalArgumentException("Unexpected exception while parsing JAAS config", e);
    }
}
 
Example 3
Source File: Lexer.java    From gemini with Apache License 2.0 5 votes vote down vote up
public Lexer(Reader r) {
    input = new StreamTokenizer(r);
    input.resetSyntax();
    input.wordChars('!', '~');
    input.ordinaryChar('/');
    input.whitespaceChars('\u0000', ' ');
    input.slashSlashComments(true);
    input.slashStarComments(true);
    input.eolIsSignificant(false);
    input.commentChar('#');
}
 
Example 4
Source File: IndexFileParser.java    From annotation-tools with MIT License 5 votes vote down vote up
private IndexFileParser(Reader in, String source, AScene scene) {
    this.source = source;
    defs = new LinkedHashMap<>();
    for (AnnotationDef ad : Annotations.standardDefs) {
        try {
            addDef(ad);
        } catch (ParseException e) {
            throw new Error(e);
        }
    }

    st = new StreamTokenizer(in);
    st.slashSlashComments(true);

    // restrict numbers -- don't really need, could interfere with
    // annotation values
    // st.ordinaryChar('-');
    // HMMM this fixes fully-qualified-name strangeness but breaks
    // floating-point numbers
    st.ordinaryChar('.');

    // argggh!!! stupid default needs to be overridden! see java bug 4217680
    st.ordinaryChar('/');

    // for "type-argument"
    st.wordChars('-', '-');

    // java identifiers can contain numbers, _, and $
    st.wordChars('0', '9');
    st.wordChars('_', '_');
    st.wordChars('$', '$');

    this.scene = scene;

    // See if the nonnull analysis picks up on this:
    // curPkgPrefix == ""; // will get changed later anyway
}
 
Example 5
Source File: Lexer.java    From jackrabbit-filevault with Apache License 2.0 5 votes vote down vote up
public Lexer(Reader r, String systemId) {
    this.systemId = systemId;
    st = new StreamTokenizer(r);

    st.eolIsSignificant(false);

    st.lowerCaseMode(false);

    st.slashSlashComments(true);
    st.slashStarComments(true);

    st.wordChars('a', 'z');
    st.wordChars('A', 'Z');
    st.wordChars(':', ':');
    st.wordChars('_', '_');

    st.quoteChar(SINGLE_QUOTE);
    st.quoteChar(DOUBLE_QUOTE);

    st.ordinaryChar(BEGIN_NODE_TYPE_NAME);
    st.ordinaryChar(END_NODE_TYPE_NAME);
    st.ordinaryChar(EXTENDS);
    st.ordinaryChar(LIST_DELIMITER);
    st.ordinaryChar(PROPERTY_DEFINITION);
    st.ordinaryChar(CHILD_NODE_DEFINITION);
    st.ordinaryChar(BEGIN_TYPE);
    st.ordinaryChar(END_TYPE);
    st.ordinaryChar(DEFAULT);
    st.ordinaryChar(CONSTRAINT);
}
 
Example 6
Source File: JavacParser.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Extract the name of a Java source's package, or null if not found. This method is only used
 * before javac parsing to determine the main type name.
 */
@VisibleForTesting
static String packageName(String source) {
  try (StringReader r = new StringReader(source)) {
    StreamTokenizer tokenizer = new StreamTokenizer(r);
    tokenizer.slashSlashComments(true);
    tokenizer.slashStarComments(true);
    StringBuilder sb = new StringBuilder();
    boolean inName = false;
    while (tokenizer.nextToken() != StreamTokenizer.TT_EOF) {
      if (inName) {
        switch (tokenizer.ttype) {
          case ';':
            return sb.length() > 0 ? sb.toString() : null;
          case '.':
            sb.append('.');
            break;
          case StreamTokenizer.TT_WORD:
            sb.append(tokenizer.sval);
            break;
          default:
            inName = false; // Invalid package statement pattern.
            break;
        }
      } else if (tokenizer.ttype == StreamTokenizer.TT_WORD && tokenizer.sval.equals("package")) {
        inName = true;
      }
    }
    return null; // Package statement not found.
  } catch (IOException e) {
    throw new AssertionError("Exception reading string: " + e);
  }
}
 
Example 7
Source File: HollowSchemaParser.java    From hollow with Apache License 2.0 4 votes vote down vote up
private static void configureTokenizer(StreamTokenizer tokenizer) {
    tokenizer.wordChars('_', '_');
    tokenizer.slashSlashComments(true);
    tokenizer.slashStarComments(true);
}
 
Example 8
Source File: CETools.java    From open-ig with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Parse a filter definition string. The format is as follows:<br>
 * "Exact words" "including:colons" id:100 name:fighter*
 * @param filterStr the filter string
 * @return the list of fields and patterns to check
 */
public static List<Pair<String, Pattern>> parseFilter(String filterStr) {
	List<Pair<String, Pattern>> result = new ArrayList<>();

	StreamTokenizer st = new StreamTokenizer(new StringReader(filterStr));
	st.slashSlashComments(false);
	st.slashStarComments(false);
	st.lowerCaseMode(true);
	st.wordChars('*', '*');
	st.wordChars('?', '?');
	st.wordChars('.', '.');
	st.wordChars('@', '@');
	st.wordChars('-', '-');
	st.wordChars('_', '_');
	st.quoteChar('"');

	List<String> tokens = new ArrayList<>();
	try {
		while (true) {
			int tok = st.nextToken();
			if (tok == StreamTokenizer.TT_EOF) {
				break;
			} else
			if (tok == StreamTokenizer.TT_WORD || tok == '"') {
				tokens.add(st.sval);
			} else {
				tokens.add(String.valueOf((char)tok));
			}
		}
	} catch (IOException ex) {
		// ignored
	}
	for (int i = 0; i < tokens.size(); i++) {
		String key = tokens.get(i);
		if (i < tokens.size() - 1 && tokens.get(i + 1).equals(":")) {
			if (i < tokens.size() - 2) {
				result.add(Pair.of(key, wildcardToRegex(tokens.get(i + 2))));
				i += 2;
			} else {
				result.add(Pair.of(key, wildcardToRegex("")));
			}
		} else {
			result.add(Pair.of("", wildcardToRegex(key)));
		}
	}
	
	return result;
}