Permalink
Browse files

A few minor fixes to Cachel

  • Loading branch information...
1 parent dfef925 commit 4e24fadf0df1180201337e059a039de7c3b642d6 Harry Pierson committed Aug 5, 2008
@@ -1,3 +0,0 @@
-// Turn on the lightweight syntax
-#light
-
@@ -355,6 +355,7 @@ EndOfFile <- !."
defs |> List.length |> should equal 29
cl |> should equal []
+(*
[<Fact>]
let test_PEG2_grammar () =
let peg_grammar = !! @"
@@ -402,4 +403,4 @@ EndOfFile <- !.
let Some(grammar, cl) = peg_grammar |> DevHawk.Parser.Peg2.Grammar
grammar.name |> should equal !!"PEG"
grammar.defs |> List.length |> should equal 31
- cl |> should equal []
+ cl |> should equal [] *)
@@ -34,11 +34,11 @@ let test_listify_with_item () =
[<Fact>]
let test_satisy_simple_predicate () =
let exp = Some('t', !!"est")
- satisfy (fun x -> x = 't') !!"test" |> should equal exp
+ satisfy item (fun x -> x = 't') !!"test" |> should equal exp
[<Fact>]
let test_satisy_failure_predicate () =
- satisfy (fun x -> x = 'e') !!"test" |> should equal None
+ satisfy item (fun x -> x = 'e') !!"test" |> should equal None
[<Fact>]
let test_any_of_success_predicate () =
@@ -55,14 +55,6 @@
{
"ProjRelPath" = "T"
}
- "peg2.fs"
- {
- "ProjRelPath" = "T"
- }
- "ometa.fs"
- {
- "ProjRelPath" = "T"
- }
}
"ProjStartupServices"
{
View
@@ -1,60 +0,0 @@
-#light
-
-(*
-ometa OMetaParser <: Parser {
- FromTo :x :y = Seq((x)) (~Seq((y)) Character)* Seq((y)),
- Space = Super((Space)) | FromTo(("//"), ("\n")) | FromTo(("/*"), ("*/")),
- NameFirst = '_' | '$' | Letter,
- NameRest = NameFirst | Digit,
- TSName = FirstAndRest(("NameFirst"), ("NameRest")):xs -> { xs.As<string>() },
- Name = Spaces TSName,
- EscapedChar = '\\' Character:c -> { System.Text.RegularExpressions.Regex.Unescape("\\" + c.As<string>())[0] }
- | Character,
- TSString = '\'' (~'\'' EscapedChar)*:xs '\'' -> { xs.As<string>() },
- Characters = '`' '`' (~('\'' '\'') EscapedChar)*:xs '\'' '\'' -> { Sugar.Cons("App", "Seq", xs.ToProgramString()) },
- SCharacters = '"' (~'"' EscapedChar)*:xs '"' -> { Sugar.Cons("App", "Token", xs.ToProgramString() ) },
- String = (('#' | '`') TSName | TSString):xs -> { Sugar.Cons("App", "Exactly", xs.ToProgramString() ) },
- Number = ('-' | Empty -> { "" }):sign Digit+:ds -> { Sugar.Cons("App", "Exactly", (sign != OMetaList<HostExpression>.Nil ? sign.As<string>() : "") + ds.As<string>()) },
- Keyword :xs = Token((xs)) ~LetterOrDigit -> { xs },
- HostExpr = Foreign((typeof(OMetaSharp.UnitTests.ManuallyCreatedCode.ManualCSharpRecognizer)), ("ParenExpr")),
- AtomicHostExpr = Foreign((typeof(OMetaSharp.UnitTests.ManuallyCreatedCode.ManualCSharpRecognizer)), ("Block")),
- Args = "(" ListOf(("HostExpr"), (",")):xs ")" -> { xs }
- | Empty -> { OMetaList<HostExpression>.Nil },
- Application = Name:rule Args:ags -> { Sugar.Cons("App", rule, ags) },
- SemAction = ("!" | "->") AtomicHostExpr:x -> { Sugar.Cons("Act", x) },
- SemPred = "?" HostExpr:x -> { Sugar.Cons("Pred", x) },
- Expr = ListOf(("Expr4"), ("|")):xs -> { Sugar.HackedInnerConcat("Or", xs) },
- Expr4 = Expr3*:xs -> { Sugar.HackedInnerConcat("And", xs) },
- OptIter :x = "*" -> { Sugar.Cons("Many", x) }
- | "+" -> { Sugar.Cons("Many1", x) }
- | Empty -> { x },
- Expr3 = Expr2:x OptIter((x)):x ( ':' Name:n -> { Sugar.StatementCons(
- () => Get<VariableSet>("Locals").Add(n.ToString())
- ,
- Sugar.Cons("Set", n, x)) }
- | Empty -> { x }
- )
- | ":" Name:n -> { Sugar.StatementCons(
- () => Get<VariableSet>("Locals").Add(n.ToString()),
- Sugar.Cons("Set", n, Sugar.Cons("App", "Anything"))) },
- Expr2 = "~" Expr2:x -> { Sugar.Cons("Not", x) }
- | "&" Expr1:x -> { Sugar.Cons("Lookahead", x) }
- | Expr1,
- Expr1 = Application | SemAction | SemPred
- | ( Keyword(("undefined")) | Keyword(("nil"))
- | Keyword(("true")) | Keyword(("false")) ):x -> { Sugar.Cons("App", "Exactly", x) }
- | Spaces (Characters | SCharacters | String | Number)
- | "[" Expr:x "]" -> { Sugar.Cons("Form", x) }
- | "(" Expr:x ")" -> { x },
- RuleName = Name
- | Spaces TSString,
- Rule = &(RuleName:n) !{Set("Locals", new VariableSet())}
- RulePart((n)):x ("," RulePart((n)))*:xs -> { Sugar.Cons("Rule", n, Get<VariableSet>("Locals"), Sugar.Cons("Or", x, xs)) },
- RulePart :rn = RuleName:n ?(n.Equals(rn)) Expr4:b1 ( "=" Expr:b2 -> { Sugar.Cons("And", b1, b2) }
- | Empty -> { b1 }
- ),
- Grammar = Keyword(("ometa")) Name:n
- ( "<:" Name | Empty -> { "OMeta" } ):sn
- "{" ListOf(("Rule"), (",")):rs "}" -> { Sugar.ConsWithFlatten("Grammar", n, sn, rs) }
-}
-*)
View
@@ -5,7 +5,7 @@ namespace DevHawk.Parser
module Core
-type Parser<'input, 'result> = 'input-> ('result * 'input) option
+type Parser<'input, 'result> = 'input -> ('result * 'input) option
//I define the monadic operators (zero, result, bind & choice) as individual
//functions so I can use them outside the parse monad
@@ -14,15 +14,15 @@ let result v : Parser<'i,'r> = fun input -> Some(v, input)
let bind p f : Parser<'i,'r> =
fun input ->
match p input with
- | Some(value, input) -> (f value) input
+ | Some(value, input) -> f value input
| None -> None
let zero : Parser<'i,'r> = fun input -> None
let choice p q : Parser<'i,'r> =
fun input ->
match p input with
- | Some(v,i) -> Some(v,i)
+ | Some(v) -> Some(v)
| None -> q input
//I define infix operator versions of bind and choice to make it more
@@ -32,7 +32,7 @@ let (+++) = choice
//Here's the parser monad definition
type ParserBuilder() =
- member w.Delay(f) = fun input -> f () (input)
+ member w.Delay(f) = fun input -> f () input
member w.Zero() = zero
member w.Return(v) = result v
member w.Bind(p, f) = p >>= f
View
@@ -296,27 +296,24 @@ let Identifier =
//Had to name this method pPrimary to avoid conflict with Primary discriminated union
let rec pPrimary =
parse {
- let! id = Identifier
- do! !~ LEFTARROW
- return Primary.Identifier(id) }
- +++
- parse {
- do! OPEN |> ignore
- let! exp = Expression
- do! CLOSE |> ignore
- return Primary.Expression(exp) }
- +++
- parse {
- let! lit = Literal
- return Primary.Literal(lit) }
- +++
- parse {
- let! cls = Class
- return Primary.Class(cls) }
- +++
- parse {
- do! DOT |> ignore
- return Dot }
+ return! parse {
+ let! id = Identifier
+ do! !~ LEFTARROW
+ return Primary.Identifier(id) }
+ return! parse {
+ do! OPEN |> ignore
+ let! exp = Expression
+ do! CLOSE |> ignore
+ return Primary.Expression(exp) }
+ return! parse {
+ let! lit = Literal
+ return Primary.Literal(lit) }
+ return! parse {
+ let! cls = Class
+ return Primary.Class(cls) }
+ return! parse {
+ do! DOT |> ignore
+ return Dot } }
///SequenceItem <- (AND / NOT)? Primary (QUESTION / STAR / PLUS)?
Oops, something went wrong.

0 comments on commit 4e24fad

Please sign in to comment.