Esempio n. 1
0
        public void ParseGothicSrc()
        {
            var AppDir       = AppDomain.CurrentDomain.BaseDirectory;
            var externals    = new Dictionary <Uri, ParseResult>();
            var buildInsPath = Path.Combine(AppDir, "DaedalusBuiltins");

            foreach (var builtIn in Directory.EnumerateFiles(buildInsPath, "*.d"))
            {
                var builtInUri   = new Uri(builtIn);
                var parsedResult = FastCompiler.Load(builtIn, true);
                externals[builtInUri] = parsedResult;
            }

            string srcPath      = @"A:\Spiele\Gothic II_Mods\_work\Data\Scripts\Content\Gothic.src";
            var    parseResults = FastCompiler.ParseSrc(srcPath, externals);
        }
        private static void ParseSrc(
            string srcPath,
            Dictionary <Uri, ParseResult> externals,
            OmniSharp.Extensions.LanguageServer.Protocol.Server.ILanguageServer router,
            ParsedDocumentsManager parsedDocumentsManager)
        {
            router.Window.LogInfo($"Parsing Gothic.Src. This might take a while.");
            var parseResults = FastCompiler.ParseSrc(srcPath, externals);

            foreach (var parseResult in parseResults)
            {
                parsedDocumentsManager.UpdateParseResult(parseResult.Key, parseResult.Value);
            }
            router.Window.LogInfo($"Parsed {parseResults.Count} scripts");

            var diagnostics = new List <PublishDiagnosticsParams>();

            foreach (var kvp in parseResults)
            {
                if (kvp.Value.SyntaxErrors.Count > 0)
                {
                    diagnostics.Add(new PublishDiagnosticsParams
                    {
                        Uri         = kvp.Key,
                        Diagnostics = new Container <Diagnostic>(
                            kvp.Value.SyntaxErrors.Select(x => new Diagnostic
                        {
                            Severity = ParsedDocumentsManager.DiagnosticSeverityFromSyntaxError(x),
                            Message  = x.ErrorCode.Description,
                            Code     = x.ErrorCode.Code,
                            Range    = new OmniSharp.Extensions.LanguageServer.Protocol.Models.Range(
                                new Position(x.Line - 1, x.Column),
                                new Position(x.Line - 1, x.Column)
                                )
                        }))
                    });
                }
            }
            foreach (var dp in diagnostics)
            {
                router.Document.PublishDiagnostics(dp);
            }
        }
Esempio n. 3
0
        private PublishDiagnosticsParams ParseInternal(Uri uri, string text, bool detailed, CancellationToken cancellation)
        {
            var newUri    = new Uri(Uri.UnescapeDataString(uri.AbsoluteUri));
            var localPath = newUri.LocalPath;

            // Workaround: Skip externals. Too many wrong function definitions
            if (localPath.Contains("AI_Intern", StringComparison.OrdinalIgnoreCase) && localPath.EndsWith("Externals.d", StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }

            ParseResult parserResult = null;

            if (string.IsNullOrWhiteSpace(text))
            {
                parserResult = FastCompiler.Load(localPath, detailed, GetDocuments().Values);
            }
            else
            {
                parserResult = FastCompiler.Parse(text, newUri, detailed, GetDocuments().Values);
            }
            PublishDiagnosticsParams result = null;

            if (parserResult.SyntaxErrors.Count > 0)
            {
                result = new PublishDiagnosticsParams
                {
                    Uri         = newUri,
                    Diagnostics = new Container <Diagnostic>(parserResult.SyntaxErrors
                                                             .Select(x => new Diagnostic
                    {
                        Message = x.ErrorCode.Description,
                        Code    = x.ErrorCode.Code,
                        //Source = localPath,
                        Severity = DiagnosticSeverityFromSyntaxError(x),
                        Range    = new OmniSharp.Extensions.LanguageServer.Protocol.Models.Range(new Position(x.Line - 1, x.Column), new Position(x.Line - 1, x.Column)),
                    }))
                };
            }
            UpdateParseResult(uri, parserResult);
            return(result);
        }
Esempio n. 4
0
        public void ParseFileWithVariables()
        {
            var parsed = FastCompiler.Parse(@"const string NINJA_MANAREG_VERSION = ""ManaReg 1.1.0""
func void Ninja_ManaReg_Regeneration() {
    // Not during loading
    if (!Hlp_IsValidNpc(hero)) { return; };
    // Only in-game
    if (!MEM_Game.timestep) { return; };
    // Only in a certain interval
    var int delayTimer; delayTimer += MEM_Timer.frameTime;
    if (delayTimer < DEFAULT_NINJA_MANAREG_TICKRATE) { return; };
	
    delayTimer -= DEFAULT_NINJA_MANAREG_TICKRATE;
    
    if (hero.attribute[ATR_MANA_MAX] >= Ninja_ManaReg_Mana_Threshold) {
        if (hero.attribute[ATR_MANA] < hero.attribute[ATR_MANA_MAX]) {
            var int menge; menge = (hero.attribute[ATR_MANA_MAX] + (Ninja_ManaReg_Max_Mana_Divisor/2)) / Ninja_ManaReg_Max_Mana_Divisor;
            Npc_ChangeAttribute(hero, ATR_MANA, menge);
		};
    };
};", detailed: true);
        }
Esempio n. 5
0
        public void ParseMultiVarsAndNumericIdentifiers()
        {
            var parsed = FastCompiler.Parse(@"///Does magical stuff
func int learn1hSkill(var int skill) {
	var string 1hSkillText, var int meinInt;
	1hSkillText = ConcatStrings (""Lerne: Einhand Stufe "", IntToString (skill));

    decreaseLearnPoints(B_GetLearnCostWeaponSkill(NPC_TALENT_1H, skill));
            PrintScreen_Ext(1hSkillText, -1, -1, FONT_SCREEN, 2);
            B_RaiseFightTalent(hero, NPC_TALENT_1H, B_GetRaiseAmountOfWeaponSkill(NPC_TALENT_1H, skill));
            onehandedSkillLevel = skill;

    MEM_SwapBytes(n0+60,                       n1+60,                      64);                          // trafo

    };");

            if (parsed.SyntaxErrors.Count > 0)
            {
                foreach (var err in parsed.SyntaxErrors)
                {
                    Console.WriteLine($"{err.Line}:{err.Column} {err.ErrorCode.Code}: {err.ErrorCode.Description}");
                }
            }
        }
Esempio n. 6
0
 public void ParseInstance()
 {
     var parsed = FastCompiler.Parse(@"instance PC_Hero (NPC_DEFAULT) {};");
 }