Skip to content

Instantly share code, notes, and snippets.

View gist:00b6c75451ce729ecdf37d22c2dfd5b9
module Regex =
open System.Text.RegularExpressions
type REx = REx of string with
member r.txt = let (REx t) = r in t
static member (+)(REx a, REx b) = REx(a + b)
let rex (REx v) = v
let (|Regex|_|) (REx pattern) input =
@amieres
amieres / Msal.fs
Created Apr 2, 2019
Preamble for Msal.js & Azure AD B2C
View Msal.fs
#I @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1"
#I @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades"
#I @"D:\Abe\CIPHERWorkspace\FSharpStation\packages\WebSharper\lib\net461"
#I @"D:\Abe\CIPHERWorkspace\FSharpStation\packages\WebSharper.UI\lib\net461"
#r @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\mscorlib.dll"
#r @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Core.dll"
#r @"D:\Abe\CIPHERWorkspace\FSharpStation\packages\WebSharper\lib\net461\WebSharper.Core.dll"
#r @"D:\Abe\CIPHERWorkspace\FSharpStation\packages\WebSharper\lib\net461\WebSharper.Core.JavaScript.dll"
#r @"D:\Abe\CIPHERWorkspace\FSharpStation\packages\WebSharper\lib\net461\WebSharper.Collections.dll"
#r @"D:\Abe\CIPHERWorkspace\FSharpStation\packages\WebSharper\lib\net461\WebSharper.InterfaceGenerator.dll"
View gist:de365ab0e98be6d91df5
private void button1_Click(object sender,EventArgs e) {
Parser P = new Parser(this.textBox1.Text);
if (P.Parse())
this.textBox2.Text = "Success!";
else
this.textBox2.Text = "Failed at " + P.Position.ToString();
}
View gist:c61c9da3055ff7dc3b1b
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace SimpleParser {
class Parser {
public Parser(string Text) {
Input = Text;
View gist:0ef3dcf02b4714183c1e
String Input = null;
int LastPosition = -1;
int SpaceLength = 0;
void SkipSpacesComments() {
if (Position == LastPosition) return;
LastPosition = Position;
CurrentString = Input.Substring(Position);
string RegEx = "^([ \\t\\n\\r]|\\/\\*.*?\\*\\/)*";
Match M = Regex.Match(CurrentString, RegEx);
View gist:ec8c5b8332c267871ea1
public int Position = 0;
String Token = null;
string CurrentString;
bool R(string RegEx) {
SkipSpacesComments();
Match M = Regex.Match(CurrentString, "^" + RegEx
, RegexOptions.IgnoreCase);
if (M.Success) {
Token = CurrentString.Substring(0, M.Length);
View gist:5829c37fe6e0c48ae561
public bool Stopping = false;
bool P(rule R) {
if (Stopping) return false;
int StartingPosition = Position;
bool Result = R();
if (!Result && StartingPosition != Position)
Stopping = true;
return Result;
}
View grammarCSharp
wexpr = () => P(() => expr(0) && EOS() );
expr = (L) => P(() => mexpr() && expr2(L) );
expr2 = (L) => P(() => L < 4 && C("+") && expr(4) && expr2(L) )
|| P(() => L < 4 && C("-") && expr(4) && expr2(L) )
|| P(() => L < 5 && C("*") && expr(5) && expr2(L) )
|| P(() => L < 5 && C("/") && expr(5) && expr2(L) )
|| P(() => L < 2 && C("<=") && expr(2) && expr2(L) )
|| P(() => L < 2 && C(">=") && expr(2) && expr2(L) )
View gist:c0ce24e4d3c29a119f7d
wexpr => expr(0) EOS
expr(L) => mexpr expr2(L)
expr2(L)=> L < 4 "+" expr(4) expr2(L)
=> L < 4 "-" expr(4) expr2(L)
=> L < 5 "*" expr(5) expr2(L)
=> L < 5 "/" expr(5) expr2(L)
=> L < 2 "<=" expr(2) expr2(L)
=> L < 2 ">=" expr(2) expr2(L)