/src/main/java/com/laytonsmith/core/MethodScriptCompiler.java
Java | 2934 lines | 2163 code | 120 blank | 651 comment | 569 complexity | 50b12a10ffc4b42fd9564cdad46af309 MD5 | raw file
Possible License(s): BSD-3-Clause
Large files files are truncated, but you can click here to view the full file
- package com.laytonsmith.core;
- import com.laytonsmith.PureUtilities.Common.FileUtil;
- import com.laytonsmith.PureUtilities.Common.StringUtils;
- import com.laytonsmith.PureUtilities.SmartComment;
- import com.laytonsmith.annotations.OperatorPreferred;
- import com.laytonsmith.annotations.breakable;
- import com.laytonsmith.annotations.nolinking;
- import com.laytonsmith.annotations.unbreakable;
- import com.laytonsmith.core.Optimizable.OptimizationOption;
- import com.laytonsmith.core.compiler.BranchStatement;
- import com.laytonsmith.core.compiler.CompilerEnvironment;
- import com.laytonsmith.core.compiler.CompilerWarning;
- import com.laytonsmith.core.compiler.FileOptions;
- import com.laytonsmith.core.compiler.KeywordList;
- import com.laytonsmith.core.compiler.TokenStream;
- import com.laytonsmith.core.compiler.analysis.StaticAnalysis;
- import com.laytonsmith.core.compiler.keywords.ObjectDefinitionKeyword;
- import com.laytonsmith.core.constructs.CBareString;
- import com.laytonsmith.core.constructs.CDecimal;
- import com.laytonsmith.core.constructs.CDouble;
- import com.laytonsmith.core.constructs.CFunction;
- import com.laytonsmith.core.constructs.CInt;
- import com.laytonsmith.core.constructs.CKeyword;
- import com.laytonsmith.core.constructs.CLabel;
- import com.laytonsmith.core.constructs.CNull;
- import com.laytonsmith.core.constructs.CPreIdentifier;
- import com.laytonsmith.core.constructs.CSlice;
- import com.laytonsmith.core.constructs.CString;
- import com.laytonsmith.core.constructs.CSymbol;
- import com.laytonsmith.core.constructs.CVoid;
- import com.laytonsmith.core.constructs.Construct;
- import com.laytonsmith.core.constructs.IVariable;
- import com.laytonsmith.core.constructs.Target;
- import com.laytonsmith.core.constructs.Token;
- import com.laytonsmith.core.constructs.Token.TType;
- import com.laytonsmith.core.constructs.Variable;
- import com.laytonsmith.core.environments.Environment;
- import com.laytonsmith.core.environments.GlobalEnv;
- import com.laytonsmith.core.exceptions.CRE.CRECastException;
- import com.laytonsmith.core.exceptions.CRE.CRERangeException;
- import com.laytonsmith.core.exceptions.ConfigCompileException;
- import com.laytonsmith.core.exceptions.ConfigCompileGroupException;
- import com.laytonsmith.core.exceptions.ConfigRuntimeException;
- import com.laytonsmith.core.exceptions.ProgramFlowManipulationException;
- import com.laytonsmith.core.extensions.ExtensionManager;
- import com.laytonsmith.core.extensions.ExtensionTracker;
- import com.laytonsmith.core.functions.Compiler;
- import com.laytonsmith.core.functions.Compiler.__autoconcat__;
- import com.laytonsmith.core.functions.Compiler.__cbrace__;
- import com.laytonsmith.core.functions.Compiler.p;
- import com.laytonsmith.core.functions.Compiler.__smart_string__;
- import com.laytonsmith.core.functions.Math.neg;
- import com.laytonsmith.core.functions.ControlFlow;
- import com.laytonsmith.core.functions.DataHandling;
- import com.laytonsmith.core.functions.Function;
- import com.laytonsmith.core.functions.FunctionBase;
- import com.laytonsmith.core.functions.FunctionList;
- import com.laytonsmith.core.functions.IncludeCache;
- import com.laytonsmith.core.functions.ArrayHandling.array_get;
- import com.laytonsmith.core.natives.interfaces.Mixed;
- import com.laytonsmith.persistence.DataSourceException;
- import java.io.File;
- import java.io.IOException;
- import java.net.URISyntaxException;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Collection;
- import java.util.Collections;
- import java.util.EmptyStackException;
- import java.util.EnumSet;
- import java.util.HashMap;
- import java.util.HashSet;
- import java.util.Iterator;
- import java.util.LinkedList;
- import java.util.List;
- import java.util.ListIterator;
- import java.util.Map;
- import java.util.NoSuchElementException;
- import java.util.Objects;
- import java.util.Set;
- import java.util.Stack;
- import java.util.concurrent.atomic.AtomicInteger;
- import java.util.regex.Pattern;
- /**
- * The MethodScriptCompiler class handles the various stages of compilation and provides helper methods for execution of
- * the compiled trees.
- */
- public final class MethodScriptCompiler {
- private static final EnumSet<Optimizable.OptimizationOption> NO_OPTIMIZATIONS = EnumSet.noneOf(Optimizable.OptimizationOption.class);
- private MethodScriptCompiler() {
- }
- private static final Pattern VAR_PATTERN = Pattern.compile("\\$[\\p{L}0-9_]+");
- private static final Pattern IVAR_PATTERN = Pattern.compile(IVariable.VARIABLE_NAME_REGEX);
- /**
- * Lexes the script, and turns it into a token stream. This looks through the script character by character.
- *
- * @param script The script to lex
- * @param file The file this script came from, or potentially null if the code is from a dynamic source
- * @param inPureMScript If the script is in pure MethodScript, this should be true. Pure MethodScript is defined as
- * code that doesn't have command alias wrappers.
- * @return A stream of tokens
- * @throws ConfigCompileException If compilation fails due to bad syntax
- */
- public static TokenStream lex(String script, Environment env, File file, boolean inPureMScript)
- throws ConfigCompileException {
- return lex(script, env, file, inPureMScript, false);
- }
- /**
- * Lexes the script, and turns it into a token stream. This looks through the script character by character.
- *
- * @param script The script to lex
- * @param env
- * @param file The file this script came from, or potentially null if the code is from a dynamic source
- * @param inPureMScript If the script is in pure MethodScript, this should be true. Pure MethodScript is defined as
- * code that doesn't have command alias wrappers.
- * @param saveAllTokens If this script is planning to be compiled, then this value should always be false, however,
- * if the calling code needs all tokens for informational purposes (and doesn't plan on actually compiling the code)
- * then this can be true. If true, all tokens are saved, including comments and (some) whitespace. Given this lexing
- * stream, the exact source code could be re-constructed.
- *
- * A note on whitespace: The whitespace tokens are not guaranteed to be accurate, however, the column information
- * is. If you have two tokens t1 and t2, each with a value of length 1, where the columns are 1 and 5, then that
- * means there are 4 spaces between the two.
- * @return A stream of tokens
- * @throws ConfigCompileException If compilation fails due to bad syntax
- */
- public static TokenStream lex(String script, Environment env, File file,
- boolean inPureMScript, boolean saveAllTokens) throws ConfigCompileException {
- if(env == null) {
- // We MUST have a CompilerEnvironment, but it doesn't need to be used, but we have to create it at this
- // stage.
- env = Environment.createEnvironment(new CompilerEnvironment());
- }
- if(!env.hasEnv(CompilerEnvironment.class)) {
- env = env.cloneAndAdd(new CompilerEnvironment());
- }
- if(script.isEmpty()) {
- return new TokenStream(new LinkedList<>(), "", new HashMap<>());
- }
- if((int) script.charAt(0) == 65279) {
- // Remove the UTF-8 Byte Order Mark, if present.
- script = script.substring(1);
- }
- final StringBuilder fileOptions = new StringBuilder();
- script = script.replaceAll("\r\n", "\n");
- script = script + "\n";
- final Set<String> keywords = KeywordList.getKeywordNames();
- final TokenStream tokenList = new TokenStream();
- // Set our state variables.
- boolean stateInQuote = false;
- int quoteLineNumberStart = 1;
- boolean inSmartQuote = false;
- int smartQuoteLineNumberStart = 1;
- boolean inComment = false;
- int commentLineNumberStart = 1;
- boolean commentIsBlock = false;
- boolean inOptVar = false;
- boolean inCommand = (!inPureMScript);
- boolean inMultiline = false;
- boolean inSmartComment = false;
- boolean inFileOptions = false;
- boolean inAnnotation = false;
- int fileOptionsLineNumberStart = 1;
- StringBuilder buf = new StringBuilder();
- int lineNum = 1;
- int column = 1;
- int lastColumn = 0;
- Target target = Target.UNKNOWN;
- // Lex the script character by character.
- for(int i = 0; i < script.length(); i++) {
- Character c = script.charAt(i);
- Character c2 = null;
- if(i < script.length() - 1) {
- c2 = script.charAt(i + 1);
- }
- column += i - lastColumn;
- lastColumn = i;
- if(c == '\n') {
- lineNum++;
- column = 1;
- if(!inMultiline && !inPureMScript) {
- inCommand = true;
- }
- }
- if(buf.length() == 0) {
- target = new Target(lineNum, file, column);
- }
- // If we are in file options, add the character to the buffer if it's not a file options end character.
- if(inFileOptions) {
- // For a '>' character outside of a comment, '\>' would have to be used in file options.
- // Other characters than '>'cannot be escaped.
- // If support for more escaped characters would be desired in the future, it could be added here.
- switch(c) {
- case '\\': {
- if(c2 == '>') { // "\>".
- fileOptions.append('>');
- i++;
- continue;
- }
- break;
- }
- case '>': {
- if(saveAllTokens) {
- tokenList.add(new Token(TType.FILE_OPTIONS_STRING,
- fileOptions.toString(), target));
- tokenList.add(new Token(TType.FILE_OPTIONS_END, ">", target));
- }
- inFileOptions = false;
- continue;
- }
- }
- fileOptions.append(c);
- continue;
- }
- // Comment handling. This is bypassed if we are in a string.
- if(!stateInQuote && !inSmartQuote) {
- switch(c) {
- // Block comments start (/* and /**) and Double slash line comment start (//).
- case '/': {
- if(!inComment) {
- if(c2 == '*') { // "/*" or "/**".
- buf.append("/*");
- inComment = true;
- commentIsBlock = true;
- if(i < script.length() - 2 && script.charAt(i + 2) == '*') { // "/**".
- inSmartComment = true;
- buf.append("*");
- i++;
- }
- commentLineNumberStart = lineNum;
- i++;
- continue;
- } else if(c2 == '/') { // "//".
- buf.append("//");
- inComment = true;
- i++;
- continue;
- }
- }
- break;
- }
- // Line comment start (#).
- case '#': {
- if(!inComment) { // "#".
- buf.append("#");
- inComment = true;
- continue;
- }
- break;
- }
- // Block comment end (*/).
- case '*': {
- if(inComment && commentIsBlock && c2 == '/') { // "*/".
- if(saveAllTokens || inSmartComment) {
- buf.append("*/");
- validateTerminatedBidiSequence(buf.toString(), target);
- tokenList.add(new Token(inSmartComment ? TType.SMART_COMMENT : TType.COMMENT,
- buf.toString(), target));
- }
- buf = new StringBuilder();
- target = new Target(lineNum, file, column);
- inComment = false;
- commentIsBlock = false;
- inSmartComment = false;
- i++;
- continue;
- }
- break;
- }
- // Line comment end (\n).
- case '\n': {
- if(inComment && !commentIsBlock) { // "\n".
- inComment = false;
- if(saveAllTokens) {
- validateTerminatedBidiSequence(buf.toString(), target);
- tokenList.add(new Token(TType.COMMENT, buf.toString(), target));
- tokenList.add(new Token(TType.NEWLINE, "\n", new Target(lineNum + 1, file, 0)));
- }
- buf = new StringBuilder();
- target = new Target(lineNum, file, column);
- continue;
- }
- break;
- }
- }
- }
- // If we are in a comment, add the character to the buffer.
- if(inComment || (inAnnotation && c != '}')) {
- buf.append(c);
- continue;
- }
- // Handle non-comment non-quoted characters.
- if(!stateInQuote) {
- // We're not in a comment or quoted string, handle: +=, -=, *=, /=, .=, ->, ++, --, %, **, *, +, -, /,
- // >=, <=, <<<, >>>, <, >, ===, !==, ==, !=, &&&, |||, &&, ||, !, {, }, .., ., ::, [, =, ], :, comma,
- // (, ), ;, and whitespace.
- matched:
- {
- Token token;
- switch(c) {
- case '+': {
- if(c2 == '=') { // "+=".
- token = new Token(TType.PLUS_ASSIGNMENT, "+=", target);
- i++;
- } else if(c2 == '+') { // "++".
- token = new Token(TType.INCREMENT, "++", target);
- i++;
- } else { // "+".
- token = new Token(TType.PLUS, "+", target);
- }
- break;
- }
- case '-': {
- if(c2 == '=') { // "-=".
- token = new Token(TType.MINUS_ASSIGNMENT, "-=", target);
- i++;
- } else if(c2 == '-') { // "--".
- token = new Token(TType.DECREMENT, "--", target);
- i++;
- } else if(c2 == '>') { // "->".
- token = new Token(TType.DEREFERENCE, "->", target);
- i++;
- } else { // "-".
- token = new Token(TType.MINUS, "-", target);
- }
- break;
- }
- case '*': {
- if(c2 == '=') { // "*=".
- token = new Token(TType.MULTIPLICATION_ASSIGNMENT, "*=", target);
- i++;
- } else if(c2 == '*') { // "**".
- token = new Token(TType.EXPONENTIAL, "**", target);
- i++;
- } else { // "*".
- token = new Token(TType.MULTIPLICATION, "*", target);
- }
- break;
- }
- case '/': {
- if(c2 == '=') { // "/=".
- token = new Token(TType.DIVISION_ASSIGNMENT, "/=", target);
- i++;
- } else { // "/".
- // Protect against matching commands.
- if(Character.isLetter(c2)) {
- break matched; // Pretend that division didn't match.
- }
- token = new Token(TType.DIVISION, "/", target);
- }
- break;
- }
- case '.': {
- if(c2 == '=') { // ".=".
- token = new Token(TType.CONCAT_ASSIGNMENT, ".=", target);
- i++;
- } else if(c2 == '.') { // "..".
- token = new Token(TType.SLICE, "..", target);
- i++;
- } else { // ".".
- token = new Token(TType.DOT, ".", target);
- }
- break;
- }
- case '%': {
- token = new Token(TType.MODULO, "%", target);
- break;
- }
- case '>': {
- if(c2 == '=') { // ">=".
- token = new Token(TType.GTE, ">=", target);
- i++;
- } else if(c2 == '>' && i < script.length() - 2 && script.charAt(i + 2) == '>') { // ">>>".
- token = new Token(TType.MULTILINE_START, ">>>", target);
- inMultiline = true;
- i += 2;
- } else { // ">".
- token = new Token(TType.GT, ">", target);
- }
- break;
- }
- case '<': {
- if(c2 == '!') { // "<!".
- if(buf.length() > 0) {
- tokenList.add(new Token(TType.UNKNOWN, buf.toString(), target));
- buf = new StringBuilder();
- target = new Target(lineNum, file, column);
- }
- if(saveAllTokens) {
- tokenList.add(new Token(TType.FILE_OPTIONS_START, "<!", target));
- }
- inFileOptions = true;
- fileOptionsLineNumberStart = lineNum;
- i++;
- continue;
- } else if(c2 == '=') { // "<=".
- token = new Token(TType.LTE, "<=", target);
- i++;
- } else if(c2 == '<' && i < script.length() - 2 && script.charAt(i + 2) == '<') { // "<<<".
- token = new Token(TType.MULTILINE_END, "<<<", target);
- inMultiline = false;
- i += 2;
- } else { // "<".
- token = new Token(TType.LT, "<", target);
- }
- break;
- }
- case '=': {
- if(c2 == '=') {
- if(i < script.length() - 2 && script.charAt(i + 2) == '=') { // "===".
- token = new Token(TType.STRICT_EQUALS, "===", target);
- i += 2;
- } else { // "==".
- token = new Token(TType.EQUALS, "==", target);
- i++;
- }
- } else { // "=".
- if(inCommand) {
- if(inOptVar) {
- token = new Token(TType.OPT_VAR_ASSIGN, "=", target);
- } else {
- token = new Token(TType.ALIAS_END, "=", target);
- inCommand = false;
- }
- } else {
- token = new Token(TType.ASSIGNMENT, "=", target);
- }
- }
- break;
- }
- case '!': {
- if(c2 == '=') {
- if(i < script.length() - 2 && script.charAt(i + 2) == '=') { // "!==".
- token = new Token(TType.STRICT_NOT_EQUALS, "!==", target);
- i += 2;
- } else { // "!=".
- token = new Token(TType.NOT_EQUALS, "!=", target);
- i++;
- }
- } else { // "!".
- token = new Token(TType.LOGICAL_NOT, "!", target);
- }
- break;
- }
- case '&': {
- if(c2 == '&') {
- if(i < script.length() - 2 && script.charAt(i + 2) == '&') { // "&&&".
- token = new Token(TType.DEFAULT_AND, "&&&", target);
- i += 2;
- } else { // "&&".
- token = new Token(TType.LOGICAL_AND, "&&", target);
- i++;
- }
- } else { // "&".
- // Bitwise symbols are not used yet.
- break matched; // Pretend that bitwise AND didn't match.
- // token = new Token(TType.BIT_AND, "&", target);
- }
- break;
- }
- case '|': {
- if(c2 == '|') {
- if(i < script.length() - 2 && script.charAt(i + 2) == '|') { // "|||".
- token = new Token(TType.DEFAULT_OR, "|||", target);
- i += 2;
- } else { // "||".
- token = new Token(TType.LOGICAL_OR, "||", target);
- i++;
- }
- } else { // "|".
- // Bitwise symbols are not used yet.
- break matched; // Pretend that bitwise OR didn't match.
- // token = new Token(TType.BIT_OR, "|", target);
- }
- break;
- }
- // Bitwise symbols are not used yet.
- // case '^': {
- // token = new Token(TType.BIT_XOR, "^", target);
- // break;
- // }
- case ':': {
- if(c2 == ':') { // "::".
- token = new Token(TType.DEREFERENCE, "::", target);
- i++;
- } else { // ":".
- token = new Token(TType.LABEL, ":", target);
- }
- break;
- }
- case '{': {
- token = new Token(TType.LCURLY_BRACKET, "{", target);
- break;
- }
- case '}': {
- if(inAnnotation) {
- // Eventually, this will no longer be a comment type, but for now, we just want
- // to totally ignore annotations, as if they were comments.
- inAnnotation = false;
- token = new Token(/*TType.ANNOTATION*/TType.COMMENT, "@{" + buf.toString() + "}", target);
- buf = new StringBuilder();
- break;
- }
- token = new Token(TType.RCURLY_BRACKET, "}", target);
- break;
- }
- case '[': {
- token = new Token(TType.LSQUARE_BRACKET, "[", target);
- inOptVar = true;
- break;
- }
- case ']': {
- token = new Token(TType.RSQUARE_BRACKET, "]", target);
- inOptVar = false;
- break;
- }
- case ',': {
- token = new Token(TType.COMMA, ",", target);
- break;
- }
- case ';': {
- token = new Token(TType.SEMICOLON, ";", target);
- break;
- }
- case '(': {
- token = new Token(TType.FUNC_START, "(", target);
- // Handle the buffer or previous token, with the knowledge that a FUNC_START follows.
- if(buf.length() > 0) {
- if(saveAllTokens) {
- // In this case, we need to check for keywords first, because we want to go ahead
- // and convert into that stage. In the future, we might want to do this
- // unconditionally, but for now, just go ahead and only do it if saveAllTokens is
- // true, because we know that won't be used by the compiler.
- if(KeywordList.getKeywordByName(buf.toString()) != null) {
- // It's a keyword.
- tokenList.add(new Token(TType.KEYWORD, buf.toString(), target));
- } else {
- // It's not a keyword, but a normal function.
- tokenList.add(new Token(TType.FUNC_NAME, buf.toString(), target));
- }
- } else {
- tokenList.add(new Token(TType.FUNC_NAME, buf.toString(), target));
- }
- buf = new StringBuilder();
- target = new Target(lineNum, file, column);
- } else {
- // The previous token, if unknown, should be changed to a FUNC_NAME. If it's not
- // unknown, we may be doing standalone parenthesis, so auto tack on the __autoconcat__
- // function.
- try {
- int count = 0;
- Iterator<Token> it = tokenList.descendingIterator();
- Token t;
- while((t = it.next()).type == TType.WHITESPACE) {
- count++;
- }
- if(t.type == TType.UNKNOWN) {
- t.type = TType.FUNC_NAME;
- // Go ahead and remove the whitespace here too, they break things.
- count--;
- for(int a = 0; a < count; a++) {
- tokenList.removeLast();
- }
- } else {
- tokenList.add(new Token(TType.FUNC_NAME, "__autoconcat__", target));
- }
- } catch (NoSuchElementException e) {
- // This is the first element on the list, so, it's another autoconcat.
- tokenList.add(new Token(TType.FUNC_NAME, "__autoconcat__", target));
- }
- }
- break;
- }
- case ')': {
- token = new Token(TType.FUNC_END, ")", target);
- break;
- }
- case ' ': { // Whitespace case #1.
- token = new Token(TType.WHITESPACE, " ", target);
- break;
- }
- case '\t': { // Whitespace case #2 (TAB).
- token = new Token(TType.WHITESPACE, "\t", target);
- break;
- }
- case '@': {
- if(c2 == '{') {
- inAnnotation = true;
- i++;
- continue;
- }
- break matched;
- }
- default: {
- // No match was found at this point, so continue matching below.
- break matched;
- }
- }
- // Add previous characters as UNKNOWN token.
- if(buf.length() > 0) {
- tokenList.add(new Token(TType.UNKNOWN, buf.toString(), target));
- buf = new StringBuilder();
- target = new Target(lineNum, file, column);
- }
- // Add the new token to the token list.
- tokenList.add(token);
- // Continue lexing.
- continue;
- }
- }
- // Handle non-comment characters that might start or stop a quoted string.
- switch(c) {
- case '\'': {
- if(stateInQuote && !inSmartQuote) {
- validateTerminatedBidiSequence(buf.toString(), target);
- tokenList.add(new Token(TType.STRING, buf.toString(), target));
- buf = new StringBuilder();
- target = new Target(lineNum, file, column);
- stateInQuote = false;
- continue;
- } else if(!stateInQuote) {
- stateInQuote = true;
- quoteLineNumberStart = lineNum;
- inSmartQuote = false;
- if(buf.length() > 0) {
- tokenList.add(new Token(TType.UNKNOWN, buf.toString(), target));
- buf = new StringBuilder();
- target = new Target(lineNum, file, column);
- }
- continue;
- } else {
- // We're in a smart quote.
- buf.append("'");
- }
- break;
- }
- case '"': {
- if(stateInQuote && inSmartQuote) {
- validateTerminatedBidiSequence(buf.toString(), target);
- tokenList.add(new Token(TType.SMART_STRING, buf.toString(), target));
- buf = new StringBuilder();
- target = new Target(lineNum, file, column);
- stateInQuote = false;
- inSmartQuote = false;
- continue;
- } else if(!stateInQuote) {
- stateInQuote = true;
- inSmartQuote = true;
- smartQuoteLineNumberStart = lineNum;
- if(buf.length() > 0) {
- tokenList.add(new Token(TType.UNKNOWN, buf.toString(), target));
- buf = new StringBuilder();
- target = new Target(lineNum, file, column);
- }
- continue;
- } else {
- // We're in normal quotes.
- buf.append('"');
- }
- break;
- }
- case '\n': {
- // Append a newline to the buffer if it's quoted.
- if(stateInQuote) {
- buf.append(c);
- } else {
- // Newline is not quoted. Move the buffer to an UNKNOWN token and add a NEWLINE token.
- if(buf.length() > 0) {
- tokenList.add(new Token(TType.UNKNOWN, buf.toString(), target));
- buf = new StringBuilder();
- target = new Target(lineNum, file, column);
- }
- tokenList.add(new Token(TType.NEWLINE, "\n", target));
- }
- continue;
- }
- case '\\': {
- // Handle escaped characters in quotes or a single "\" seperator token otherwise.
- // Handle backslash character outside of quotes.
- if(!stateInQuote) {
- tokenList.add(new Token(TType.SEPERATOR, "\\", target));
- break;
- }
- // Handle an escape sign in a quote.
- switch(c2) {
- case '\\':
- if(inSmartQuote) {
- // Escaping of '@' and '\' is handled within __smart_string__.
- buf.append('\\');
- }
- buf.append('\\');
- break;
- case '\'':
- case '"':
- buf.append(c2);
- break;
- case 'n':
- buf.append('\n');
- break;
- case 'r':
- buf.append('\r');
- break;
- case 't':
- buf.append('\t');
- break;
- case '0':
- buf.append('\0');
- break;
- case 'f':
- buf.append('\f');
- break; // Form feed.
- case 'v':
- buf.append('\u000B');
- break; // Vertical TAB.
- case 'a':
- buf.append('\u0007');
- break; // Alarm.
- case 'b':
- buf.append('\u0008');
- break; // Backspace.
- case 'u': { // Unicode (4 characters).
- // Grab the next 4 characters, and check to see if they are numbers.
- if(i + 5 >= script.length()) {
- throw new ConfigCompileException("Unrecognized unicode escape sequence", target);
- }
- String unicode = script.substring(i + 2, i + 6);
- int unicodeNum;
- try {
- unicodeNum = Integer.parseInt(unicode, 16);
- } catch (NumberFormatException e) {
- throw new ConfigCompileException(
- "Unrecognized unicode escape sequence: \\u" + unicode, target);
- }
- buf.append(Character.toChars(unicodeNum));
- i += 4;
- break;
- }
- case 'U': { // Unicode (8 characters).
- // Grab the next 8 characters and check to see if they are numbers.
- if(i + 9 >= script.length()) {
- throw new ConfigCompileException("Unrecognized unicode escape sequence", target);
- }
- String unicode = script.substring(i + 2, i + 10);
- int unicodeNum;
- try {
- unicodeNum = Integer.parseInt(unicode, 16);
- } catch (NumberFormatException e) {
- throw new ConfigCompileException(
- "Unrecognized unicode escape sequence: \\u" + unicode, target);
- }
- buf.append(Character.toChars(unicodeNum));
- i += 8;
- break;
- }
- case '@': {
- if(!inSmartQuote) {
- throw new ConfigCompileException("The escape sequence \\@ is not"
- + " a recognized escape sequence in a non-smart string", target);
- }
- buf.append("\\@");
- break;
- }
- default: {
- // Since we might expand this list later, don't let them use unescaped backslashes.
- throw new ConfigCompileException(
- "The escape sequence \\" + c2 + " is not a recognized escape sequence", target);
- }
- }
- i++;
- continue;
- }
- default: {
- // At this point, only non-comment and non-escaped characters that are not part of a
- // quote start/end are left.
- // Disallow Non-Breaking Space Characters.
- if(!stateInQuote && c == '\u00A0'/*nbsp*/) {
- throw new ConfigCompileException("NBSP character in script", target);
- }
- // Add the characters that didn't match anything to the buffer.
- buf.append(c);
- continue;
- }
- }
- } // End of lexing.
- // Handle unended file options.
- if(inFileOptions) {
- throw new ConfigCompileException("Unended file options. You started the the file options on line "
- + fileOptionsLineNumberStart, target);
- }
- // Handle unended string literals.
- if(stateInQuote) {
- if(inSmartQuote) {
- throw new ConfigCompileException("Unended string literal. You started the last double quote on line "
- + smartQuoteLineNumberStart, target);
- } else {
- throw new ConfigCompileException("Unended string literal. You started the last single quote on line "
- + quoteLineNumberStart, target);
- }
- }
- // Handle unended comment blocks. Since a newline is added to the end of the script, line comments are ended.
- if(inComment || commentIsBlock) {
- throw new ConfigCompileException("Unended block comment. You started the comment on line "
- + commentLineNumberStart, target);
- }
- // Look at the tokens and get meaning from them. Also, look for improper symbol locations
- // and go ahead and absorb unary +- into the token.
- ListIterator<Token> it = tokenList.listIterator(0);
- while(it.hasNext()) {
- Token t = it.next();
- // Combine whitespace tokens into one.
- if(t.type == TType.WHITESPACE && it.hasNext()) {
- Token next;
- if((next = it.next()).type == TType.WHITESPACE) {
- t.value += next.val();
- it.remove(); // Remove 'next'.
- } else {
- it.previous(); // Select 'next' <--.
- }
- it.previous(); // Select 't' <--.
- it.next(); // Select 't' -->.
- }
- // Convert "-" + number to -number if allowed.
- it.previous(); // Select 't' <--.
- if(it.hasPrevious() && t.type == TType.UNKNOWN) {
- Token prev1 = it.previous(); // Select 'prev1' <--.
- if(prev1.type.isPlusMinus()) {
- // Find the first non-whitespace token before the '-'.
- Token prevNonWhitespace = null;
- while(it.hasPrevious()) {
- if(it.previous().type != TType.WHITESPACE) {
- prevNonWhitespace = it.next();
- break;
- }
- }
- while(it.next() != prev1) { // Skip until selection is at 'prev1 -->'.
- }
- if(prevNonWhitespace != null) {
- // Convert "±UNKNOWN" if the '±' is used as a sign (and not an add/subtract operation).
- if(!prevNonWhitespace.type.isIdentifier() // Don't convert "number/string/var ± ...".
- && prevNonWhitespace.type != TType.FUNC_END // Don't convert "func() ± ...".
- && prevNonWhitespace.type != TType.RSQUARE_BRACKET // Don't convert "] ± ..." (arrays).
- && !IVAR_PATTERN.matcher(t.val()).matches() // Don't convert "± @var".
- && !VAR_PATTERN.matcher(t.val()).matches()) { // Don't convert "± $var".
- // It is a negative/positive number: Absorb the sign.
- t.value = prev1.value + t.value;
- it.remove(); // Remove 'prev1'.
- }
- }
- } else {
- it.next(); // Select 'prev1' -->.
- }
- }
- it.next(); // Select 't' -->.
- // Assign a type to all UNKNOWN tokens.
- if(t.type == TType.UNKNOWN) {
- if(t.val().charAt(0) == '/' && t.val().length() > 1) {
- t.type = TType.COMMAND;
- } else if(t.val().equals("$")) {
- t.type = TType.FINAL_VAR;
- } else if(VAR_PATTERN.matcher(t.val()).matches()) {
- t.type = TType.VARIABLE;
- } else if(IVAR_PATTERN.matcher(t.val()).matches()) {
- t.type = TType.IVARIABLE;
- } else if(t.val().charAt(0) == '@') {
- throw new ConfigCompileException("IVariables must match the regex: " + IVAR_PATTERN, t.getTarget());
- } else if(keywords.contains(t.val())) {
- t.type = TType.KEYWORD;
- } else if(t.val().matches("[\t ]*")) {
- t.type = TType.WHITESPACE;
- } else {
- t.type = TType.LIT;
- }
- }
- // Skip this check if we're not in pure mscript.
- if(inPureMScript) {
- if(it.hasNext()) {
- Token next = it.next(); // Select 'next' -->.
- it.previous(); // Select 'next' <--.
- it.previous(); // Select 't' <--.
- if(t.type.isSymbol() && !t.type.isUnary() && !next.type.isUnary()) {
- if(it.hasPrevious()) {
- Token prev1 = it.previous(); // Select 'prev1' <--.
- if(prev1.type.equals(TType.FUNC_START) || prev1.type.equals(TType.COMMA)
- || next.type.equals(TType.FUNC_END) || next.type.equals(TType.COMMA)
- || prev1.type.isSymbol() || next.type.isSymbol()) {
- throw new ConfigCompileException("Unexpected symbol (" + t.val() + ")", t.getTarget());
- }
- it.next(); // Select 'prev1' -->.
- }
- }
- it.next(); // Select 't' -->.
- }
- }
- }
- // Set file options
- {
- Map<String, String> defaults = new HashMap<>();
- List<File> dirs = new ArrayList<>();
- if(file != null) {
- File f = file.getParentFile();
- while(true) {
- if(f == null) {
- break;
- }
- File fileOptionDefaults = new File(f, ".msfileoptions");
- if(fileOptionDefaults.exists()) {
- dirs.add(fileOptionDefaults);
- }
- f = f.getParentFile();
- }
- }
- Collections.reverse(dirs);
- for(File d : dirs) {
- try {
- defaults.putAll(TokenStream.parseFileOptions(FileUtil.read(d), defaults).getRawOptions());
- } catch (IOException ex) {
- throw new ConfigCompileException("Cannot read " + d.getAbsolutePath(), Target.UNKNOWN, ex);
- }
- }
- tokenList.setFileOptions(fileOptions.toString(), defaults);
- }
- // Make sure that the file options are the first non-comment code in the file
- {
- boolean foundCode = false;
- for(Token t : tokenList) {
- if(t.type.isFileOption()) {
- if(foundCode) {
- throw new ConfigCompileException("File options must be the first non-comment section in the"
- + " code", t.target);
- }
- break;
- }
- if(!t.type.isComment() && !t.type.isWhitespace()) {
- foundCode = true;
- }
- }
- }
- {
- // Filename check
- String fileName = tokenList.getFileOptions().getName();
- if(!fileName.isEmpty()) {
- if(!file.getAbsolutePath().replace("\\", "/").endsWith(fileName.replace("\\", "/"))) {
- CompilerWarning warning = new CompilerWarning(file + " has the wrong file name in the file options ("
- + fileName + ")", new Target(0, file, 0), null);
- env.getEnv(CompilerEnvironment.class).addCompilerWarning(null, warning);
- }
- }
- }
- {
- // Required extension check
- // TODO: Add support for specifying required versions
- Collection<ExtensionTracker> exts = ExtensionManager.getTrackers().values();
- Set<String> notFound = new HashSet<>();
- for(String extension : tokenList.getFileOptions().getRequiredExtensions()) {
- boolean found = false;
- for(ExtensionTracker t : exts) {
- if(t.getIdentifier().equalsIgnoreCase(extension)) {
- found = true;
- break;
- }
- }
- if(!found) {
- notFound.add(extension);
- }
- }
- if(!notFound.isEmpty()) {
- throw new ConfigCompileException("Could not compile file, because one or more required"
- + " extensions are not loaded: " + StringUtils.Join(notFound, ", ")
- + ". These extensions must be provided before compilation can continue.",
- new Target(0, file, 0));
- }
- }
- return tokenList;
- }
- /**
- * This function breaks the token stream into parts, separating the aliases/MethodScript from the command triggers
- *
- * @param tokenStream
- * @param envs
- * @return
- * @throws ConfigCompileException
- */
- public static List<Script> preprocess(TokenStream tokenStream,
- Set<Class<? extends Environment.EnvironmentImpl>> envs) throws ConfigCompileException {
- if(tokenStream == null || tokenStream.isEmpty()) {
- return new ArrayList<>();
- }
- // Remove leading newlines.
- while(!tokenStream.isEmpty() && tokenStream.getFirst().type == TType.NEWLINE) {
- tokenStream.removeFirst(); // Remove leading newlines.
- }
- // Return an empty list if there were only newlines.
- if(tokenStream.isEmpty()) {
- return new ArrayList<>();
- }
- // Remove whitespaces and duplicate newlines.
- {
- ListIterator<Token> it = tokenStream.listIterator(0);
- Token token = it.next();
- outerLoop:
- while(true) {
- switch(token.type) {
- case WHITESPACE: {
- it.remove(); // Remove whitespaces.
- if(!it.hasNext()) {
- break outerLoop;
- }
- token = it.next();
- continue outerLoop;
- }
- case NEWLINE: {
- while(it.hasNext()) {
- if((token = it.next()).type == TType.NEWLINE) {
- it.remove(); // Remove duplicate newlines.
- } else {
- continue outerLoop;
- }
- }
- break outerLoop;
- }
- default: {
- if(!it.hasNext()) {
- break outerLoop;
- }
- token = it.next();
- continue outerLoop;
- }
- }
- }
- }
- // Handle multiline constructs.
- // Take out newlines between the '= >>>' and '<<<' tokens (also removing the '>>>' and '<<<' tokens).
- // Also remove comments and also remove newlines that are behind a '\'.
- boolean insideMultiline = false;
- ListIterator<Token> it = tokenStream.listIterator(0);
- Token token = null;
- while(it.hasNext()) {
- token = it.next();
- switch(token.type) {
- case ALIAS_END: { // "=".
- if(it.hasNext()) {
- if(it.next().type == TType.MULTILINE_START) { // "= >>>".
- insideMultiline = true;
- it.remove(); // Remove multiline start (>>>).
- it.previous(); // Select 'token' <---.
- it.next(); // Select 'token' -->.
- } else {
- it.previous(); // Select 'next' <---.
- }
- }
- continue;
- }
- case MULTILINE_END: { // "<<<".
- // Handle multiline end token (<<<) without start.
- if(!insideMultiline) {
- throw new ConfigCompileException(
- "Found multiline end symbol, and no multiline start found", token.target);
- }
- insideMultiline = false;
- it.remove(); // Remove multiline end (<<<).
- continue;
- }
- case MULTILINE_START: { // ">>>".
- // Handle multiline start token (>>>) while already in multiline.
- if(insideMultiline) {
- throw new ConfigCompileException("Did not expect a multiline start symbol here,"
- + " are you missing a multiline end symbol above this line?", token.target);
- }
- // Handle multiline start token (>>>) without alias end (=) in front.
- it.previous(); // Select 'token' <--.
- if(!it.hasPrevious() || it.previous().type != TType.ALIAS_END) {
- throw new ConfigCompileException(
- "Multiline symbol must follow the alias_end (=) symbol", token.target);
- }
- it.next(); // Select 'prev' -->.
- it.next(); // Select 'token' -->.
- continue;
- }
- case NEWLINE: { // "\n".
- // Skip newlines that are inside a multiline construct.
- if(insideMultiline) {
- it.remove(); // Remove newline.
- }
- continue;
- }
- // Remove comments.
- case COMMENT: {
- it.remove(); // Remove comment.
- continue;
- }
- default: {
- // Remove newlines that are behind a '\'.
- if(token.type != TType.STRING && token.val().equals("\\") && it.hasNext()) {
- if(it.next().type == TType.NEWLINE) {
- it.remove(); // Remove newline.
- it.previous(); // Select 'token' <--.
- it.next(); // Select 'token' -->.
- } else {
- it.previous(); // Select 'next' <--.
- }
- }
- }
- }
- }
- assert token != null;
- // Handle missing multiline end token.
- if(insideMultiline) {
- throw new ConfigCompileException("Expecting a multiline end symbol, but your last multiline alias appears to be missing one.", token.target);
- }
- // Now that we have all lines minified, we should be able to split on newlines
- // and easily find the left and right sides.
- List<Token> left = new ArrayList<>();
- List<Token> right = new ArrayList<>();
- List<Script> scripts = new ArrayList<>();
- SmartComment comment = null;
- tokenLoop:
- for(it = tokenStream.listIterator(0); it.hasNext();) {
- Token t = it.next();
- if(t.type == TType.SMART_COMMENT) {
- if(comment != null) {
- // TODO: Double smart comment, this should be an error case
- }
- comment = new SmartComment(t.val());
- t = it.next();
- }
- // Add all tokens until ALIAS_END (=) or end of stream.
- while(t.type != TType.ALIAS_END) {
- if(!it.hasNext()) {
- break tokenLoop; // End of stream.
- }
- left.add(t);
- t = it.next();
- }
- // Add all tokens until NEWLINE (\n).
- while(t.type != TType.NEWLINE) {
- assert it.hasNext(); // All files end with a newline, so end of stream should be impossible here.
- right.add(t);
- t = it.next();
- }
- // Create a new script for the obtained left and right if end of stream has not been reached.
- if(t.type == TType.NEWLINE) {
- // Check for spurious symbols, which indicate an issue with the script, but ignore any whitespace.
- for(int j = left.size() - 1; j >= 0; j--) {
- if(left.get(j).type == TType.NEWLINE) {
- if(j > 0 && left.get(j - 1).type != TType.WHITESPACE) {
- throw new ConfigCompileException(
- "Unexpected token: " + left.get(j - 1).val(), left.get(j - 1).getTarget());
- }
- }
- }
- // Create a new script from the command descriptor (left) and code (right) and add it to the list.
- Script s = new Script(left, right, null, envs, tokenStream.getFileOptions(), comment);
- scripts.add(s);
- // Create new left and right array for the next script.
- left = new ArrayList<>();
- right = new ArrayList<>();
- comment = null;
- }
- }
- // Return the scripts.
- return scripts;
- }
- /**
- * Compiles the token stream into a valid ParseTree. This also includes optimization and reduction.
- *
- * @param stream The token stream, as generated by {@link #lex(String, Environment, File, boolean) lex}
- * @param environment If an environment is already set up, it can be passed in here. The code will tolerate a null
- * value, but if present, should be passed in. If the value is null, a standalone environment will be generated
- * and used.
- * @param envs The environments that are going to be present at runtime. Even if the {@code environment} parameter
- * is null, this still must be non-null and populated with one or more values.
- * @return A fully compiled, optimized, and reduced parse tree. If {@code stream} is null or empty, null is
- * returned.
- * @throws ConfigCompileException If the script contains syntax errors. Additionally, during optimization, certain
- * methods may cause compile errors. Any function that can optimize static occurrences and throws a
- * {@link ConfigRuntimeException} will have that exception converted to a ConfigCompileException.
- * @throws com.laytonsmith.core.exceptions.ConfigCompileGroupException A ConfigCompileGroupException is just
- * a collection of single {@link ConfigCompileException}s.
- */
- public static ParseTree compile(TokenStream stream, Environment environment,
- Set<Class<? extends Environment.EnvironmentImpl>> envs) throws ConfigCompileException,
- ConfigCompileGroupException {
- return compile(stream, environment, envs, new StaticAnalysis(true));
- }
- /**
- * Compiles the token stream into a valid ParseTree. This also includes optimization and reduction.
- *
- * @param stream The token stream, as generated by {@link #lex(String, Environment, File, boolean) lex}
- * @param environment If an environment is already set up, it can be passed in here. The code will tolerate a null
- * value, but if present, should be passed in. If the value is null, a standalone environment will be generated
- * and used.
- * @param envs The environments that are going to be present at runtime. Even if the {@code environment} parameter
- * is null, this still must be non-null and populated with one or more values.
- * @param staticAnalysis The static analysis object, or {@code null} to not perform static analysis. This object
- * is used to perform static analysis on the AST that results from parsing, before any AST optimizations.
- * this method has finished execution.
- * @return A fully compiled, optimized, and reduced parse tree. If {@code stream} is null or empty, null is
- * returned.
- * @throws ConfigCompileException If the script contains syntax errors. Additionally, during optimization, certain
- * methods may cause compile errors. Any function that can optimize static occurrences and throws a
- * {@link ConfigRuntimeException} will have that exception converted to a ConfigCompileException.
- * @throws com.laytonsmith.core.exceptions.ConfigCompileGroupException A ConfigCompileGroupException is just
- * a collection of single {@link ConfigCompileException}s.
- */
- public static ParseTree compile(TokenStream stream, Environment environment,
- Set<Class<? extends Environment.EnvironmentImpl>> envs, StaticAnalysis staticAnalysis)
- throws ConfigCompileException, ConfigCompileGroupException {
- Objects.requireNonNull(envs, () -> "envs parameter must not be null");
- try {
- if(environment == null) {
- // We MUST have a CompilerEnvironment. It doesn't need to be used, but we have to create it at
- // this stage.
- environment = Static.GenerateStandaloneEnvironment(false);
- }
- if(!environment.hasEnv(CompilerEnvironment.class)) {
- Environment e = Static.GenerateStandaloneEnvironment(false);
- environment = environment.cloneAndAdd(e.getEnv(CompilerEnvironment.class));
- }
- } catch (IOException | DataSourceException | URISyntaxException | Profiles.InvalidProfileException ex) {
- throw new RuntimeException(ex);
- }
- Set<ConfigCompileException> compilerErrors = new HashSet<>();
- if(stream == null || stream.isEmpty()) {
- return null;
- }
- Target unknown;
- try {
- //Instead of using Target.UNKNOWN, we can at least set the file.
- unknown = new Target(0, stream.get(0).target.file(), 0);
- } catch (Exception e) {
- unknown = Target.UNKNOWN;
- }
- // Remove all newlines and whitespaces.
- ListIterator<Token> it = stream.listIterator(0);
- while(it.hasNext()) {
- if(it.next().type.isWhitespace()) {
- it.remove();
- }
- }
- // Get the file options.
- final FileOptions fileOptions = stream.getFileOptions();
- final ParseTree rootNode = new ParseTree(fileOptions);
- rootNode.setData(CNull.NULL);
- ParseTree tree = rootNode;
- Stack<ParseTree> parents = new Stack<>();
- /**
- * constructCount is used to determine if we need to use autoconcat when reaching a FUNC_END. The previous
- * constructs, if the count is greater than 1, will be moved down into an autoconcat.
- */
- Stack<AtomicInteger> constructCount = new Stack<>();
- constructCount.push(new AtomicInteger(0));
- parents.push(tree);
- tree.addChild(new ParseTree(new CFunction(__autoconcat__.NAME, unknown), fileOptions));
- parents.push(tree.getChildAt(0));
- tree = tree.getChildAt(0);
- constructCount.push(new AtomicInteger(0));
- /**
- * The array stack is used to keep track of the number of square braces in use.
- */
- Stack<AtomicInteger> arrayStack = new Stack<>();
- arrayStack.add(new AtomicInteger(-1));
- Stack<AtomicInteger> minusArrayStack = new Stack<>();
- Stack<AtomicInteger> minusFuncStack = new Stack<>();
- int parens = 0;
- Token t = null;
- int braceCount = 0;
- boolean inObjectDefinition = false;
- // Create a Token array to iterate over, rather than using the LinkedList's O(n) get() method.
- Token[] tokenArray = stream.toArray(new Token[stream.size()]);
- for(int i = 0; i < tokenArray.length; i++) {
- t = tokenArray[i];
- Token prev1 = i - 1 >= 0 ? tokenArray[i - 1] : new Token(TType.UNKNOWN, "", t.target);
- Token next1 = i + 1 < stream.size() ? tokenArray[i + 1] : new Token(TType.UNKNOWN, "", t.target);
- Token next2 = i + 2 < stream.size() ? tokenArray[i + 2] : new Token(TType.UNKNOWN, "", t.target);
- Token next3 = i + 3 < stream.size() ? tokenArray[i + 3] : new Token(TType.UNKNOWN, "", t.target);
- // Brace handling
- if(t.type == TType.LCURLY_BRACKET) {
- inObjectDefinition = false;
- ParseTree b = new ParseTree(new CFunction(__cbrace__.NAME, t.getTarget()), fileOptions);
- tree.addChild(b);
- tree = b;
- parents.push(b);
- braceCount++;
- constructCount.push(new AtomicInteger(0));
- continue;
- }
- if(t.type == TType.RCURLY_BRACKET) {
- if(braceCount == 0) {
- throw new ConfigCompileException("Unexpected end curly brace", t.target);
- }
- braceCount--;
- if(constructCount.peek().get() > 1) {
- //We need to autoconcat some stuff
- int stacks = constructCount.peek().get();
- int replaceAt = tree.getChildren().size() - stacks;
- ParseTree c = new ParseTree(new CFunction(__autoconcat__.NAME, tree.getTarget()), fileOptions);
- List<ParseTree> subChildren = new ArrayList<>();
- for(int b = replaceAt; b < tree.numberOfChildren(); b++) {
- subChildren.add(tree.getChildAt(b));
- }
- c.setChildren(subChildren);
- if(replaceAt > 0) {
- List<ParseTree> firstChildren = new ArrayList<>();
- for(int d = 0; d < replaceAt; d++) {
- firstChildren.add(tree.getChildAt(d));
- }
- tree.setChildren(firstChildren);
- } else {
- tree.removeChildren();
- }
- tree.addChild(c);
- }
- parents.pop();
- tree = parents.peek();
- constructCount.pop();
- try {
- constructCount.peek().incrementAndGet();
- } catch (EmptyStackException e) {
- throw new ConfigCompileException("Unexpected end curly brace", t.target);
- }
- continue;
- }
- if(t.type == TType.KEYWORD && KeywordList.getKeywordByName(t.value) instanceof ObjectDefinitionKeyword) {
- inObjectDefinition = true;
- }
- //Associative array/label handling
- if(t.type == TType.LABEL && tree.getChildren().size() > 0) {
- //If it's not an atomic identifier it's an error.
- if(!prev1.type.isAtomicLit() && prev1.type != TType.IVARIABLE && prev1.type != TType.KEYWORD) {
- ConfigCompileException error = new ConfigCompileException("Invalid label specified", t.getTarget());
- if(prev1.type == TType.FUNC_END) {
- // This is a fairly common mistake, so we have special handling for this,
- // because otherwise we would get a "Mismatched parenthesis" warning (which doesn't make sense),
- // and potentially lots of other invalid errors down the line, so we go ahead
- // and stop compilation at this point.
- throw error;
- }
- compilerErrors.add(error);
- }
- // Wrap previous construct in a CLabel
- ParseTree cc = tree.getChildren().get(tree.getChildren().size() - 1);
- tree.removeChildAt(tree.getChildren().size() - 1);
- tree.addChild(new ParseTree(new CLabel((Construct) cc.getData()), fileOptions));
- continue;
- }
- //Array notation handling
- if(t.type.equals(TType.LSQUARE_BRACKET)) {
- //tree.addChild(new ParseTree(new CFunction("__cbracket__", t.getTarget()), fileOptions));
- arrayStack.push(new AtomicInteger(tree.getChildren().size() - 1));
- continue;
- } else …
Large files files are truncated, but you can click here to view the full file