-
Notifications
You must be signed in to change notification settings - Fork 0
Scanner Command Reference
Abe Pralle edited this page Nov 23, 2021
·
12 revisions
A .froley file should have one scanner section which is comprised of any number of routines.
From the [Simple][https://github.com/AbePralle/Froley/Examples/03-Simple-Scanner/Source/Simple.froley] scanner example.
First examine the full Scanner definition:
--------------------------------------------------------------------------------
scanner
--------------------------------------------------------------------------------
- main
consume [ \r\t]* # whitespace
if (consume('\n')) produce EOL
# single-line comment
if consume("#" [^\n]*) restart
if (not hasAnother) halt
markPosition
match
produceAny Symbols
endMatch
scan_id_or_keyword
scan_number
scan_string
syntaxError
- scan_id_or_keyword
if (not scan([_a-zA-Z][_a-zA-Z0-9]*)) return
match buffer
produceAny Keywords
others: produce IDENTIFIER
endMatch
- scan_number
if (not hasAnother) return
if (scan [0-9])
scan_integer
if (scan '.') scan_integer
produce NUMBER
elseIf (scan '.')
scan_integer
produce NUMBER
else
return
endIf
- scan_integer
while hasAnother
if (not scan([0-9]) and not consume('_'*)) return
endWhile
return
- scan_string
if (not consume('"')) return
while (hasAnother and not nextIs('\n'))
ch = read
if (ch == '"') produce STRING
elseIf (ch == '\\' and hasAnother) ch = read
collect ch
endWhile
syntaxError "Unterminated string."
Next