pascalabcnet/VisualPlugins/LanguageConverter/ListSyntRules.cs
samuraiGH d491e88aa7
migration to new build system (#3241)
* converting project files into sdk style
* new build commands
* adding new dll into nsis
* removing unused .cs files
2025-03-03 20:34:51 +03:00

69 lines
2.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace Converter
{
public class ListSyntRules
{
// хранит соответствие между узлами семантического дерева РАВСNET и соответствующими синтаксическими правилами другого языка
private Dictionary<string, string> Rules;
private string fileName;
private const string nodeSeparator = "@", ruleSeparator = "::";
public ListSyntRules(string _fileName)
{
fileName = _fileName;
initialisation();
}
public string GetRule(string _nodeName)
{
string result;
if (Rules.TryGetValue(_nodeName, out result))
{
return result;
}
else
return "";
}
public string[] GetWordsFromRule(string _node)
{
return GetRule(_node).Split(' ');
}
private void initialisation()
{
Rules = new Dictionary<string, string>();
initRules(readRulesTXTInToStr());
}
private string readRulesTXTInToStr()
{
TextReader readerTXT = File.OpenText(fileName);
return readerTXT.ReadToEnd();
}
private void initRules(string _rulesTXT)
{
string[] nameNodeAndRule;
string[] nodes;
string[] nodeSeparators = new string[1], ruleSeparators = new string[1];
nodeSeparators[0] = nodeSeparator;
ruleSeparators[0] = ruleSeparator;
nodes = _rulesTXT.Split(nodeSeparators, StringSplitOptions.RemoveEmptyEntries);
foreach (string node in nodes)
{
nameNodeAndRule = node.Split(ruleSeparators, StringSplitOptions.RemoveEmptyEntries);
nameNodeAndRule[0] = nameNodeAndRule[0].Replace(" ", "");
Rules.Add(nameNodeAndRule[0], nameNodeAndRule[1]);
}
}
}
}