static void Main() { ProtoCore.Core core = new ProtoCore.Core(new ProtoCore.Options()); string filePath = @"C:\DSCode\autodeskresearch\branches\UIResearch\DesignScriptParser\DSParser\DSParser\scripts\test1.ds"; DesignScript.Parser.Scanner s = new DesignScript.Parser.Scanner(filePath); DesignScript.Parser.Parser p = new DesignScript.Parser.Parser(s, core); p.Parse(); DesignScript.Parser.Node c = p.root; }
public bool ParseScript(string scriptFilePath) { try { this.fullScriptPath = scriptFilePath; DesignScript.Parser.Scanner scanner = new DesignScript.Parser.Scanner(scriptFilePath); DesignScript.Parser.Parser parser = new DesignScript.Parser.Parser(scanner, core); parser.Parse(); parserErrors = parser.errors.errMsgFormat; codeBlockNode = parser.root; } catch (Exception) { return(false); } return(null != codeBlockNode); }
void Import_Statement(out Node node) { DesignScript.Parser.Associative.ImportNode importNode = null; importNode = new DesignScript.Parser.Associative.ImportNode(); while (!(la.kind == 0 || la.kind == 41)) {SynErr(72); Get();} Expect(41); if (t.kind == _Kw_import) importNode.KwImport.SetValue(t.val, t.line, t.col); if (la.val == "(") importNode.OpenParen.SetValue(la.val, la.line, la.col); Expect(9); if (la.kind == 4) { Get(); if (t.kind == _textstring) { DesignScript.Parser.Associative.StringNode path = new DesignScript.Parser.Associative.StringNode() { value = t.val, Line = t.line, Col = t.col }; importNode.Path = path; } } else if (la.kind == 1) { Get(); if (t.kind == _ident) importNode.Identifier.SetValue(t.val, t.line, t.col); Expect(42); if (t.kind == _Kw_from) importNode.KwFrom.SetValue(t.val, t.line, t.col); Expect(4); if (t.kind == _textstring) { DesignScript.Parser.Associative.StringNode path = new DesignScript.Parser.Associative.StringNode() { value = t.val, Line = t.line, Col = t.col }; importNode.Path = path; } } else SynErr(73); if (la.val == ")" && importNode.OpenParen.Value != null) importNode.CloseParen.SetValue(la.val, la.line, la.col); else if (la.val != ")") importNode.OpenParen.Value = null; Expect(10); if (la.kind == 43) { Get(); if (t.kind == _Kw_prefix) importNode.KwPrefix.SetValue(t.val, t.line, t.col); Expect(1); if (t.kind == _ident) importNode.PrefixIdent.SetValue(t.val, t.line, t.col); } Expect(20); if (t.val == ";") importNode.EndLine.SetValue(t.val, t.line, t.col); else { if (null != importNode.OpenParen) importNode.OpenParen.SetValue(string.Empty, -1, -1); if (null != importNode.CloseParen) importNode.CloseParen.SetValue(string.Empty, -1, -1); } // We only allow "import" statements at the beginning of files, // so if any actual code started (anything that is not an import // statement), we will mark this import statement as invalid. // if (false != codeSegmentStarted) { if (null != importNode.KwImport) importNode.KwImport.SetValue(string.Empty, -1, -1); } string ModuleName = null; if (importNode.Path != null && importNode.Path.value != null && (ModuleName = GetImportedModuleFullPath(importNode.Path.value)) != null && Path.GetExtension(ModuleName) == ".ds") { if (GlobalModuleTable == null) { GlobalModuleTable = new Dictionary<string, DesignScript.Parser.Associative.ImportNode>(); if (core.Options.RootModulePathName != null) GlobalModuleTable[core.Options.RootModulePathName] = null; } if (GlobalModuleTable.ContainsKey(ModuleName)) { importNode.CodeNode = null; importNode.HasBeenImported = true; } else { GlobalModuleTable[ModuleName] = importNode; string curDirectory = Directory.GetCurrentDirectory(); Directory.SetCurrentDirectory(Path.GetDirectoryName(ModuleName)); DesignScript.Parser.Scanner scanner = new DesignScript.Parser.Scanner(ModuleName); DesignScript.Parser.Parser parser = new DesignScript.Parser.Parser(scanner, core); parser.GlobalModuleTable = GlobalModuleTable; parser.Parse(); Directory.SetCurrentDirectory(curDirectory); //if (parseErrors.ToString() != String.Empty) //core.BuildStatus.LogSyntaxError(parseErrors.ToString()); //core.BuildStatus.errorCount += parser.errors.count; importNode.CodeNode = parser.root as DesignScript.Parser.Associative.CodeBlockNode; } } node = importNode; }