public (Token, string) Parse(string input) { var letKeyword = new Word("let").Parse(input); var sp1 = new SkipWhitespace().Parse(letKeyword.Item2); var typeName = new TypeName().Parse(sp1.Item2); var sp2 = new SkipWhitespace().Parse(typeName.Item2); var name = new Ident().Parse(sp2.Item2); var sp3 = new SkipWhitespace().Parse(name.Item2); var assignment = new Maybe( new Create(TokenType.Assignment) { new SkipWhitespace(), new Char('='), new SkipWhitespace(), new Expr() } ).Parse(sp3.Item2); var decl = letKeyword.Item1 + typeName.Item1 + name.Item1; if (assignment.Item1.type != TokenType.Failure) { decl += assignment.Item1; } decl.type = TokenType.Declaration; return(decl, assignment.Item2); }
public (Token, string) Parse(string input) { var typeName = new TypeName().Parse(input); var sp1 = new SkipWhitespace().Parse(typeName.Item2); var name = new Ident().Parse(sp1.Item2); var suffix = new Maybe( new Many( new Create(TokenType.Node) { new SkipWhitespace(), new Char(','), new SkipWhitespace(), new TypeName(), new SkipWhitespace(), new Ident() } ) ).Parse(name.Item2); var typeArgList = typeName.Item1 + name.Item1; if (suffix.Item1.type != TokenType.Failure) { typeArgList += suffix.Item1; } typeArgList.type = TokenType.TypeArgList; return(typeArgList, suffix.Item2); }
public (Token, string) Parse(string input) { // Declaration items var dataKeyword = new Word("data").Parse(input); var sp1 = new SkipWhitespace().Parse(dataKeyword.Item2); var name = new Ident().Parse(sp1.Item2); var sp2 = new SkipWhitespace().Parse(name.Item2); var lpar = new Char('(').Parse(sp2.Item2); var sp3 = new SkipWhitespace().Parse(lpar.Item2); var firstExpr = new Expr().Parse(sp3.Item2); var nextExprs = new Maybe( new Many( new Create(TokenType.Node) { new SkipWhitespace(), new Char(','), new Expr() } ) ).Parse(firstExpr.Item2); var sp4 = new SkipWhitespace().Parse(nextExprs.Item2); var rpar = new Char(')').Parse(sp4.Item2); // Combine var declr = dataKeyword.Item1 + name.Item1 + lpar.Item1 + firstExpr.Item1; if (nextExprs.Item1.type != TokenType.Failure) { declr += nextExprs.Item1; } declr += rpar.Item1; declr.type = TokenType.CompOrRecDec; return(declr, rpar.Item2); }
public (Token, string) Parse(string input) { var defKeyword = new Word("def").Parse(input); var sp1 = new SkipWhitespace().Parse(defKeyword.Item2); var recKeyword = new Word("rec").Parse(sp1.Item2); var sp2 = new SkipWhitespace().Parse(recKeyword.Item2); var name = new Ident().Parse(sp2.Item2); var sp3 = new SkipWhitespace().Parse(name.Item2); var newLine = new Many(new Char('\n')).Parse(sp3.Item2); var functions = new Maybe( new Many( new Create(TokenType.FuncDef) { new SkipWhitespace(), new MiniFuncDef(), new SkipWhitespace(), new Many(new Char('\n')) } ) ).Parse(newLine.Item2); var sp4 = new SkipWhitespace().Parse(functions.Item2); var endKeyword = new Word("end").Parse(sp4.Item2); var token = defKeyword.Item1 + recKeyword.Item1 + name.Item1; if (functions.Item1.type != TokenType.Failure) { token += functions.Item1; } token += endKeyword.Item1; token.type = TokenType.RecDef; return(token, endKeyword.Item2); }
public Token(string id, SkipWhitespace skipWs, RegExpr expr) { Id = id; SkipLeadingWhitespace = (skipWs == SkipWhitespace.Enable); Expr = expr; Rules = new TokenRules(); Children = new HashSet <Token>(); Parents = new Dictionary <string, Token>(); }
public Token(string id, SkipWhitespace skipWs, RegExpr expr) { Id = id; SkipLeadingWhitespace = (skipWs == SkipWhitespace.Enable); Expr = expr; Rules = new TokenRules(); CaptureId = GenerateCaptureId(Id); Children = new List <Token>(); }
public (Token, string) Parse(string input) { var retKeyword = new Word("return").Parse(input); var sp1 = new SkipWhitespace().Parse(retKeyword.Item2); var expr = new Expr().Parse(sp1.Item2); var ret = retKeyword.Item1 + expr.Item1; return(ret, expr.Item2); }
public (Token, string) Parse(string input) { var imports = new Maybe( new Many( new Create(TokenType.Import) { new SkipWhitespace(), new Import(), new SkipWhitespace(), new Many(new Char('\n')) } ) ).Parse(input); var sp1 = new SkipWhitespace().Parse(imports.Item2); var export = new Export().Parse(sp1.Item2); var sp2 = new SkipWhitespace().Parse(export.Item2); var implement = new Maybe(new Implement()).Parse(sp2.Item2); var newLine = new Many( new Create(TokenType.Character) { new SkipWhitespace(), new Char('\n'), new SkipWhitespace() } ).Parse(implement.Item2); var definitions = new Maybe( new Many( new Create(TokenType.Definition) { new SkipWhitespace(), new Definition(), new Many( new Create(TokenType.Character) { new SkipWhitespace(), new Char('\n') } ) } ) ).Parse(newLine.Item2); var module = export.Item1; if (imports.Item1.type != TokenType.Failure) { module = imports.Item1 + module; } if (implement.Item1.type != TokenType.Failure) { module += implement.Item1; } if (definitions.Item1.type != TokenType.Failure) { module += definitions.Item1; } return(module, definitions.Item2); }
public (Token, string) Parse(string input) { var varName = new Ident().Parse(input); var sp1 = new SkipWhitespace().Parse(varName.Item2); var equ = new Char('=').Parse(sp1.Item2); var sp2 = new SkipWhitespace().Parse(equ.Item2); var expr = new Expr().Parse(sp2.Item2); var assignment = varName.Item1 + equ.Item1 + expr.Item1; return(assignment, expr.Item2); }
public (Token, string) Parse(string input) { var exportKeyword = new Word("exports").Parse(input); var sp1 = new SkipWhitespace().Parse(exportKeyword.Item2); var list = new IdentList().Parse(sp1.Item2); var export = exportKeyword.Item1 + list.Item1; export.type = TokenType.Export; return(export, list.Item2); }
public (Token, string) Parse(string input) { var implementKeyword = new Word("implements").Parse(input); var sp1 = new SkipWhitespace().Parse( implementKeyword.Item2 ); var list = new MemberAccList().Parse(sp1.Item2); var implement = implementKeyword.Item1 + list.Item1; implement.type = TokenType.Implement; return(implement, list.Item2); }
public (Token, string) Parse(string input) { var defKeyword = new Word("def").Parse(input); var sp1 = new SkipWhitespace().Parse(defKeyword.Item2); var fnKeyword = new Word("fn").Parse(sp1.Item2); var sp2 = new SkipWhitespace().Parse(fnKeyword.Item2); var name = new Ident().Parse(sp2.Item2); var sp8 = new SkipWhitespace().Parse(name.Item2); var lpar = new Char('(').Parse(sp8.Item2); var sp3 = new SkipWhitespace().Parse(lpar.Item2); var argList = new Maybe(new TypeArgList()).Parse(sp3.Item2); var sp4 = new SkipWhitespace().Parse(argList.Item2); var rpar = new Char(')').Parse(sp4.Item2); var sp5 = new SkipWhitespace().Parse(rpar.Item2); var retType = new SelectFrom { new TypeName(), new Word("void") }.Parse(sp5.Item2); var sp6 = new SkipWhitespace().Parse(retType.Item2); var newLine = new Many(new Char('\n')).Parse(sp6.Item2); var stmts = new Maybe( new Many( new Create(TokenType.Node) { new SkipWhitespace(), new Statement(), new SkipWhitespace(), new Many(new Char('\n')) } ) ).Parse(newLine.Item2); var sp7 = new SkipWhitespace().Parse(stmts.Item2); var endKeyword = new Word("end").Parse(sp7.Item2); var funcDef = defKeyword.Item1 + fnKeyword.Item1 + name.Item1 + lpar.Item1; if (argList.Item1.type != TokenType.Failure) { funcDef += argList.Item1; } funcDef += rpar.Item1; if (stmts.Item1.type != TokenType.Failure) { funcDef += stmts.Item1; } funcDef += endKeyword.Item1; funcDef.type = TokenType.FuncDef; return(funcDef, endKeyword.Item2); }
public (Token, string) Parse(string input) { // lambda items var lambdaKeyword = new Word("lambda").Parse(input); var sp1 = new SkipWhitespace().Parse(lambdaKeyword.Item2); var lpar = new Char('(').Parse(sp1.Item2); var sp2 = new SkipWhitespace().Parse(lpar.Item2); var arglist = new Maybe(new TypeArgList()).Parse(sp2.Item2); var sp3 = new SkipWhitespace().Parse(arglist.Item2); var rpar = new Char(')').Parse(sp3.Item2); var sp4 = new SkipWhitespace().Parse(rpar.Item2); var typeName = new TypeName().Parse(sp4.Item2); var sp5 = new SkipWhitespace().Parse(typeName.Item2); var newLine = new Many(new Char('\n')).Parse(sp5.Item2); var statements = new Maybe( new Create(TokenType.Node) { new SkipWhitespace(), new Many(new Statement()), new SkipWhitespace(), new Many(new Char('\n')) } ).Parse(newLine.Item2); var sp6 = new SkipWhitespace().Parse(statements.Item2); var endKeyword = new Word("end").Parse(sp6.Item2); // Combine var lambda = lambdaKeyword.Item1 + lpar.Item1; if (arglist.Item1.type != TokenType.Failure) { lambda += arglist.Item1; } lambda += rpar.Item1; lambda += typeName.Item1; if (statements.Item1.type != TokenType.Failure) { lambda += statements.Item1; } lambda += endKeyword.Item1; lambda.type = TokenType.Lambda; return(lambda, endKeyword.Item2); }
public (Token, string) Parse(string input) { // Function call items var callKeyword = new Word("call").Parse(input); var sp1 = new SkipWhitespace().Parse(callKeyword.Item2); var name = new Ident().Parse(sp1.Item2); var sp2 = new SkipWhitespace().Parse(name.Item2); var exprs = new Maybe(new Many(new Expr())).Parse(sp2.Item2); // Combine var funcCall = callKeyword.Item1 + name.Item1; if (exprs.Item1.type != TokenType.Failure) { funcCall += exprs.Item1; } funcCall.type = TokenType.FuncCall; return(funcCall, exprs.Item2); }
public (Token, string) Parse(string input) { var name = new Ident().Parse(input); var sp1 = new SkipWhitespace().Parse(name.Item2); var lpar = new Char('(').Parse(sp1.Item2); var sp2 = new SkipWhitespace().Parse(lpar.Item2); var argList = new Maybe(new TypeArgList()).Parse(sp2.Item2); var sp3 = new SkipWhitespace().Parse(argList.Item2); var rpar = new Char(')').Parse(sp3.Item2); var sp4 = new SkipWhitespace().Parse(rpar.Item2); var typeName = new TypeName().Parse(sp4.Item2); var token = name.Item1 + lpar.Item1; if (argList.Item1.type != TokenType.Failure) { token += argList.Item1; } token += rpar.Item1 + typeName.Item1; token.type = TokenType.Node; return(token, typeName.Item2); }
public (Token, string) Parse(string input) { var mutKeyword = new Maybe(new Word("mut")).Parse(input); var sp1 = new SkipWhitespace().Parse(mutKeyword.Item2); var baseTypeName = new SelectFrom { new Create(TokenType.TypeName) { new Word("fn"), new SkipWhitespace(), new Char('('), new SkipWhitespace(), new TypeList(), new SkipWhitespace(), new Char(')'), new SkipWhitespace(), new TypeName() }, new Word("int"), new Word("float"), new Word("str"), new Ident(), new Create(TokenType.TypeName) { new Char('('), new SkipWhitespace(), new TypeName(), new SkipWhitespace(), new Char(')') }, new Create(TokenType.TypeName) { new Char('['), new SkipWhitespace(), new TypeName(), new SkipWhitespace(), new Char(']') } }.Parse(sp1.Item2); var typeName = baseTypeName.Item1; if (mutKeyword.Item1.type != TokenType.Failure) { typeName = mutKeyword.Item1 + typeName; } typeName.type = TokenType.TypeName; return(typeName, baseTypeName.Item2); }
public Token(Enum id, SkipWhitespace skipWs, RegExpr expr) : this(id.ToString(), skipWs, expr) { }