summary refs log tree commit diff stats
path: root/compiler/sigmatch.nim
Commit message (Expand)AuthorAgeFilesLines
* make range type checking more restrictive, see tn8vsint16 test case; minor br...Andreas Rumpf2017-11-011-1/+10
* made nimresolve part of the compilerAndreas Rumpf2017-10-291-1/+1
* deprecated unary '<'Andreas Rumpf2017-10-291-8/+8
* fixes #6526Araq2017-10-271-10/+14
* destructors: supportsCopyMem finally works for recursive typesAraq2017-10-261-1/+2
* preparations for another bugfixAndreas Rumpf2017-10-191-1/+12
* breaking change: arrays of char do not convert to cstring; ptr to array of ch...Andreas Rumpf2017-10-101-6/+7
* some work to make 'opt' a first class typeAndreas Rumpf2017-09-241-1/+1
* first implementation of the 'func' keywordAndreas Rumpf2017-09-231-4/+4
* fix #5918Zahary Karadjov2017-08-191-1/+3
* Fix #5084Zahary Karadjov2017-06-201-3/+6
* Fix #4737Zahary Karadjov2017-06-201-3/+6
* Fix #5127Zahary Karadjov2017-06-201-5/+6
* fix #1017; fix #3309Zahary Karadjov2017-06-201-0/+6
* fix #2730; fix #4880Zahary Karadjov2017-06-201-0/+7
* fix #5017; fix #5893Zahary Karadjov2017-06-201-1/+3
* fix #5864Zahary Karadjov2017-06-201-0/+2
* add a useful helper for debugging typeRel problemsZahary Karadjov2017-06-201-4/+26
* introduce a pre-processing pass for the concept bodiesZahary Karadjov2017-06-201-36/+22
* fix #5890Zahary Karadjov2017-06-201-1/+2
* cleanup of in/out covariance handlingAndreas Rumpf2017-05-171-6/+6
* enforce the covariance rules for user-defined generic typesZahary Karadjov2017-05-131-4/+4
* covariance for arrays and sequencesZahary Karadjov2017-05-121-12/+40
* doh, forgot to add all files in the previous commitZahary Karadjov2017-05-121-12/+58
* a simple way to simulate covariance in generic typesZahary Karadjov2017-04-281-1/+6
* fix a regrsesion in signature matching of derived ptr typesZahary Karadjov2017-04-181-3/+5
* Restore the compilation of linalg by tweaking the complex disambiguation rulesZahary Karadjov2017-04-161-10/+18
* fix regression in tmatrixconceptZahary Karadjov2017-04-161-0/+4
* fix a compilation error in linalgZahary Karadjov2017-04-161-25/+23
* fix #5689Zahary Karadjov2017-04-151-8/+10
* fix #5683Zahary Karadjov2017-04-141-6/+9
* lift parameter-less do block to lambdasZahary Karadjov2017-04-101-1/+12
* fix the do notation when used with procsZahary Karadjov2017-04-091-0/+3
* fix #5643; fix #5644Zahary Karadjov2017-04-081-2/+3
* Restore the Nim's 0.14 proper handling of generic aliasesZahary Karadjov2017-04-081-20/+67
* attempt to fix #5632 typedesc typeRel regression (#5634)andri lim2017-03-311-1/+1
* requested code review changesZahary Karadjov2017-03-291-12/+12
* restore compilation and make all concepts tests greenZahary Karadjov2017-03-241-4/+4
* Working test cases for the sophisticated matrix library example from the manualZahary Karadjov2017-03-241-19/+27
* further improvements to the error messages produced by conceptsZahary Karadjov2017-03-241-2/+7
* proper error reporting for concepts and the introduction of the {.explain.} p...Zahary Karadjov2017-03-241-13/+45
* implement the special treatment of explicit type params in conceptsZahary Karadjov2017-03-241-1/+3
* infer static parameters even when more complicated arithmetic is involvedZahary Karadjov2017-03-241-29/+114
* support derived values in non-generic user type classesZahary Karadjov2017-03-241-14/+6
* support for inferring static[T] concept paramsZahary Karadjov2017-03-241-21/+25
* introduce tyInferred for the unbound concept type paramsZahary Karadjov2017-03-241-71/+80
* support the full range of type modifiers when declaring concept vars and test...Zahary Karadjov2017-03-241-10/+21
* support for matching generic types' procs in generic conceptsZahary Karadjov2017-03-241-6/+36
* support for accessing types and consts defined in concepts with the dot operatorZahary Karadjov2017-03-241-12/+23
* support for accessing the inferred concept type params with the dot operatorZahary Karadjov2017-03-241-3/+14
span>= newStringStream() processed: seq[string] = @[] proc prt(outp: Stream, kind: PegKind, s: string; level: int = 0) = outp.writeLine indent.repeat(level) & "$1: $2" % [$kind, s] proc recLoop(p: Peg, level: int = 0) = case p.kind of pkEmpty..pkWhitespace: discard of pkTerminal, pkTerminalIgnoreCase, pkTerminalIgnoreStyle: outp.prt(p.kind, $p, level) of pkChar, pkGreedyRepChar: outp.prt(p.kind, $p, level) of pkCharChoice, pkGreedyRepSet: outp.prt(p.kind, $p, level) of pkNonTerminal: outp.prt(p.kind, "$1 @($3, $4)" % [p.nt.name, $p.nt.rule.kind, $p.nt.line, $p.nt.col], level) if not(p.nt.name in processed): processed.add p.nt.name p.nt.rule.recLoop level+1 of pkBackRef..pkBackRefIgnoreStyle: outp.prt(p.kind, $p, level) else: outp.prt(p.kind, $p, level) for s in items(p): s.recLoop level+1 pegAst.recLoop echo "PEG AST traversal output" echo "------------------------" echo outp.data block: var pStack: seq[string] = @[] valStack: seq[float] = @[] opStack = "" let parseArithExpr = pegAst.eventParser: pkNonTerminal: enter: pStack.add p.nt.name leave: pStack.setLen pStack.high if length > 0: let matchStr = s.substr(start, start+length-1) case p.nt.name of "Value": try: valStack.add matchStr.parseFloat echo valStack except ValueError: discard of "Sum", "Product": try: let val {.used.} = matchStr.parseFloat except ValueError: if valStack.len > 1 and opStack.len > 0: valStack[^2] = case opStack[^1] of '+': valStack[^2] + valStack[^1] of '-': valStack[^2] - valStack[^1] of '*': valStack[^2] * valStack[^1] else: valStack[^2] / valStack[^1] valStack.setLen valStack.high echo valStack opStack.setLen opStack.high echo opStack pkChar: leave: if length == 1 and "Value" != pStack[^1]: let matchChar = s[start] opStack.add matchChar echo opStack echo "Event parser output" echo "-------------------" let pLen = parseArithExpr(txt) doAssert txt.len == pLen import std/importutils block: proc pegsTest() = privateAccess(NonTerminal) privateAccess(Captures) doAssert escapePeg("abc''def'") == r"'abc'\x27\x27'def'\x27" doAssert match("(a b c)", peg"'(' @ ')'") doAssert match("W_HI_Le", peg"\y 'while'") doAssert(not match("W_HI_L", peg"\y 'while'")) doAssert(not match("W_HI_Le", peg"\y v'while'")) doAssert match("W_HI_Le", peg"y'while'") doAssert($ +digits == $peg"\d+") doAssert "0158787".match(peg"\d+") doAssert "ABC 0232".match(peg"\w+\s+\d+") doAssert "ABC".match(peg"\d+ / \w+") var accum: seq[string] = @[] for word in split("00232this02939is39an22example111", peg"\d+"): accum.add(word) doAssert(accum == @["this", "is", "an", "example"]) doAssert matchLen("key", ident) == 3 var pattern = sequence(ident, *whitespace, term('='), *whitespace, ident) doAssert matchLen("key1= cal9", pattern) == 11 var ws = newNonTerminal("ws", 1, 1) ws.rule = *whitespace var expr = newNonTerminal("expr", 1, 1) expr.rule = sequence(capture(ident), *sequence( nonterminal(ws), term('+'), nonterminal(ws), nonterminal(expr))) var c: Captures var s = "a+b + c +d+e+f" doAssert rawMatch(s, expr.rule, 0, c) == len(s) var a = "" for i in 0..c.ml-1: a.add(substr(s, c.matches[i][0], c.matches[i][1])) doAssert a == "abcdef" #echo expr.rule #const filename = "lib/devel/peg/grammar.txt" #var grammar = parsePeg(newFileStream(filename, fmRead), filename) #echo "a <- [abc]*?".match(grammar) doAssert find("_____abc_______", term("abc"), 2) == 5 doAssert match("_______ana", peg"A <- 'ana' / . A") doAssert match("abcs%%%", peg"A <- ..A / .A / '%'") var matches: array[0..MaxSubpatterns-1, string] if "abc" =~ peg"{'a'}'bc' 'xyz' / {\ident}": doAssert matches[0] == "abc" else: doAssert false var g2 = peg"""S <- A B / C D A <- 'a'+ B <- 'b'+ C <- 'c'+ D <- 'd'+ """ doAssert($g2 == "((A B) / (C D))") doAssert match("cccccdddddd", g2) doAssert("var1=key; var2=key2".replacef(peg"{\ident}'='{\ident}", "$1<-$2$2") == "var1<-keykey; var2<-key2key2") doAssert("var1=key; var2=key2".replace(peg"{\ident}'='{\ident}", "$1<-$2$2") == "$1<-$2$2; $1<-$2$2") doAssert "var1=key; var2=key2".endsWith(peg"{\ident}'='{\ident}") if "aaaaaa" =~ peg"'aa' !. / ({'a'})+": doAssert matches[0] == "a" else: doAssert false if match("abcdefg", peg"c {d} ef {g}", matches, 2): doAssert matches[0] == "d" doAssert matches[1] == "g" else: doAssert false accum = @[] for x in findAll("abcdef", peg".", 3): accum.add(x) doAssert(accum == @["d", "e", "f"]) for x in findAll("abcdef", peg"^{.}", 3): doAssert x == "d" if "f(a, b)" =~ peg"{[0-9]+} / ({\ident} '(' {@} ')')": doAssert matches[0] == "f" doAssert matches[1] == "a, b" else: doAssert false doAssert match("eine übersicht und außerdem", peg"(\letter \white*)+") # ß is not a lower cased letter?! doAssert match("eine übersicht und auerdem", peg"(\lower \white*)+") doAssert match("EINE ÜBERSICHT UND AUSSERDEM", peg"(\upper \white*)+") doAssert(not match("456678", peg"(\letter)+")) doAssert("var1 = key; var2 = key2".replacef( peg"\skip(\s*) {\ident}'='{\ident}", "$1<-$2$2") == "var1<-keykey;var2<-key2key2") doAssert match("prefix/start", peg"^start$", 7) if "foo" =~ peg"{'a'}?.*": doAssert matches[0].len == 0 else: doAssert false if "foo" =~ peg"{''}.*": doAssert matches[0] == "" else: doAssert false if "foo" =~ peg"{'foo'}": doAssert matches[0] == "foo" else: doAssert false let empty_test = peg"^\d*" let str = "XYZ" doAssert(str.find(empty_test) == 0) doAssert(str.match(empty_test)) proc handleMatches(m: int, n: int, c: openArray[string]): string = result = "" if m > 0: result.add ", " result.add case n: of 2: toLowerAscii(c[0]) & ": '" & c[1] & "'" of 1: toLowerAscii(c[0]) & ": ''" else: "" doAssert("Var1=key1;var2=Key2; VAR3". replace(peg"{\ident}('='{\ident})* ';'* \s*", handleMatches) == "var1: 'key1', var2: 'Key2', var3: ''") doAssert "test1".match(peg"""{@}$""") doAssert "test2".match(peg"""{(!$ .)*} $""") pegsTest() static: pegsTest()