compiler/Dart__Scanner.st
changeset 3 46c322c66a29
parent 1 46dd2b3b6974
child 5 77d56b3a771b
equal deleted inserted replaced
2:8fedb5e096fc 3:46c322c66a29
   104 
   104 
   105     ActionArray := Array new:256.
   105     ActionArray := Array new:256.
   106     TypeArray := Array new:256.
   106     TypeArray := Array new:256.
   107 
   107 
   108     block := [:s :char | s nextNumber].
   108     block := [:s :char | s nextNumber].
   109     ($0 asciiValue) to:($9 asciiValue) do:[:index |
   109     ($0 codePoint) to:($9 codePoint) do:[:index |
   110         ActionArray at:index put:block
   110         ActionArray at:index put:block
   111     ].
   111     ].
   112 
   112 
   113     block := [:s :char | s nextSingleCharacterToken:char].
   113     block := [:s :char | s nextSingleCharacterToken:char].
   114     #( $: $; $, ${ $} $( $) $[ $] $_ $? $@) do:[:ch |
   114     #( $: $; $, ${ $} $( $) $[ $] $_ $? $@) do:[:ch |
   115         ActionArray at:(ch asciiValue) put:block
   115         ActionArray at:(ch asciiValue) put:block
   116     ].
   116     ].
   117 
   117 
   118     block := [:s :char | s nextIdentifier].
   118     block := [:s :char | s nextIdentifier].
   119     ($a asciiValue) to:($z asciiValue) do:[:index |
   119     ($a codePoint) to:($z codePoint) do:[:index |
   120         ActionArray at:index put:block
   120         ActionArray at:index put:block
   121     ].
   121     ].
   122     ($A asciiValue) to:($Z asciiValue) do:[:index |
   122     ($A codePoint) to:($Z codePoint) do:[:index |
   123         ActionArray at:index put:block
   123         ActionArray at:index put:block
   124     ].
   124     ].
   125     ActionArray at:$_ asciiValue put:block.
   125     ActionArray at:$_ codePoint put:block.
   126 
   126 
   127     ActionArray at:$$ asciiValue put:block.
   127     ActionArray at:$$ codePoint put:block.
   128 
   128 
   129     ActionArray at:($. asciiValue) put:[:s :char | s nextDotOrFloatOrEllipsis].
   129     ActionArray at:($. codePoint) put:[:s :char | s nextDotOrFloatOrEllipsis].
   130 
   130 
   131     ActionArray at:($' asciiValue) put:[:s :char | s nextString:$' character:true].
   131     ActionArray at:($' codePoint) put:[:s :char | s nextString:$' character:false].
   132     ActionArray at:($" asciiValue) put:[:s :char | s nextString:$" character:false].
   132     ActionArray at:($" codePoint) put:[:s :char | s nextString:$" character:false].
   133     ActionArray at:($!! asciiValue) put:[:s :char | s nextMulti:#(($= #'!!=')) after:char].
   133     ActionArray at:($!! codePoint) put:[:s :char | s nextMulti:#(($= #'!!=')) after:char].
   134     ActionArray at:($= asciiValue) put:[:s :char | s nextMulti:#(($= #'==')) after:char].
   134     ActionArray at:($= codePoint) put:[:s :char | s nextMulti:#(($= #'==')) after:char].
   135     ActionArray at:($< asciiValue) put:[:s :char | s nextMulti:#(($= #'<=') ($< #'<<')) after:char].
   135     ActionArray at:($< codePoint) put:[:s :char | s nextMulti:#(($= #'<=') ($< #'<<')) after:char].
   136     ActionArray at:($> asciiValue) put:[:s :char | s nextMulti:#(($= #'>=') ($> #'>>' $> #'>>>' $= #'>>>=')) after:char].
   136     ActionArray at:($> codePoint) put:[:s :char | s nextMulti:#(($= #'>=') ($> #'>>' $> #'>>>' $= #'>>>=')) after:char].
   137 
   137 
   138     ActionArray at:($- asciiValue) put:[:s :char | s nextMulti:#(($- #'--') ($= #'-=')) after:char].
   138     ActionArray at:($- codePoint) put:[:s :char | s nextMulti:#(($- #'--') ($= #'-=')) after:char].
   139     ActionArray at:($+ asciiValue) put:[:s :char | s nextMulti:#(($+ #'++') ($= #'+=')) after:char].
   139     ActionArray at:($+ codePoint) put:[:s :char | s nextMulti:#(($+ #'++') ($= #'+=')) after:char].
   140     ActionArray at:($* asciiValue) put:[:s :char | s nextMulti:#(($= #'*=')) after:char].
   140     ActionArray at:($* codePoint) put:[:s :char | s nextMulti:#(($= #'*=')) after:char].
   141     ActionArray at:($/ asciiValue) put:[:s :char | s nextMulti:#(($= #'/=') ($/ nil #skipEOLComment) ($* nil #skipComment)) after:char].
   141     ActionArray at:($/ codePoint) put:[:s :char | s nextMulti:#(($= #'/=') ($/ nil #skipEOLComment) ($* nil #skipComment)) after:char].
   142     ActionArray at:($% asciiValue) put:[:s :char | s nextMulti:#(($= #'%=')) after:char].
   142     ActionArray at:($% codePoint) put:[:s :char | s nextMulti:#(($= #'%=')) after:char].
   143     ActionArray at:($& asciiValue) put:[:s :char | s nextMulti:#(($= #'&=') ($& #'&&')) after:char].
   143     ActionArray at:($& codePoint) put:[:s :char | s nextMulti:#(($= #'&=') ($& #'&&')) after:char].
   144     ActionArray at:($^ asciiValue) put:[:s :char | s nextMulti:#(($= #'^=')) after:char].
   144     ActionArray at:($^ codePoint) put:[:s :char | s nextMulti:#(($= #'^=')) after:char].
   145     ActionArray at:($~ asciiValue) put:[:s :char | s nextMulti:#(($= #'~=')) after:char].
   145     ActionArray at:($~ codePoint) put:[:s :char | s nextMulti:#(($= #'~=')) after:char].
   146     ActionArray at:($| asciiValue) put:[:s :char | s nextMulti:#(($= #'|=') ($| #'||')) after:char].
   146     ActionArray at:($| codePoint) put:[:s :char | s nextMulti:#(($= #'|=') ($| #'||')) after:char].
   147 
   147 
   148     "
   148     "
   149      self setupActions
   149      self setupActions
   150     "
   150     "
   151 
   151 
   152     "Created: / 14-05-1998 / 15:48:03 / cg"
   152     "Created: / 14-05-1998 / 15:48:03 / cg"
   153     "Modified: / 17-05-1998 / 21:03:37 / cg"
   153     "Modified: / 17-05-1998 / 21:03:37 / cg"
   154     "Modified: / 16-03-2012 / 23:49:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   154     "Modified: / 11-01-2013 / 13:04:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   155 !
   155 !
   156 
   156 
   157 setupKeywordTable
   157 setupKeywordTable
   158     "initialize the scanners actionTables - these are used to dispatch
   158     "initialize the scanners actionTables - these are used to dispatch
   159      into scanner methods as characters are read"
   159      into scanner methods as characters are read"
   216     "Created: / 14-05-1998 / 15:48:03 / cg"
   216     "Created: / 14-05-1998 / 15:48:03 / cg"
   217     "Modified: / 17-05-1998 / 21:03:37 / cg"
   217     "Modified: / 17-05-1998 / 21:03:37 / cg"
   218     "Modified: / 10-01-2013 / 10:51:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   218     "Modified: / 10-01-2013 / 10:51:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   219 ! !
   219 ! !
   220 
   220 
       
   221 !Scanner class methodsFor:'utility scanning'!
       
   222 
       
   223 scan: aString
       
   224     | tokens scanner |
       
   225 
       
   226     tokens := OrderedCollection new.
       
   227     scanner := (self for: aString).
       
   228     [ scanner atEnd ] whileFalse:[
       
   229         tokens add: scanner nextToken
       
   230     ].
       
   231     ^tokens
       
   232 
       
   233     "Created: / 11-01-2013 / 12:57:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   234 ! !
       
   235 
   221 !Scanner methodsFor:'accessing'!
   236 !Scanner methodsFor:'accessing'!
   222 
   237 
   223 token
   238 token
   224     "the previously scanned token"
   239     "the previously scanned token"
   225 
   240 
  1057 
  1072 
  1058 value:something
  1073 value:something
  1059     value := something.
  1074     value := something.
  1060 ! !
  1075 ! !
  1061 
  1076 
  1062 !Scanner::Token methodsFor:'printing & storing'!
       
  1063 
       
  1064 printOn:aStream
       
  1065     "append a printed representation if the receiver to the argument, aStream"
       
  1066 
       
  1067     super printOn:aStream.
       
  1068     aStream nextPutAll:'type: '.
       
  1069     type printOn:aStream.
       
  1070     aStream nextPutAll:'value: '.
       
  1071     value printOn:aStream.
       
  1072     aStream nextPutAll:'startPosition: '.
       
  1073     startPosition printOn:aStream.
       
  1074     aStream nextPutAll:'endPosition: '.
       
  1075     endPosition printOn:aStream.
       
  1076 ! !
       
  1077 
  1077 
  1078 !Scanner class methodsFor:'documentation'!
  1078 !Scanner class methodsFor:'documentation'!
  1079 
  1079 
  1080 version_HG
  1080 version_HG
  1081 
  1081