summary refs log tree commit diff stats
path: root/lib/base/lex.nim
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2008-08-23 11:32:48 +0200
committerAndreas Rumpf <rumpf_a@web.de>2008-08-23 11:32:48 +0200
commit972c51086152bd45aef4eb17c099fa3472a19d04 (patch)
tree3e51e4f71f737a4f943bb71cd889d7002c3d4b5a /lib/base/lex.nim
parent07d5a8085bbcc21a1d9d06a2976ecc00e9c8d55b (diff)
downloadNim-972c51086152bd45aef4eb17c099fa3472a19d04.tar.gz
deleted web and dist
Diffstat (limited to 'lib/base/lex.nim')
-rw-r--r--lib/base/lex.nim73
1 files changed, 73 insertions, 0 deletions
diff --git a/lib/base/lex.nim b/lib/base/lex.nim
new file mode 100644
index 000000000..34f0c32a8
--- /dev/null
+++ b/lib/base/lex.nim
@@ -0,0 +1,73 @@
+# Lexer generator for Nimrod
+#   (c) 2008 Andreas Rumpf
+
+# Stress testing for the macro feature
+
+# the syntax that should be supported is:
+
+# template numpostfix = 
+#   '\'' & 'F'|'f'|'i'|'I' & "32"|"64"|"8"|"16"
+# template edigits = 
+#   'e'|'E' & +digits
+# tokens(
+#   tkIdent: +UniIdentStart & *UniIdentRest,
+#   tkHexNumber: '0' & ('x'|'X') & +hexDigits & ?( numpostfix ),
+#   tkOctNumber: '0' & ('c'|'C') & +octDigits & ?( numpostfix ),
+#   tkBinNumber: '0' & ('b'|'B') & +binDigits & ?( numpostfix ),
+#   tkIntNumber: +digits & ?( numpostfix ), 
+#   tkFloatNumber: +digits & ('.' & +digits & ?(edigits) | edigits) & ?(numpostfix),
+#   
+# )
+# actions(
+#   tkIdent: lookup
+# ) 
+# 
+
+#
+#  match inputstream
+#  of +('A'..'Z' | '_' | 'a'..'z') *('A'..'Z' | '_' | 'a'..'z' | '0'..'9') :
+#    
+#    x = inputstream[pos..length]
+#  of '0' 'x' +('0'..'9' | 'a'..'f' | '_' | 'A'..'F') : 
+#    y = ...
+
+const
+  AsciiLetter = {'A'..'Z', 'a'..'z'}
+  uniLetter = AsciiLetter + {'\128'..'\255'}
+  digits = {'0'..'9'}
+  hexDigits = {'0'..'9', 'a'..'f', 'A'..'F'}
+  octDigits = {'0'..'7'}
+  binDigits = {'0'..'1'}
+  AsciiIdentStart = AsciiLetter + {'_'} 
+  AsciiIdentRest = AsciiIdentStart + Digits
+  UniIdentStart = UniLetter + {'_'} 
+  UniIdentRest = UniIdentStart + Digits
+
+# --> if match(s, +AsciiIdentStart & *AsciiIdentRest): 
+
+#  Regular expressions in Nimrod itself!
+#  -------------------------------------
+#  
+#  'a' -- matches the character a
+#  'a'..'z'  -- range operator '-'
+#  'A' | 'B' -- alternative operator |
+#  * 'a' -- prefix * is needed
+#  + 'a' -- prefix + is needed
+#  ? 'a' -- prefix ? is needed
+#  *? prefix is needed
+#  +? prefix is needed
+#  letter  -- character classes with real names!
+#  letters
+#  white
+#  whites
+#  any   -- any character
+#  ()    -- are Nimrod syntax
+#  ! 'a'-'z'
+#  
+#  -- concatentation via proc call:
+#  
+#  re('A' 'Z' *word  )
+
+macro re(n: expr): expr = 
+  
+  result = newCall("magic_re", x)