Parse single instruction in neutral text
This commit is contained in:
30
ldtext/Lexer.fsl
Normal file
30
ldtext/Lexer.fsl
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
open Parser
|
||||
open FSharp.Text.Lexing
|
||||
|
||||
exception SyntaxError of string
|
||||
|
||||
let lexeme (lexbuf:LexBuffer<byte>) = System.Text.Encoding.ASCII.GetString lexbuf.Lexeme
|
||||
}
|
||||
|
||||
// It's not necessary to name regexes like this, but it might
|
||||
// make the rule(s) clearer.
|
||||
let ident = ['_' 'a'-'z' 'A'-'Z' ]['_' 'a'-'z' 'A'-'Z' '.' '0'-'9']*
|
||||
|
||||
rule read =
|
||||
parse
|
||||
| ' '+ { read lexbuf }
|
||||
| ident { IDENTIFIER (lexeme lexbuf) }
|
||||
| '(' { LEFT_PAREN }
|
||||
| ')' { RIGHT_PAREN }
|
||||
| '[' { LEFT_BRACKET }
|
||||
| ']' { RIGHT_BRACKET }
|
||||
| ',' { COMMA }
|
||||
| ';' { SEMICOLON }
|
||||
| '?' { QUESTION_MARK }
|
||||
| eof { EOF }
|
||||
| _ { raise (SyntaxError (sprintf
|
||||
"SyntaxError: Unexpected char: '%s' Line: %d Column: %d"
|
||||
(lexeme lexbuf)
|
||||
(lexbuf.StartPos.Line + 1)
|
||||
lexbuf.StartPos.Column))}
|
Reference in New Issue
Block a user