public void AppendTokenList( String delim, ArrayList<KToken> TokenList, int BeginIdx, int EndIdx, int ParseOption) { assert (this.NodeList.size() == 1); int start = BeginIdx; for (int i = BeginIdx; i < EndIdx; i++) { KToken Token = TokenList.get(i); if (Token.EqualsText(delim)) { AddParsedNode(ParseNewNode2(NodeNameSpace, null, TokenList, start, i, ParseOption)); start = i + 1; } } if (start < EndIdx) { AddParsedNode(ParseNewNode2(NodeNameSpace, null, TokenList, start, EndIdx, ParseOption)); } }
public int MatchKeyword( int Index, String Symbol, ArrayList<KToken> TokenList, int BeginIdx, int EndIdx, int ParseOption) { if (BeginIdx == -1) return -1; if (BeginIdx < EndIdx) { KToken Token = TokenList.get(BeginIdx); if (Token.EqualsText(Symbol)) { SetAt(Index, Token); return BeginIdx + 1; } } return ReportExpectedAfter(TokenList, BeginIdx, EndIdx, Symbol, ParseOption); }
public static UntypedNode ParseNewNode2( KNameSpace ns, UntypedNode PrevNode, ArrayList<KToken> TokenList, int BeginIdx, int EndIdx, int ParseOption) { UntypedNode LeftNode = null; KToken.DumpTokenList(0, "ParseNewNode2", TokenList, BeginIdx, EndIdx); while (BeginIdx < EndIdx) { int NextIdx = BeginIdx; KToken KeyToken = TokenList.get(NextIdx); KSyntax Syntax = KeyToken.ResolvedSyntax; // KonohaDebug.P("nextIdx="+NextIdx+",Syntax="+Syntax); if (LeftNode == null) { if (Syntax.IsDelim()) { // A ; B NextIdx++; } else { LeftNode = new UntypedNode(ns, KeyToken); NextIdx = LeftNode.ParseToken(KeyToken, TokenList, NextIdx, EndIdx); } } else { if (Syntax.IsDelim()) { // A ; B ParseNewNode2(ns, LeftNode, TokenList, NextIdx, EndIdx, AllowEmpty); break; } else if (Syntax.IsBinaryOperator()) { // A + B UntypedNode RightNode = ParseNewNode2(ns, null, TokenList, NextIdx + 1, EndIdx, 0); LeftNode = BinaryNode(ns, LeftNode, KeyToken, RightNode); break; } else if (Syntax.IsSuffixOperator()) { // A [] NextIdx = LeftNode.ParseToken(KeyToken, TokenList, NextIdx, EndIdx); } else { } } if (!(BeginIdx < NextIdx)) { KonohaDebug.P("Panic ** " + Syntax + " BeginIdx=" + BeginIdx + ", NextIdx=" + NextIdx); break; } BeginIdx = NextIdx; } if (LeftNode == null) {} if (PrevNode != null && LeftNode != null) { PrevNode.LinkNode(LeftNode); } return LeftNode; }
public static UntypedNode ParseGroup(KNameSpace ns, KToken GroupToken, int ParseOption) { ArrayList<KToken> GroupList = GroupToken.GetGroupList(); return ParseNewNode2(ns, null, GroupList, 1, GroupList.size() - 1, ParseOption); }
public static UntypedNode NewNullNode(KNameSpace ns, ArrayList<KToken> TokenList, int BeginIdx) { KToken EmptyToken = new KToken(""); EmptyToken.uline = TokenList.get(BeginIdx - 1).uline; EmptyToken.ResolvedSyntax = KSyntax.EmptySyntax; return new UntypedNode(ns, EmptyToken); }