Parse single instruction in neutral text

This commit is contained in:
2025-09-07 21:20:32 -06:00
parent 5ba25d4270
commit 925e486e65
15 changed files with 482 additions and 18 deletions

30
ldtext/Lexer.fsl Normal file
View 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))}