summary refs log blame commit diff stats
path: root/tests/lexer/tlexer.nim
blob: e36220e7adabb5911baf786fb2560dc80202807e (plain) (tree)



























































                                                                                                
discard """
  disabled: true
"""

# We start with a comment
# This is the same comment

# This is a new one!

import
  lexbase, os, strutils

type
  TMyRec {.final.} = object
    x, y: int     # coordinates
    c: char       # a character
    a: int32      # an integer

  PMyRec = ref TMyRec # a reference to `TMyRec`

proc splitText(txt: string): seq[string] # splits a text into several lines
                                         # the comment continues here
                                         # this is not easy to parse!

proc anotherSplit(txt: string): seq[string] =
  # the comment should belong to `anotherSplit`!
  # another problem: comments are statements!

const
  x = 0B0_10001110100_0000101001000111101011101111111011000101001101001001'f64 # x ~~ 1.72826e35
  myNan = 0B01111111100000101100000000001000'f32 # NAN
  y = """
    a rather long text.
    Over many
    lines.
  """
  s = "\xff"
  a = {0..234}
  b = {0..high(int)}
  v = 0'i32
  z = 6767566'f32

# small test program for lexbase

proc main*(infile: string, a, b: int, someverylongnamewithtype = 0,
           anotherlongthingie = 3) =
  var
    myInt: int = 0
    s: seq[string]
  # this should be an error!
  if initBaseLexer(L, infile, 30): nil
  else:
    writeLine(stdout, "could not open: " & infile)
  writeLine(stdout, "Success!")
  call(3, # we use 3
       12, # we use 12
       43) # we use 43


main(ParamStr(1), 9, 0)
uot;"" output: '''TBar2 TFoo ''' """ ## XXX this output needs to be adapated for VCC which produces different results. # It turned out that it's hard to generate correct for these two test cases at # the same time. type TFoo = ref object of RootObj Data: int TBar = ref object of TFoo nil TBar2 = ref object of TBar d2: int template super(self: TBar): TFoo = self template super(self: TBar2): TBar = self proc Foo(self: TFoo) = echo "TFoo" #proc Foo(self: TBar) = # echo "TBar" # Foo(super(self)) # works when this code is uncommented proc Foo(self: TBar2) = echo "TBar2" Foo(super(self)) var b: TBar2 new(b) Foo(b) # bug #837 type PView* = ref TView TView* {.inheritable.} = object data: int PWindow* = ref TWindow TWindow* = object of TView data3: int PDesktop* = ref TDesktop TDesktop* = object of TView data2: int proc makeDesktop(): PDesktop = new(TDesktop) proc makeWindow(): PWindow = new(TWindow) proc thisCausesError(a: PView, b: PView) = discard var dd = makeDesktop() var aa = makeWindow() thisCausesError(dd, aa) # bug #5892 type Foo6 = distinct array[4, float32] AnotherFoo = distinct array[4, float32] AbstractAnimationSampler* = ref object of RootObj AnimationSampler*[T] = ref object of AbstractAnimationSampler sampleImpl: proc(s: AnimationSampler[T], p: float): T ArrayAnimationSampler*[T] = ref object of AnimationSampler[T] proc newArrayAnimationSampler*[T](): ArrayAnimationSampler[T] = result.new() result.sampleImpl = nil discard newArrayAnimationSampler[Foo6]() discard newArrayAnimationSampler[AnotherFoo]()