summary refs log tree commit diff
path: root/machines/zibeline/hardware.nix
blob: b60a848569ae3fcd16b1ca03f8d6510f8e6c3443 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Do not modify this file!  It was generated by ‘nixos-generate-config’
# and may be overwritten by future invocations.  Please make changes
# to /etc/nixos/configuration.nix instead.
{ config, lib, pkgs, modulesPath, ... }:

{
  imports = [ ];

  boot.initrd.availableKernelModules = [ "ata_piix" "sd_mod" ];
  boot.initrd.kernelModules = [ ];
  boot.kernelModules = [ ];
  boot.extraModulePackages = [ ];

  fileSystems."/" =
    { device = "/dev/disk/by-uuid/a029352d-e2e9-432d-ae2a-43921652ea8b";
      fsType = "ext4";
    };

  swapDevices = [ ];

  nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
  virtualisation.hypervGuest.enable = true;
}
t.Special */ .highlight .gd { color: #DDD } /* Generic.Deleted */ .highlight .ge { color: #DDD } /* Generic.Emph */ .highlight .ges { color: #DDD } /* Generic.EmphStrong */ .highlight .gr { color: #DDD } /* Generic.Error */ .highlight .gh { color: #DDD } /* Generic.Heading */ .highlight .gi { color: #DDD } /* Generic.Inserted */ .highlight .go { color: #DDD } /* Generic.Output */ .highlight .gp { color: #DDD } /* Generic.Prompt */ .highlight .gs { color: #DDD } /* Generic.Strong */ .highlight .gu { color: #DDD } /* Generic.Subheading */ .highlight .gt { color: #DDD } /* Generic.Traceback */ .highlight .kc { color: #F00 } /* Keyword.Constant */ .highlight .kd { color: #F00 } /* Keyword.Declaration */ .highlight .kn { color: #F00 } /* Keyword.Namespace */ .highlight .kp { color: #F00 } /* Keyword.Pseudo */ .highlight .kr { color: #F00 } /* Keyword.Reserved */ .highlight .kt { color: #EE82EE } /* Keyword.Type */ .highlight .ld { color: #DDD } /* Literal.Date */ .highlight .m { color: #F0F } /* Literal.Number */ .highlight .s { color: #87CEEB } /* Literal.String */ .highlight .na { color: #DDD } /* Name.Attribute */ .highlight .nb { color: #DDD } /* Name.Builtin */ .highlight .nc { color: #DDD } /* Name.Class */ .highlight .no { color: #7FFFD4 } /* Name.Constant */ .highlight .nd { color: #DDD } /* Name.Decorator */ .highlight .ni { color: #DDD } /* Name.Entity */ .highlight .ne { color: #DDD } /* Name.Exception */ .highlight .nf { color: #FF0 } /* Name.Function */ .highlight .nl { color: #DDD } /* Name.Label */ .highlight .nn { color: #DDD } /* Name.Namespace */ .highlight .nx { color: #DDD } /* Name.Other */ .highlight .py { color: #DDD } /* Name.Property */ .highlight .nt { color: #DDD } /* Name.Tag */ .highlight .nv { color: #EEDD82 } /* Name.Variable */ .highlight .ow { color: #F00 } /* Operator.Word */ .highlight .pm { color: #DDD } /* Punctuation.Marker */ .highlight .w { color: #DDD } /* Text.Whitespace */ .highlight .mb { color: #F0F } /* Literal.Number.Bin */ .highlight .mf { color: #F0F } /* Literal.Number.Float */ .highlight .mh { color: #F0F } /* Literal.Number.Hex */ .highlight .mi { color: #F0F } /* Literal.Number.Integer */ .highlight .mo { color: #F0F } /* Literal.Number.Oct */ .highlight .sa { color: #87CEEB } /* Literal.String.Affix */ .highlight .sb { color: #87CEEB } /* Literal.String.Backtick */ .highlight .sc { color: #87CEEB } /* Literal.String.Char */ .highlight .dl { color: #87CEEB } /* Literal.String.Delimiter */ .highlight .sd { color: #87CEEB } /* Literal.String.Doc */ .highlight .s2 { color: #87CEEB } /* Literal.String.Double */ .highlight .se { color: #87CEEB } /* Literal.String.Escape */ .highlight .sh { color: #87CEEB } /* Literal.String.Heredoc */ .highlight .si { color: #87CEEB } /* Literal.String.Interpol */ .highlight .sx { color: #87CEEB } /* Literal.String.Other */ .highlight .sr { color: #87CEEB } /* Literal.String.Regex */ .highlight .s1 { color: #87CEEB } /* Literal.String.Single */ .highlight .ss { color: #87CEEB } /* Literal.String.Symbol */ .highlight .bp { color: #DDD } /* Name.Builtin.Pseudo */ .highlight .fm { color: #FF0 } /* Name.Function.Magic */ .highlight .vc { color: #EEDD82 } /* Name.Variable.Class */ .highlight .vg { color: #EEDD82 } /* Name.Variable.Global */ .highlight .vi { color: #EEDD82 } /* Name.Variable.Instance */ .highlight .vm { color: #EEDD82 } /* Name.Variable.Magic */ .highlight .il { color: #F0F } /* Literal.Number.Integer.Long */
use std::{iter::Peekable, str::Chars};

use super::token::{Location, Token, TokenVariant};

pub struct Lexer<'source> {
    location: Location,
    chars: Peekable<Chars<'source>>,
    done: bool,
}

impl Iterator for Lexer<'_> {
    type Item = Token;

    fn next(&mut self) -> Option<Self::Item> {
        use super::token::TokenVariant::*;

        if self.done {
            return None;
        }

        if let None = self.chars.peek() {
            self.done = true;
            return Some(Token {
                location: self.location,
                variant: Eof,
            });
        }

        self.skip_whitespace();

        let c = *self.chars.peek()?;

        let token = if c.is_numeric() {
            self.number()
        } else if c.is_alphabetic() {
            self.identifier()
        } else if c == '"' {
            self.str()
        } else {
            let location = self.location;

            // Fixed length tokens
            let variant = match self.advance().unwrap() {
                '+' => OpPlus,
                '-' => {
                    if self.advance_if('>') {
                        Arrow
                    } else {
                        OpMinus
                    }
                }
                '*' => OpStar,
                '/' => OpSlash,
                '=' => {
                    if self.advance_if('=') {
                        OpEq
                    } else {
                        Assign
                    }
                }
                '!' => {
                    if self.advance_if('=') {
                        OpNeq
                    } else {
                        OpNot
                    }
                }
                '<' => {
                    if self.advance_if('=') {
                        OpLte
                    } else {
                        OpLt
                    }
                }
                '>' => {
                    if self.advance_if('=') {
                        OpGte
                    } else {
                        OpGt
                    }
                }
                '(' => GroupOpen,
                ')' => GroupClose,
                '{' => BlockOpen,
                '}' => BlockClose,
                '.' => Dot,
                ',' => Comma,
                ':' => {
                    if self.advance_if('=') {
                        ConstAssign
                    } else {
                        Colon
                    }
                }
                ';' => SemiColon,
                _ => Unknown(c),
            };

            Token { location, variant }
        };

        Some(token)
    }
}

impl<'s> Lexer<'s> {
    pub fn new(source: &'s str) -> Self {
        Lexer {
            location: Location { col: 0, row: 0 },
            chars: source.chars().peekable(),
            done: false,
        }
    }

    fn advance(&mut self) -> Option<char> {
        let next = self.chars.next();
        if let Some(c) = next {
            if c == '\n' {
                self.location.row += 1;
                self.location.col = 0;
            } else {
                self.location.row += 1;
            }
        }

        next
    }

    fn advance_if(&mut self, c: char) -> bool {
        self.chars.next_if_eq(&c).is_some()
    }

    fn skip_whitespace(&mut self) {
        while self
            .chars
            .peek()
            .map_or(false, |x| x.is_whitespace() && *x != '\n')
        {
            self.advance();
        }
    }

    fn number(&mut self) -> Token {
        let location = self.location;

        let mut is_integer = true;
        let mut buffer = String::new();

        while self
            .chars
            .peek()
            .map_or(false, |&c| c.is_numeric() || c == '.')
        {
            let c = self.advance().unwrap();
            if c == '.' {
                is_integer = false;
            }
            buffer.push(c);
        }

        let variant = if is_integer {
            let int = buffer.parse().expect("Failed lexing integer token.");
            TokenVariant::Int(int)
        } else {
            let float = buffer.parse().expect("Failed lexing float token.");
            TokenVariant::Float(float)
        };

        Token { location, variant }
    }

    fn identifier(&mut self) -> Token {
        let location = self.location;

        let mut buffer = String::new();

        while self.chars.peek().map_or(false, |&c| c.is_alphabetic()) {
            let c = self.advance().unwrap();
            buffer.push(c);
        }

        let variant = match buffer.as_str() {
            "fn" => TokenVariant::KeywordFn,
            "type" => TokenVariant::KeywordType,
            "form" => TokenVariant::KeywordForm,
            "self" => TokenVariant::KeywordSelf,
            _ => TokenVariant::Identifer(buffer),
        };

        Token { location, variant }
    }

    fn str(&mut self) -> Token {
        let location = self.location;

        // Remove first "
        self.advance().unwrap();

        let mut buffer = String::new();
        loop {
            let c = self.advance().expect("Expected Str literal to be closed");
            if c == '"' {
                break;
            }
            buffer.push(c);
        }

        Token {
            location,
            variant: TokenVariant::Str(buffer),
        }
    }
}