Boost.Spirit用户手册翻译(17):深入:扫描器

 

In-depth: The Scanner

深入:扫描器


 

Basic Scanner API

基本扫描器API

class scanner
value_t

typedef: The value type of the scanner's iterator

typedef,扫描器的迭代器的值类型

ref_t

typedef: The reference type of the scanner's iterator

typedef,扫描器迭代器的引用类型

bool at_end() const

Returns true if the input is exhausted

如果输入耗尽则返回真

value_t operator*() const

Dereference/get a value_t from the input

从输入解引用/取得一个value_t

scanner const& operator++()

move the scanner forward

使扫描器步进

IteratorT& first

The iterator pointing to the current input position. Held by reference

指向当前位置的迭代器,以引用的方式使用。

IteratorT const last

The iterator pointing to the end of the input. Held by value

指向输入终点的迭代器,以值的方式使用。

The basic behavior of the scanner is handled by policies. The actual execution of the scanner's public member functions listed in the table above is implemented by the scanner policies.

扫描器的基本行为是通过策略执行的。上表中列出的扫描器的public成员函数的真正执行是由扫描器策略来实现的。

Three sets of policies govern the behavior of the scanner. These policies make it possible to extend Spirit non-intrusively. The scanner policies allow the core-functionality to be extended without requiring any potentially destabilizing changes to the code. A library writer might provide her own policies that override the ones that are already in place to fine tune the parsing process to fit her own needs. Layers above the core might also want to take advantage of this policy based machanism. Abstract syntax tree generation, debuggers and lexers come to mind.

三类策略决定了扫描器的行为。这些策略使得非侵犯性地扩展Spirit成为可能。扫描器的策略使得从根本上不必对原有代码进行修改就可以扩展其核心功能。一个库的编写者可以用他自己编写的策略覆盖原有的策略来调整分析过程以适应自己的需要。核心之上的层次也有可能从基于策略的设计方式获得好处。抽象语法树的生成、调试器、词法分析器等等就是这种情况。

There are three sets of policies that govern:

三类策略分别管理:

  • Iteration and filtering
  • 迭代和过滤
  • Recognition and matching
  • 识别与匹配
  • Handling semantic actions
  • 处理语义动作

iteration_policy

Here are the default policies that govern iteration and filtering:

这是管理迭代和过滤的默认策略:

    struct iteration_policy
    {
        template <typename ScannerT>
        void
        advance(ScannerT const& scan) const
        { ++scan.first; }

        template <typename ScannerT>
        bool at_end(ScannerT const& scan) const
        { return scan.first == scan.last; }

        template <typename T>
        T filter(T ch) const
        { return ch; }

        template <typename ScannerT>
        typename ScannerT::ref_t
        get(ScannerT const& scan) const
        { return *scan.first; }
    };

Iteration and filtering policies

迭代和过滤策略 

advance

Move the iterator forward

步进迭代器

at_end

Return true if the input is exhausted

如果输入耗尽则返回真

filter

Filter a character read from the input

过滤从输入中读入的一个字符

get

Read a character from the input

从输入中读取一个字符

The following code snippet demonstrates a simple policy that converts all characters to lower case:

下面的代码片断展示了一个把所有字母转为小写的简单策略:

    struct inhibit_case_iteration_policy : public iteration_policy
    {
        template <typename CharT>
        CharT filter(CharT ch) const
        { 
            return std::tolower(ch); 
        }
    };

match_policy

Here are the default policies that govern recognition and matching:

这是管理识别和匹配的默认策略:

    struct match_policy
    {
        template <typename T>
        struct result 
        { 
            typedef match<T> type; 
        };

        const match<nil_t>
        no_match() const
        { 
            return match<nil_t>(); 
        }

        const match<nil_t>
        empty_match() const
        { 
            return match<nil_t>(0, nil_t()); 
        }

        template <typename AttrT, typename IteratorT>
        match<AttrT>
        create_match(
            std::size_t         length,
            AttrT const&        val,
            IteratorT const&    /*first*/,
            IteratorT const&    /*last*/) const
        { 
            return match<AttrT>(length, val); 
        }

        template <typename MatchT, typename IteratorT>
        void
        group_match(
            MatchT&             /*m*/,
            parser_id const&    /*id*/,
            IteratorT const&    /*first*/,
            IteratorT const&    /*last*/) const {}

        template <typename Match1T, typename Match2T>
        void
        concat_match(Match1T& l, Match2T const& r) const
        { 
            l.concat(r); 
        }
    };

Recognition and matching

识别与匹配

result

A metafunction that returns a match type given an attribute type (see In-depth: The Parser)

给定属性类型返回匹配类型的元函数(见 深入:分析器)

no_match

Create a failed match

生成一个失败匹配

empty_match

Create an empty match. An empty match is a successful epsilon match (matching length == 0)

生成一个空匹配。空匹配是指成功的空集匹配(匹配长度为0)

create_match

Create a match given the matching length, an attribute and the iterator pair pointing to the matching portion of the input

生成一个带着匹配长度、匹配属性和指向输入中的匹配段的迭代器对的匹配

group_match

For non terminals such as rules, this is called after a successful match has been made to allow post processing

对诸如rule这样的非终结符,这玩意将在成功匹配后调用以进行后续处理

concat_match

Concatenate two match objects

合并两个匹配对象

action_policy

The action policy has only one function for handling semantic actions:

动作策略只有一个处理语义动作的函数:

    struct action_policy
    {
        template <typename ActorT, typename AttrT, typename IteratorT>
        void
        do_action(
            ActorT const&       actor,
            AttrT const&        val,
            IteratorT const&    first,
            IteratorT const&    last) const;
    };

The default action policy forwards to:

默认的策略为:

    actor(first, last);

If the attribute val is of type nil_t. Otherwise:

如果属性val是nil_t的话。否则:

    actor(val);

scanner_policies mixer

scanner_policies 混合器

The class scanner_policies combines the three scanner policy classes above into one:

scanner_policies类把上面三类策略捆绑在了一起:

    template <
        typename IterationPolicyT   = iteration_policy,
        typename MatchPolicyT       = match_policy,
        typename ActionPolicyT      = action_policy>
    struct scanner_policies;

This mixer class inherits from all the three policies. This scanner_policies class is then used to parameterize the scanner:

这个混合器类同时继承了三个策略。然后这个scanner_policies就被用于将扫描器参数化:

    template <
        typename IteratorT = char const*,
        typename PoliciesT = scanner_policies<> >
    class scanner;

The scanner in turn inherits from the PoliciesT.

扫描器接着继承PoliciesT。

Rebinding Policies

策略重绑定

The scanner can be made to rebind to a different set of policies anytime. It has a member function change_policies(new_policies). Given a new set of policies, this member function creates a new scanner with the new set of policies. The result type of the rebound scanner can be can be obtained by calling the metafunction:

扫描器在任何时刻都可以绑定另外的策略。它有一个change_policies(new_policies)成员函数。给定一个新的策略集,这个成员函数产生一个带有给定策略集的新的扫描器。重新绑定的扫描器的结果类可以通过下述元函数取得:

    rebind_scanner_policies<ScannerT, PoliciesT>::type

Rebinding Iterators

迭代器重绑定

The scanner can also be made to rebind to a different iterator type anytime. It has a member function change_iterator(first, last). Given a new pair of iterator of type different from the ones held by the scanner, this member function creates a new scanner with the new pair of iterators. The result type of the rebound scanner can be can be obtained by calling the metafunction:

扫描器也可以在任何时刻重新绑定不同的迭代器类。它有一个change_iterator(first, last)成员函数。给定一对与原先的扫描器所持有的迭代器的类型不同的迭代器,这个成员函数将产生一个带有新的迭代器对的扫描器。重绑定的扫描器的结果类可以通过下述元函数取得:

    rebind_scanner_iterator<ScannerT, IteratorT>::type
 


基于SSM框架的智能家政保洁预约系统,是一个旨在提高家政保洁服务预约效率和管理水平的平台。该系统通过集成现代信息技术,为家政公司、家政服务人员和消费者提供了一个便捷的在线预约和管理系统。 系统的主要功能包括: 1. **用户管理**:允许消费者注册、登录,并管理他们的个人资料和预约历史。 2. **家政人员管理**:家政服务人员可以注册并更新自己的个人信息、服务类别和服务时间。 3. **服务预约**:消费者可以浏览不同的家政服务选项,选择合适的服务人员,并在线预约服务。 4. **订单管理**:系统支持订单的创建、跟踪和管理,包括订单的确认、完成和评价。 5. **评价系统**:消费者可以在家政服务完成后对服务进行评价,帮助提高服务质量和透明度。 6. **后台管理**:管理员可以管理用户、家政人员信息、服务类别、预约订单以及处理用户反馈。 系统采用Java语言开发,使用MySQL数据库进行数据存储,通过B/S架构实现用户与服务的在线交互。系统设计考虑了不同用户角色的需求,包括管理员、家政服务人员和普通用户,每个角色都有相应的权限和功能。此外,系统还采用了软件组件化、精化体系结构、分离逻辑和数据等方法,以便于未来的系统升级和维护。 智能家政保洁预约系统通过提供一个集中的平台,不仅方便了消费者的预约和管理,也为家政服务人员提供了一个展示和推广自己服务的机会。同时,系统的后台管理功能为家政公司提供了强大的数据支持和决策辅助,有助于提高服务质量和管理效率。该系统的设计与实现,标志着家政保洁服务向现代化和网络化的转型,为管理决策和控制提供保障,是行业发展中的重要里程碑。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值