Example #1
0
        /// <summary>
        /// Assumes the first line is the declaration line.
        /// </summary>
        /// <param name="lines"></param>
        /// <returns></returns>
        public static MethodNodeAST Parse(List <List <Token> > lines)
        {
            MethodNodeAST methodNode = ParseDeclaration(lines[0]);

            methodNode.ParseBody(lines.GetRange(1));

            return(methodNode);
        }
Example #2
0
        private static MethodNodeAST ParseDeclaration(List <Token> line)
        {
            int           index      = line.FindIndex(t => t.Type == TokenType.typeSpecifier);
            MethodNodeAST methodNode = new MethodNodeAST(line[index], line[index + 1]);

            index += 2;

            //int paramsStartIndex = 1 + line.FindNextIndex(index, t => t.Type == TokenType.cBraceOpen);
            //index = line.FindNextIndex(paramsStartIndex, t => t.Type == TokenType.cBraceClose);
            //methodNode._parameters = ParseParameters(line.GetRangeBetween(paramsStartIndex, index));

            index = line.FindNextIndex(index, t => t.Type == TokenType.rBraceOpen);
            var expressionRange = line.GetRangeContained(index, t => t.Type == TokenType.rBraceOpen, t => t.Type == TokenType.rBraceClose);

            methodNode._parameters = ParseParameters(expressionRange);

            return(methodNode);
        }