• R/O
  • SSH
  • HTTPS

jobjectpascal: Commit


Commit MetaInfo

Revision133 (tree)
Time2015-06-14 06:57:46
Authoriga

Log Message

impl func.

Change Summary

Incremental Difference

--- trunk/src/jp/igapyon/jobjectpascal/parser/syntax/PascalSyntaxTokenFunctionParser.java (nonexistent)
+++ trunk/src/jp/igapyon/jobjectpascal/parser/syntax/PascalSyntaxTokenFunctionParser.java (revision 133)
@@ -0,0 +1,57 @@
1+package jp.igapyon.jobjectpascal.parser.syntax;
2+
3+import jp.igapyon.jobjectpascal.PascalConstants;
4+import jp.igapyon.jobjectpascal.parser.PascalLexicalToken;
5+import jp.igapyon.jobjectpascal.parser.PascalSyntaxProcessInfo;
6+import jp.igapyon.jobjectpascal.parser.PascalSyntaxTokenUtil;
7+import jp.igapyon.jobjectpascal.parser.ast.PascalAstFunction;
8+
9+public class PascalSyntaxTokenFunctionParser {
10+ public void parse(PascalSyntaxProcessInfo processInfo) {
11+ final PascalAstFunction ast = new PascalAstFunction();
12+ ast.setName("function");
13+
14+ final PascalLexicalToken nameToken = PascalSyntaxTokenUtil
15+ .readNextTokenWithoutWhitespaces(processInfo);
16+ ast.setFuncName(nameToken.getWord());
17+ if (PascalConstants.TokenType.IDENTIFIRE_OR_DIRECTIVE != nameToken
18+ .getType()) {
19+ System.out
20+ .println("ERROR: function: name must be IDENTIFIRE_OR_DIRECTIVE");
21+ }
22+
23+ {
24+ final PascalLexicalToken checkToken = PascalSyntaxTokenUtil
25+ .readNextTokenWithoutWhitespaces(processInfo);
26+ if (PascalConstants.TokenType.SPECIAL_SYMBOL_WITHOUT_WORD != checkToken
27+ .getType())
28+ System.out
29+ .println("ERROR: function: ( must be SPECIAL_SYMBOL_WITHOUT_WORD");
30+ if (!"(".equals(checkToken.getWord()))
31+ System.out.println("ERROR: function: expected ( but was: "
32+ + checkToken.getWord());
33+ }
34+
35+ ast.setFuncArgs(PascalSyntaxTokenUtil.readToDelimWithoutWhitespaces(
36+ processInfo, ")"));
37+ processInfo.lexicalIndex++;
38+
39+ {
40+ final PascalLexicalToken checkToken = PascalSyntaxTokenUtil
41+ .readNextTokenWithoutWhitespaces(processInfo);
42+ if (PascalConstants.TokenType.SPECIAL_SYMBOL_WITHOUT_WORD != checkToken
43+ .getType())
44+ System.out
45+ .println("ERROR: function: ( must be SPECIAL_SYMBOL_WITHOUT_WORD");
46+ if (!":".equals(checkToken.getWord()))
47+ System.out.println("ERROR: function: expected ( but was: "
48+ + checkToken.getWord());
49+ }
50+
51+ ast.setFuncResultType(PascalSyntaxTokenUtil
52+ .readToDelimWithoutWhitespaces(processInfo, ";"));
53+ processInfo.lexicalIndex++;
54+
55+ processInfo.syntaxTokenList.add(ast);
56+ }
57+}
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
--- trunk/src/jp/igapyon/jobjectpascal/parser/ast/PascalAstFunction.java (nonexistent)
+++ trunk/src/jp/igapyon/jobjectpascal/parser/ast/PascalAstFunction.java (revision 133)
@@ -0,0 +1,36 @@
1+package jp.igapyon.jobjectpascal.parser.ast;
2+
3+public class PascalAstFunction extends PascalAstNodeImpl {
4+ protected String funcName;
5+ protected String funcArgs;
6+ protected String funcResultType;
7+
8+ public String getFuncName() {
9+ return funcName;
10+ }
11+
12+ public void setFuncName(String funcName) {
13+ this.funcName = funcName;
14+ }
15+
16+ public String getFuncArgs() {
17+ return funcArgs;
18+ }
19+
20+ public void setFuncArgs(String funcArgs) {
21+ this.funcArgs = funcArgs;
22+ }
23+
24+ public String getFuncResultType() {
25+ return funcResultType;
26+ }
27+
28+ public void setFuncResultType(String funcResultType) {
29+ this.funcResultType = funcResultType;
30+ }
31+
32+ public String getString() {
33+ return getName() + ": " + getFuncName() + "(" + getFuncArgs() + ") "
34+ + getFuncResultType() + ";";
35+ }
36+}
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
--- trunk/src/jp/igapyon/jobjectpascal/parser/PascalSyntaxTokenParser.java (revision 132)
+++ trunk/src/jp/igapyon/jobjectpascal/parser/PascalSyntaxTokenParser.java (revision 133)
@@ -45,6 +45,7 @@
4545 import jp.igapyon.jobjectpascal.parser.ast.PascalAstNodeImpl;
4646 import jp.igapyon.jobjectpascal.parser.ast.PascalAstType;
4747 import jp.igapyon.jobjectpascal.parser.syntax.PascalSyntaxTokenConstParser;
48+import jp.igapyon.jobjectpascal.parser.syntax.PascalSyntaxTokenFunctionParser;
4849 import jp.igapyon.jobjectpascal.parser.syntax.PascalSyntaxTokenProgramParser;
4950 import jp.igapyon.jobjectpascal.parser.syntax.PascalSyntaxTokenUsesParser;
5051 import jp.igapyon.jobjectpascal.parser.syntax.PascalSyntaxTokenVarParser;
@@ -140,8 +141,8 @@
140141 processInfo.lexicalIndex++;
141142 new PascalSyntaxTokenConstParser().parseMuiti(processInfo);
142143 } else if ("function".equals(wordSymbol)) {
143- // FIXME to be implemented
144- //parseFunctionDecl();
144+ processInfo.lexicalIndex++;
145+ new PascalSyntaxTokenFunctionParser().parse(processInfo);
145146 } else if ("procedure".equals(wordSymbol)) {
146147 // FIXME to be implemented
147148 //parseProcedureDecl();
--- trunk/src/jp/igapyon/jobjectpascal/parser/PascalSyntaxTokenUtil.java (revision 132)
+++ trunk/src/jp/igapyon/jobjectpascal/parser/PascalSyntaxTokenUtil.java (revision 133)
@@ -36,6 +36,8 @@
3636 import java.util.ArrayList;
3737 import java.util.List;
3838
39+import org.xml.sax.ext.LexicalHandler;
40+
3941 import jp.igapyon.jobjectpascal.PascalConstants;
4042 import jp.igapyon.jobjectpascal.parser.ast.PascalAstNode;
4143 import jp.igapyon.jobjectpascal.parser.ast.PascalAstType;
@@ -58,6 +60,21 @@
5860 return false;
5961 }
6062
63+ public static PascalLexicalToken readNextTokenWithoutWhitespaces(
64+ final PascalSyntaxProcessInfo processInfo) {
65+ for (; processInfo.lexicalIndex < processInfo.lexicalTokenList.size(); processInfo.lexicalIndex++) {
66+ final PascalLexicalToken token = processInfo.lexicalTokenList
67+ .get(processInfo.lexicalIndex);
68+ if (isWhitespaceTokenSeparators(token)) {
69+ continue;
70+ }
71+ processInfo.lexicalIndex++;
72+ return token;
73+ }
74+
75+ return null;
76+ }
77+
6178 public static String readToDelimWithoutWhitespaces(
6279 final PascalSyntaxProcessInfo processInfo, final String delimiter) {
6380 String result = "";
Show on old repository browser