public async Task <bool> UpdateTokAsync(Tok tok) { var apiUrl = $"{_apiSettings.ApiPrefix}/tok/{tok.Id}{_apiSettings.CodePrefix}{_apiSettings.ApiKey}"; HttpResponseMessage response = await _httpClient.PutAsJsonAsync(apiUrl, tok); return(response.IsSuccessStatusCode); }
public void SacuvajTokoveZaProces(long idProcesa, List <Tok> tokovi) { Proces proces = _procesOPP.VratiProcesPoIDSaTokovima(idProcesa); if (proces != null) { if (tokovi == null || !tokovi.Any()) { proces.Tokovi.AddRange(tokovi); } else { tokovi.ForEach(tok => { Tok tokUProcesu = proces.Tokovi.FirstOrDefault(t => t.RBToka == tok.RBToka); if (tokUProcesu == null) { proces.Tokovi.Add(tok); } else { tokUProcesu.AktivnostiUToku = tok.AktivnostiUToku; tokUProcesu.PodprocesiUToku = tok.PodprocesiUToku; } }); } _procesOPP.SacuvajPromene(); return; } throw new Exception("Процес " + idProcesa + " не постоји."); }
public Operator(GeneralLanguageDef languageDef) : base( inp => { var res = Tok.Lexeme( from name in new Oper(languageDef) where !OpsHelper.IsReservedOp(name, languageDef) select new OperatorToken(name, inp.First().Location)) .Parse(inp); if (res.IsFaulted) { return(res); } if (res.Value.IsEmpty) { return(ParserResult.Fail <OperatorToken>("unexpected: reserved operator", inp)); } return(res); } ) { }
public Identifier(GeneralLanguageDef languageDef) : base( inp => { var res = Tok.Lexeme( from name in new Ident(languageDef) where !IdentHelper.IsReservedName(name, languageDef) select new IdentifierToken(name, inp.First().Location) ) .Parse(inp); if (res.IsFaulted) { return(res); } if (res.Value.IsEmpty) { return(ParserResult.Fail <IdentifierToken>("unexpected: reserved word", inp)); } return(res); } ) { }
public string SacuvajTokoveZaProces(long id, List <TokPodaci> tokovi) { if (tokovi.Any()) { try { List <Tok> tokoviModel = new List <Tok>(); tokovi.ForEach(t => { int prebroj = 0; Tok novi = new Tok { IDProcesa = id, RBToka = t.rbToka }; if (t.aktivnostiUToku != null) { prebroj += t.aktivnostiUToku.Count; novi.AktivnostiUToku = t.aktivnostiUToku.Select(aut => new AktivnostUToku() { IDProcesa = id, RBToka = t.rbToka, IDAktivnosti = aut.idAktivnosti }).ToList(); } if (t.podprocesiUToku != null) { prebroj += t.podprocesiUToku.Count; novi.PodprocesiUToku = t.podprocesiUToku.Select(put => new ProcesUToku() { IDNadprocesa = id, RBToka = t.rbToka, IDPodprocesa = put.idProcesa }).ToList(); } if (prebroj < 2) { throw new Exception("Сваки ток мора имати најмање једну активност или подпроцес."); } tokoviModel.Add(novi); }); _procesServis.SacuvajTokoveZaProces(id, tokoviModel); return("Токови за процес " + id + " су успешно сачувани."); } catch (DbUpdateException ex) { throw new Exception("Дошло је до грешке, систем не може сачувати токове за процес " + id + ".", ex); } } throw new Exception("Процес мора имати бар један ток."); }
public void SymbolTest() { var sym = from s in Tok.Symbol("***") select s; var res = sym.Parse("*** "); Assert.True(!res.IsFaulted); }
public async Task <bool> CreateTokAsync(Tok tok) { InitializeApiClientUser(true); client.BaseAddress = new Uri($"{baseUrl}/tok{codePrefix}{apiKey}"); HttpResponseMessage response = await client.PostAsJsonAsync(client.BaseAddress, tok); client = new HttpClient(); return(response.IsSuccessStatusCode); }
public static Exception ArrayIntervalInitializeCbrMissed(Tok openBracket, Tok lastToken, bool hasStep) { int start = openBracket.Start; int finish = lastToken.Finish; return(new FunParseException(240, $"{(hasStep?"[x..y..step ???]":"[x..y ???]")}. ']' was missed'{Nl} Example: a[1..5..2]", start, finish)); }
public Symbol(string name) : base( inp => (from sym in Tok.Lexeme <ImmutableList <ParserChar> >(Prim.String(name)) select new SymbolToken(sym)) .Parse(inp) ) { }
public static Exception ArrayIndexCbrMissed(Tok openBracket, Tok lastToken) { int start = openBracket.Start; int finish = lastToken.Finish; return(new FunParseException(243, $"a[x ??? <- was missed ']'{Nl} Example: a[1] or a[1:2] or a[1:5:2]", start, finish)); }
public void NextLexem() { PassSpaces(); // R К этому моменту первый символ лексемы считан в ch LexText = ""; LexRow = row; LexCol = col; // Тип лексемы определяется по ее первому символу // Для каждой лексемы строится синтаксическая диаграмма if (currentCh == ';') { NextCh(); LexKind = Tok.SEMICOLON; } else if (currentCh == ':') { NextCh(); if (currentCh != '=') { LexError("= was expected"); } NextCh(); LexKind = Tok.ASSIGN; } else if (char.IsLetter(currentCh)) { while (char.IsLetterOrDigit(currentCh)) { NextCh(); } if (keywordsMap.ContainsKey(LexText)) { LexKind = keywordsMap[LexText]; } else { LexKind = Tok.ID; } } else if (char.IsDigit(currentCh)) { while (char.IsDigit(currentCh)) { NextCh(); } LexValue = Int32.Parse(LexText); LexKind = Tok.INUM; } else if ((int)currentCh == 0) { LexKind = Tok.EOF; } else { LexError("Incorrect symbol " + currentCh); } }
public void OneLineComment() { var p = from v in Tok.OneLineComment(new HaskellDef()) select v; var res = p.Parse("-- This whole line is a comment"); Assert.True(!res.IsFaulted); }
public List <Token> ParseUntil(Tok type) { var toks = new List <Token>(); while (PeekType() != type) { toks.Add(Read()); } return(toks); }
private void TokOrTokEq(Tok tok, Tok tokEq) { NextCh(); LexKind = tok; if (currentCh == '=') { NextCh(); LexKind = tokEq; } }
private void Is(Tok t, int skip = 0, int len = 0) { var lt = _read[_tok++]; Assert.AreEqual(t, lt.Token); _pos += skip; Assert.AreEqual(_pos, lt.Start); Assert.AreEqual(len, lt.Length); _pos += len; }
public Natural() : base( inp => (from lex in Tok.Lexeme(new Int()) select lex) .Fail("natural") .Parse(inp) ) { }
public static Exception ArraySliceCbrMissed(Tok openBracket, Tok lastToken, bool hasStep) { int start = openBracket.Start; int finish = lastToken.Finish; return(new FunParseException(246, $"a{(hasStep?"[x:y:step]":"[x:y]")} <- ']' was missed{Nl} Example: a[1:5:2]", start, finish)); }
public Integer() : base( inp => (from lex in Tok.Lexeme(new Int()) select lex) .Fail("integer") .Parse(inp) ) { }
public void LexemeTest() { var lex = from l in Tok.Lexeme <ParserChar>(Prim.Character('A')) select l; var res = lex.Parse("A"); Assert.True(!res.IsFaulted); res = lex.Parse("A "); Assert.True(!res.IsFaulted); }
public async Task <bool> CreateTokAsync(Tok tok) { var apiUrl = $"{_apiSettings.ApiPrefix}/tok{_apiSettings.CodePrefix}{_apiSettings.ApiKey}"; _httpClient.DefaultRequestHeaders.Add("tokgroupid", tok.TokGroup.ToIdFormat()); _httpClient.DefaultRequestHeaders.Add("toktypeid", tok.TokTypeId); _httpClient.DefaultRequestHeaders.Add("categoryid", tok.CategoryId); HttpResponseMessage response = await _httpClient.PostAsJsonAsync(apiUrl, tok); return(response.IsSuccessStatusCode); }
public Reserved(string name, GeneralLanguageDef languageDef) : base( inp => Tok.Lexeme( from cs in IdentHelper.CaseString(name, languageDef) from nf in Prim.NotFollowedBy(languageDef.IdentLetter) .Fail("end of " + cs.AsString()) select new ReservedToken(cs, inp.Head().Location) ) .Parse(inp) ) { }
public static Exception FunctionArgumentInBracketDefinition(FunCallSyntaxNode headNode, ISyntaxNode headNodeChild, Tok flowCurrent) { if (flowCurrent == null) { throw new ArgumentNullException(nameof(flowCurrent)); } var sb = ErrorsHelper.ToFailureFunString(headNode, headNodeChild); return(new FunParseException(339, $"{headNode.Id}({sb}) = ... {Nl} Function argument is in bracket. Variable name (with optional type) without brackets expected", headNodeChild.Interval.Start, headNodeChild.Interval.Finish)); }
public Int() : base( inp => (from f in Tok.Lexeme <ParserChar>(new Sign()) from n in new Nat() select new IntegerToken( f.Value == '-' ? -n.Value : n.Value, f.Location )) .Parse(inp) ) { }
public ReservedOp(string name, GeneralLanguageDef languageDef) : base( inp => Tok.Lexeme( from op in Prim.String(name) from nf in Prim.NotFollowedBy(languageDef.OpLetter) .Fail("end of " + op.AsString()) select new ReservedOpToken(op, inp.First().Location) ) .Parse(inp) ) { }
public string TokToString(Tok t) { var result = t.ToString(); switch (t) { case Tok.ID: result += ' ' + LexText; break; case Tok.INUM: result += ' ' + LexValue.ToString(); break; } return(result); }
public void WhiteSpaceTest() { var p = from v in Tok.WhiteSpace(new HaskellDef()) select v; var res = p.Parse( @" {- This whole {- line is a comment and so is -} this one with nested comments this too -} let x=1"); var left = res.Value.Head().Item2.AsString(); Assert.True(!res.IsFaulted && left == "let x=1"); }
public CharLiteral() : base( inp => Tok.Lexeme( Prim.Between( Prim.Character('\''), Prim.Character('\'').Fail("end of character"), new CharacterChar() )) .Select(ch => new CharLiteralToken(ch, inp.Head().Location)) .Fail("character") .Parse(inp) ) { }
public async Task <bool> UpdateTokAsync(Tok tok) { InitializeApiClientUser(true); if (User.Id != tok.UserId) { throw new UnauthorizedAccessException(); } client.DefaultRequestHeaders.Add("userid", User.Id); client.DefaultRequestHeaders.Add("token", User.IdToken); client.BaseAddress = new Uri($"{baseUrl}/tok/{tok.Id}{codePrefix}{apiKey}"); HttpResponseMessage response = await client.PutAsJsonAsync(client.BaseAddress, tok); client = new HttpClient(); return(response.IsSuccessStatusCode); }
public static Exception ArrayInitializeStepMissed(Tok openBracket, Tok lastToken, Tok missedVal) { int start = openBracket.Start; int finish = lastToken.Finish; if (string.IsNullOrWhiteSpace(missedVal?.Value)) { return(new FunParseException(234, $"'[x..y..???]. Array step expected but was nothing'{Nl} Example: a[1..5..2]", start, finish)); } else { return(new FunParseException(237, $"'[x..y..???]. Array step expected but was {ErrorsHelper.ToText(missedVal)}'{Nl} Example: a[1..5..2]", start, finish)); } }
public static void Main() { String[] args = Environment.GetCommandLineArgs(); CmdIo source = new CmdIo(); try { source = new CmdIo(args); Tok tokenizer = new Tok(source); Lib funclibrary = new Lib(); Parser parser = new Parser(source, tokenizer, funclibrary); parser.parse_and_compile(); source.Finish(); } catch { source.Message("plil: compiler error."); } }