Search in sources :

Example 1 with JSKeywordGroup

use of me.itay.idemodthingy.languages.js.tokens.JSKeywordGroup in project IDEProgram by Itay2805.

the class IDELanguageJavaScript method parse.

@Override
public List<Token> parse(Project project, ProjectFile currentFile) {
    List<Token> ret = new ArrayList<>();
    String text = currentFile.getCode();
    if (text.length() == 0) {
        return ret;
    }
    String[] tokens = text.split(DELIMITER);
    StringBuilder sb = new StringBuilder();
    for (String token : tokens) {
        if (text.contains("\"")) {
            if (quote) {
                quote = false;
                ret.add(new DynamicToken(sb.toString()));
                continue;
            }
            quote = true;
        }
        if (quote) {
            sb.append(token);
            continue;
        }
        if (JSKeywordGroup.getTokens().contains(token)) {
            ret.add(new JSKeywordGroup());
            continue;
        }
        if (lastToken.equals("function")) {
            ret.add(new DynamicToken(text));
        }
        lastToken = text;
    }
    return ret;
}
Also used : JSKeywordGroup(me.itay.idemodthingy.languages.js.tokens.JSKeywordGroup) ArrayList(java.util.ArrayList) DynamicToken(me.itay.idemodthingy.programs.bluej.api.tokens.DynamicToken) Token(me.itay.idemodthingy.programs.bluej.api.tokens.Token) DynamicToken(me.itay.idemodthingy.programs.bluej.api.tokens.DynamicToken)

Aggregations

ArrayList (java.util.ArrayList)1 JSKeywordGroup (me.itay.idemodthingy.languages.js.tokens.JSKeywordGroup)1 DynamicToken (me.itay.idemodthingy.programs.bluej.api.tokens.DynamicToken)1 Token (me.itay.idemodthingy.programs.bluej.api.tokens.Token)1