Skip to content

Commit

Permalink
minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellwrosen committed Jan 16, 2024
1 parent 447e924 commit a74c690
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion parser-typechecker/src/Unison/Runtime/IOSource.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Unison.Runtime.IOSource where
import Control.Lens (view, _2)
import Control.Monad.Morph (hoist)
import Data.List (elemIndex, genericIndex)
import qualified Data.Map as Map
import Data.Map qualified as Map
import Data.Text qualified as Text
import Text.RawString.QQ (r)
import Unison.Builtin qualified as Builtin
Expand Down
17 changes: 10 additions & 7 deletions parser-typechecker/src/Unison/Syntax/TermParser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import Unison.Prelude
import Unison.Reference (Reference)
import Unison.Referent (Referent)
import Unison.Syntax.Lexer qualified as L
import Unison.Syntax.Name qualified as Name (toString, toText, toVar, unsafeFromVar)
import Unison.Syntax.Name qualified as Name (toText, toVar, unsafeFromVar)
import Unison.Syntax.Parser hiding (seq)
import Unison.Syntax.Parser qualified as Parser (seq, uniqueName)
import Unison.Syntax.TypeParser qualified as TypeParser
Expand Down Expand Up @@ -407,17 +407,20 @@ hashQualifiedInfixTerm = resolveHashQualified =<< hqInfixId

quasikeyword :: Ord v => Text -> P v m (L.Token ())
quasikeyword kw = queryToken \case
L.WordyId (HQ'.NameOnly n) ->
case (Name.isRelative n, Name.reverseSegments n) of
(True, s NonEmpty.:| []) | NameSegment.toText s == kw -> Just ()
_ -> Nothing
L.WordyId (HQ'.NameOnly n) | nameIsKeyword n kw -> Just ()
_ -> Nothing

symbolyQuasikeyword :: (Ord v) => String -> P v m (L.Token ())
symbolyQuasikeyword :: (Ord v) => Text -> P v m (L.Token ())
symbolyQuasikeyword kw = queryToken \case
L.SymbolyId (HQ'.NameOnly n) | Name.toString n == kw -> Just ()
L.SymbolyId (HQ'.NameOnly n) | nameIsKeyword n kw -> Just ()
_ -> Nothing

nameIsKeyword :: Name -> Text -> Bool
nameIsKeyword name keyword =
case (Name.isRelative name, Name.reverseSegments name) of
(True, segment NonEmpty.:| []) -> NameSegment.toText segment == keyword
_ -> False

-- If the hash qualified is name only, it is treated as a var, if it
-- has a short hash, we resolve that short hash immediately and fail
-- committed if that short hash can't be found in the current environment
Expand Down

0 comments on commit a74c690

Please sign in to comment.